Hello, General question I can not seem to find anwser to using Google: I am tinkering with a processor that has no DIV instruction, and am wondering how to represent a reciprocal such that I can use MUL instruction to perform div's.
The CPU is integer-only, 32bit. It has a small instruction set, but does include the basics - add, sub, shl, shr, and so forth.
In my particular application, the divisor will always be only 16 bits. External memory availability is not good, so I would prefer not to use a table. By "not good", I mean A) there is only a few KB of available memory, and B) access is slow due to architecture. Speed is of some concern, and I am hoping that there is some "shortcut" method that can be used. I can tolerate some degree of inaccuracy; +/-
1 at least. There is no FPU, and no support (nor need) for floating point math.In comp.lang.asm.x86 a kind gentleman pointed me to this page:
There, I see this text:
"Dividing by a constant can be done by multiplying with the reciprocal."
And this text:
"..you first calculate the reciprocal f = 2^r / d"
I don't understand the benefit of calculating a reciprocal if you need to use a "div" instruction to get there. However, I have a poor math foundation and am not an experienced programmer (quite the opposite!), so perhaps I am simply missing the point there.
Any advice or suggestions appreciated. TT