
 1000  *SAVE S.DIVIDE 32/16
 1010  *--------------------------------
 1020  DIVIDE LDX #17           16-BIT DIVISOR
 1040         CLC               START WITH NO OVERFLOW
 1050  .1     ROR OVERFLOW
 1060         SEC
 1070         LDA DIVIDEND+1    NEXT-TO-HIGHEST BYTE
 1080         SBC DIVISOR+1     LEAST SIGNIFICANT BYTE
 1090         TAY               SAVE RESULT
 1100         LDA DIVIDEND      HIGHEST BYTE
 1110         SBC DIVISOR
 1120         BCS .2            QUOTIENT BIT = 1
 1130         ASL OVERFLOW      TRUE QUOTIENT BIT
 1140         BCC .3
 1150  .2     STY DIVIDEND+1    QUOTIENT BIT = 1
 1160         STA DIVIDEND
 1170  .3     ROL DIVIDEND+3    SHIFT QUOTIENT BIT INTO END
 1180         ROL DIVIDEND+2    AND MOVE TO NEXT POSITION
 1190         ROL DIVIDEND+1
 1200         ROL DIVIDEND
 1210         DEX
 1220         BNE .1
 1230         ROR DIVIDEND      SHIFT REMAINDER BACK IN PLACE
 1240         ROR DIVIDEND+1
 1250         ROR OVERFLOW      SET SIGN BIT IF OVERFLOW
 1260         RTS
 1270  *--------------------------------
 1280  DIVIDEND   .BS 4
 1290  REMAINDER  .EQ DIVIDEND
 1300  QUOTIENT   .EQ DIVIDEND+2
 1310  DIVISOR    .BS 2
 1320  OVERFLOW   .BS 1
 1330  *--------------------------------
 1340         .LIF

