I've been reading about how to do various math routines with 65816 assembly. I've figured out how to add, subtract, and multiply 8bit integers, but division is still stumping me. I'd also like to learn how to work with 16bit integers, but am not sure the best way to approach that.
For multiplying integers, I read about the multiplicand and multiplier registers in Yoshi's docs. It's pretty simple. I'm using neviksti's printing macros to print to the screen.
Here is my code for multiplication:
Here is my code for division:
Lastly, when performing mathematical operations, do you use the accumulator primarily or is it a combination of the accumulator, x, and y?
EDIT: After testing my code for multiplication on the real hardware, it doesn't appear to multiply the numbers correctly. I tested it in ZSNES before testing it on the SNES.
For multiplying integers, I read about the multiplicand and multiplier registers in Yoshi's docs. It's pretty simple. I'm using neviksti's printing macros to print to the screen.
Here is my code for multiplication:
Code:
PrintString "\nMultiplication: 50*4 = "
lda #50
sta $4202 ; store the multiplicand
lda #4
sta $4203 ; store the multiplier
PrintNum $4216 ; print result
lda #50
sta $4202 ; store the multiplicand
lda #4
sta $4203 ; store the multiplier
PrintNum $4216 ; print result
Here is my code for division:
Code:
PrintString "\nDivision with remainder: 5/4="
lda #5
sta $4204 ; store dividend
lda #4
sta $4205 ; store divisor
PrintNum $4214 ; print result
PrintString "\nRemainder:"
PrintNum $4216 ; print remainder
lda #5
sta $4204 ; store dividend
lda #4
sta $4205 ; store divisor
PrintNum $4214 ; print result
PrintString "\nRemainder:"
PrintNum $4216 ; print remainder
Lastly, when performing mathematical operations, do you use the accumulator primarily or is it a combination of the accumulator, x, and y?
EDIT: After testing my code for multiplication on the real hardware, it doesn't appear to multiply the numbers correctly. I tested it in ZSNES before testing it on the SNES.