Talking about division through multiplication and a table lookup, On Tue, 3 Jun 2008 08:28:21 -0700, "Simon Cooke" <[EMAIL PROTECTED]> wrote: > Never implemented it, but the principle is sound. It's not tremendously > different to a reciprocal table.
I never implemented it on z80 but I did do the same on ARM (where it gives you a massive win since there's a MUL instruction but no DIV). Without wanting to teach egg-sucking, it's fairly simple in concept: you just multiply the two numbers then shift the result down. So to divide an 8 bit number in L by 14, you need to multiply by (256/14)= 18(ish) then use the H register as your result... so that gives you (effectively) L * (256 / 14) / 256 The 256's cancel each other out, so you end up with L * (1 / 14) Obviously there's a loss of accuracy but it does mean you can get away with a table of 256 bytes for an 8 bit divide. My problem is you still end up having to do a multiply, which (on z80) is way too slow. I'd be tempted to use a 64kiB divide table and to hell with it. Geoff