Subject: Re: div by 10 on Z80
Jim Battle
frustum at pacbell.net
Thu Jan 24 22:29:27 CST 2008
dwight elvey wrote:
>> From: korpela at ssl.berkeley.edu
>>
>>> Every time I see code like this for processors without a native DIV, I
>>> wonder if the same code ported to x86 would indeed outperform the native
>>> DIV. Would it? I know that on a 286 or higher, where MUL and DIV were
>>> greatly optimized to about 12 cycles, no; but what about on the original
>>> 808x, where MUL/DIV could take as much as 144 cycles?
>> In 286 and 386 you could usually beat IDIV when dividing by small
>> constants especially if you knew your dividend was of less than the
>> full range of the possible register values.
>>
>
> Based on an email I just had from the cpm news group, I thought
> it might be fun to write some Z80 code to do the 0 to 799 as fast
> as one could, with no size restriction. Just clocks count.
There is a trivial solution: a look up table.
add hl,hl ; double it
ld de,table ; base addr of table
add hl,de ; index
ld a,(hl) ; pick up quotient
...
table db 0,0 ; 0: quotient, remainder
db 0,1 ; 1
db 0,2
db 0,3
etc
More information about the cctech
mailing list