+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  What am I doing wrong? (6502 related)
Pages: 1 [2]
Author Topic: What am I doing wrong? (6502 related)  (Read 2 times)
tomaitheous
Guest
« Reply #15 on: May 04, 2008, 02:26:43 am »

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).



Code:
    1100   remainder 1
    ------
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.

 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.
creaothceann
Guest
« Reply #16 on: May 04, 2008, 03:19:55 am »

For those interested, fxtbook has some pages on bit tricks.
Pages: 1 [2]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC