... i just don't like to use Divu/Divs on the 68000, and i also wanted to to hear if other had some good idea.
but i have learn some great things today, how the Divu can fail and also about BCD instruction, that i can use later
so thx all
What you essentially need (probably not, but you asked for it and I think it's a nice opportunity to show something - at least I consider - smart from a book I own
) is a fast replacement for a division by 10 that preserves the division rest (x / 10, x % 10).
At least on Hatari (and using a C compiler), that said algorithm is roughly 6 times faster than a plain div/mod (don't know how it does on real hw).
The idea is to replace the division with a multiplication of the inverse of the divisor and replace that with an approximation of shifts and adds. This will produce a (known) error that needs to be accounted for in the end:
Code: Select all
void divmod10(long in, long *div, long *mod)
* 8 / 10 = (approx.) 0.1100 1100 1100 1100 1100 1100 1100 1100
long q = (in >> 1) + (in >> 2);
q = q + (q >> 4);
q = q + (q >> 8);
q = q + (q >> 16);
q = q >> 3;
long r = in - ((q << 3) + (q << 1));
*div = q + (r > 9);
if (r > 9) *mod = r - 10;
else *mod = r;
The code is (more or less) a straight copy of Hacker's Delight, 2nd edition"
, pg. 257, Figure 10-12. A nice read, delightful
I'll leave it to you to translate it into assembler