
 1000  *SAVE S.DIV.8.BY.4
 1010  *--------------------------------
 1020  *      DIVIDE 8-BIT VALUE
 1030  *          BY 4-BIT VALUE
 1040  *--------------------------------
 1050  DIVIDEND   .EQ 0
 1060  DIVISOR    .EQ 1
 1070  QUOTIENT   .EQ 2
 1080  *--------------------------------
 1090  S.DIV.8.BY.4
 1100         LDY #5       COUNT OFF 5 STEPS
 1110         LDA #0
 1120         STA QUOTIENT
 1130         LDA DIVISOR       SEE IF DIVISOR IN RANGE
 1140         BEQ .3            DIVIDE BY ZERO IS ILLEGAL
 1150         ASL          SHIFT DIVISOR TO LEFT NYBBLE
 1160         ASL 
 1170         ASL 
 1180         ASL 
 1190         STA DIVISOR
 1200  .1     LDA DIVIDEND      COMPARE DIVIDEND TO DIVISOR
 1210         SEC
 1220         SBC DIVISOR
 1230         BCC .2            DIVIDEND IS SMALLER
 1240         CMP DIVISOR       SEE IF STILL LARGER
 1250         BCS .3            YES, OVERFLOW
 1260         SEC               SET QUOTIENT BIT = 1
 1270         STA DIVIDEND
 1280  .2     ROL QUOTIENT      SHIFT QUOTIENT BIT IN
 1290         LSR DIVISOR       SHIFT DIVISOR OVER
 1300         DEY
 1310         BNE .1            DO NEXT STEP
 1320         ROL DIVISOR  RESTORE DIVISOR
 1330         RTS
 1340  .3     BRK          DIVIDE FAULT

