Quote from: KingMike on May 03, 2008, 09:00:37 pm
I actually tried to do multiplication on the NES, using some manner of shifts, though a loop would accomplish the job (slowly). (like 6x5 = 6x4 + 6x1 = (6 left-shift 2) + 6 instead of 6+6+6+6+6). Don't remember if even finished a routine, though.
(yeah, I'm talking about integer multiplications. Floating point could be a mess, and would definitely be slow.)
Not sure if there's a simple way to do division, aside from a subtraction loop (would probably have to settle for an integer and remainder result).
(yeah, I'm talking about integer multiplications. Floating point could be a mess, and would definitely be slow.)
Not sure if there's a simple way to do division, aside from a subtraction loop (would probably have to settle for an integer and remainder result).
Code:
1100 remainder 1
------
101/111101
-101
------
10101
-101
-------
01
------
101/111101
-101
------
10101
-101
-------
01
Quote from: WDC programming manual/PDF
There are several methods for doing this, but all are based on the division principles for multi-digit
numbers that you learned in grade school. Line up the divisor under the left-most set of digits of the dividend,
appending an imaginary set of zeroes out to the right, and subtract as many times as possible. Record the
number of successful subtractions; then shift the divisor right one place and continue until the divisor is flush
right with the dividend, and no more subtractions are possible. Any non-subtractable value remaining is called
the remainder.
numbers that you learned in grade school. Line up the divisor under the left-most set of digits of the dividend,
appending an imaginary set of zeroes out to the right, and subtract as many times as possible. Record the
number of successful subtractions; then shift the divisor right one place and continue until the divisor is flush
right with the dividend, and no more subtractions are possible. Any non-subtractable value remaining is called
the remainder.
Multiplication is the same concept. Add the shifted component on each set bit. Check out the WDC programming manual/pdf for more clear explanation and example code. Both routines are as fast as you can get in software (excluding any LUTs). Mul and Div on fixed point math isn't so bad either.