
 1000  *SAVE S.DIVIDE 32/16 WITH TRACE
 1010  *--------------------------------
 1020  OVERFLOW   .EQ $00
 1030  DIVIDEND   .EQ $01 THRU $04
 1040  REMAINDER  .EQ DIVIDEND
 1050  QUOTIENT   .EQ DIVIDEND+2
 1060  DIVISOR    .EQ $05 AND $06
 1070  *--------------------------------
 1080  MON.CROUT  .EQ $FD8E
 1090  MON.PRHEX  .EQ $FDDA
 1100  MON.COUT   .EQ $FDED
 1110  *--------------------------------
 1120  DIVIDE LDX #17           16-BIT DIVISOR
 1130         CLC               START WITH NO OVERFLOW
 1140  .1     ROR OVERFLOW
 1150         JSR TRACE
 1160         SEC
 1170         LDA DIVIDEND+1    NEXT-TO-HIGHEST BYTE
 1180         SBC DIVISOR+1     LEAST SIGNIFICANT BYTE
 1190         TAY               SAVE RESULT
 1200         LDA DIVIDEND      HIGHEST BYTE
 1210         SBC DIVISOR
 1220         BCS .2            QUOTIENT BIT = 1
 1230         ASL OVERFLOW      TRUE QUOTIENT BIT
 1240         BCC .3
 1250  .2     STY DIVIDEND+1    QUOTIENT BIT = 1
 1260         STA DIVIDEND
 1270  .3     ROL DIVIDEND+3    SHIFT QUOTIENT BIT INTO END
 1280         ROL DIVIDEND+2    AND MOVE TO NEXT POSITION
 1290         ROL DIVIDEND+1
 1300         ROL DIVIDEND
 1310         DEX
 1320         BNE .1
 1330         ROR DIVIDEND      SHIFT REMAINDER BACK IN PLACE
 1340         ROR DIVIDEND+1
 1350         ROR OVERFLOW      SET SIGN BIT IF OVERFLOW
 1360  *--------------------------------
 1370  TRACE  LDA #$B0
 1380         BIT OVERFLOW
 1390         BPL .1
 1400         LDA #$B1
 1410  .1     JSR MON.COUT
 1420         LDY #0
 1430  .2     LDA #$A0
 1440         JSR MON.COUT
 1450         LDA DIVIDEND,Y
 1460         JSR MON.PRHEX
 1470         INY
 1480         CPY #4
 1490         BCC .2
 1500         JSR MON.CROUT
 1510         RTS
 1520  *--------------------------------
 1530         .LIF

