- ;; 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
- ld (.dcnt),a
- rl l ; Carry (next bit of quotient) to bit 0
- rl h ; Shift remaining bytes
- rl c
- rl b ; Clears carry since BC was 0
- ;; If remainder is >= divisor, next bit of quotient is 1. This
- ;; bit goes to carry
- push bc ; Save current remainder
- 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)
- jr C,.drop ; Jump if remainder is >= dividend
- pop bc ; Otherwise, restore remainder
- jr .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
+ ld (.dcnt),a
+ rl l ; Carry (next bit of quotient) to bit 0
+ rl h ; Shift remaining bytes
+ rl c
+ rl b ; Clears carry since BC was 0
+ ;; If remainder is >= divisor, next bit of quotient is 1. This
+ ;; bit goes to carry
+ push bc ; Save current remainder
+ 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)
+ jr C,.drop ; Jump if remainder is >= dividend
+ pop bc ; Otherwise, restore remainder
+ jr .nodrop