- ;; Shift next bit of quotient into bit 0 of dividend
- ;; Shift next MSB of dividend into LSB of remainder
- ;; BC holds both dividend and quotient. While we shift a bit from
- ;; MSB of dividend, we shift next bit of quotient in from carry
- ;; HL holds remainder
- ;; Do a 32-bit left shift, shifting carry to L, L to H,
- ;; H to C, C to B
- ex af,af'
- RL C ; Carry (next bit of quotient) to bit 0
- RL B ; Clears carry since BC was 0
- adc hl,hl
-
- ;; If remainder is >= divisor, next bit of quotient is 1. This
- ;; bit goes to carry
- PUSH HL ; Save current remainder
- sbc hl,de
-; LD A,C ; Substract divisor from remainder
-; SBC E
-; LD C,A
-; LD A,B
-; SBC D
-; LD B,A
- CCF ; Complement borrow so 1 indicates a
- ; successful substraction (this is the
- ; next bit of quotient)
- jp C,.drop ; Jump if remainder is >= dividend
- POP HL ; Otherwise, restore remainder
- jp .nodrop
+ ;; Shift next bit of quotient into bit 0 of dividend
+ ;; Shift next MSB of dividend into LSB of remainder
+ ;; BC holds both dividend and quotient. While we shift a bit from
+ ;; MSB of dividend, we shift next bit of quotient in from carry
+ ;; HL holds remainder
+ ;; Do a 32-bit left shift, shifting carry to L, L to H,
+ ;; H to C, C to B
+ ex af,af'
+ rl c ; Carry (next bit of quotient) to bit 0
+ rl b ; Clears carry since BC was 0
+ adc hl,hl
+
+ ;; If remainder is >= divisor, next bit of quotient is 1. This
+ ;; bit goes to carry
+ push hl ; Save current remainder
+ sbc hl,de
+; ld a,c ; Substract divisor from remainder
+; sbc e
+; ld c,a
+; ld a,b
+; sbc d
+; ld b,a
+ ccf ; Complement borrow so 1 indicates a
+ ; successful substraction (this is the
+ ; next bit of quotient)
+ jp C,.drop ; Jump if remainder is >= dividend
+ pop hl ; Otherwise, restore remainder
+ jp .nodrop