On 20 Jun 2007 at 11:03, Allison wrote:
I've used the same idea for decimal to bin and bin
to decimal as multiply
or divide by 10 is costly in 8080/Z80/8048. It was far easier and faster
to do a pair of shifts and one add and then do a shift again than a
general multiply. The same is true for the reverse though then you do
a subtract as needed. The code is linear and faster. It also works well
for other non binary constants (3,5,6,7,9,10,11..). Doing it this way
is the obvious specific unrolling of a general shift and add multiply
routine.
Two shifts and a subtract for divide by 10 with no conditional tests?
Do you have some source code? I don't think I've ever seen that done
on large binary numbers. Or maybe I misunderstood.
On the other hand, dividing by a constant by multiplying by a scaled
reciprocal of the constant is very old. We'd do an unnormalized
lower DP multiply by 1/10 scaled by 2**47 on the CDC 6600 for a
shortcut integer divide by 10.
Cheers,
Chuck