[A83] Re: help for a routine - ASM Multiplying and dividing shortcut
[Prev][Next][Index][Thread]
[A83] Re: help for a routine - ASM Multiplying and dividing shortcut
> I think I'll use divHLbyA for the moment, but i'm sure
finding the
> ratio of two numbers ( a fortiori with a precision of 2
units) can be
> done with a trick....
>
And the trick is called division. :) DivHLbyA is really the
best of the compact solutions. If you need more speed but
don't want to use tables, you can still unroll it:
; this routine does HL=HL/D
; D must be less than 128, otherwise the result might be
incorrect
#define DIVMACRO add hl,hl \ rla \ cp d \ jp c,$+5 \ sub d
\ inc l
DivHLbyD:
xor a
DIVMACRO \ DIVMACRO \ DIVMACRO \ DIVMACRO
DIVMACRO \ DIVMACRO \ DIVMACRO \ DIVMACRO
DIVMACRO \ DIVMACRO \ DIVMACRO \ DIVMACRO
DIVMACRO \ DIVMACRO \ DIVMACRO
add hl,hl
rla
cp d
ret c
inc l
ret
I hope I didn't screw up... It's a bit long, but it does
the job.
PG
References: