Dwight Elvey
Veteran Member
Hi
I had this question up on cclassic list but thought I'd ask here as
well. For the floppy controller I'm writing code for, I need to divide
by 10 and keep the remainder. We've come up with some code that
we think is close to optimal but I thought I'd bring it to a larger
audience ( I know there is some overlap here ).
Here is what we have so far:
; HL dividend less then 1023d ( only need 0-799 )
; returns A quotient
; H remainder
Div10:
xor a
ld b,#7
ld de,#-640d
divloop:
add hl,de
jr c, div1
sbc hl,de
ora a ; not sure if this is needed here to clear carry
div1:
rl a
add hl,hl
djnz divloop
add hl,hl
ret
Any suggestions for improvements welcome.
Dwight
I had this question up on cclassic list but thought I'd ask here as
well. For the floppy controller I'm writing code for, I need to divide
by 10 and keep the remainder. We've come up with some code that
we think is close to optimal but I thought I'd bring it to a larger
audience ( I know there is some overlap here ).
Here is what we have so far:
; HL dividend less then 1023d ( only need 0-799 )
; returns A quotient
; H remainder
Div10:
xor a
ld b,#7
ld de,#-640d
divloop:
add hl,de
jr c, div1
sbc hl,de
ora a ; not sure if this is needed here to clear carry
div1:
rl a
add hl,hl
djnz divloop
add hl,hl
ret
Any suggestions for improvements welcome.
Dwight