Subject: Re: div by 10 on Z80 was RE: Reading Polymorphic
dwight elvey
dkelvey at hotmail.com
Tue Jan 22 22:35:18 CST 2008
> From: dkelvey at hotmail.com
---snip--
>
> Ok
> Here goes with using your idea to double use the a register. Except
> If I start it with 2, I can use the carry instead of the sign bit. What fun!
>
>
> Div10:
> ld a,#2
> ld de,#-640d
> divloop:
> add hl,de
> jr c, div1
> sbc hl,de
> div1:
> rl a
> jr nc,divloop
> add hl,hl
> ret
>
Oops!! I blew it. I forgot an 'add hl,hl' !!!!!!$$$####
Here is the change using the sign bit instead. Still saves time and cycles
by not needing the DJNZ. One less cycle per loop. The and at the end
balances the ld B#7 but the ld a, #1 is one more byte. Still the jp
is faster than the jr for the 7 loops. Still 19 bytes!
div10:
ld a,#1
ld de,#-640d
divloop:
add hl,de
jr c,div1
sbc hl,de
div1:
rl a
add hl,hl
jp p,div1
add hl,hl
and #7F
ret
Dwight
_________________________________________________________________
Helping your favorite cause is as easy as instant messaging. You IM, we give.
http://im.live.com/Messenger/IM/Home/?source=text_hotmail_join
More information about the cctalk
mailing list