Hi Guys,
I'm trying to get my head around adding numbers that a greater than 8 bit.
I've managed to get 16 bit addition working to an extent.
Here I'm adding 6000 to the previous contents of result, which is working ok if the result is below 65536.
Code:
clc
lda #<6000
adc result + 0
sta result + 0 ; store sum of LSBs
lda #>6000
adc result + 1 ; add the MSBs using carry
sta result + 1
I'll only ever be adding 16 bit number at maximum. How would I go about expanding this to flow over in to a 24 bit result? I have provision for "result + 2" allocated in RAM.
I've tried a few different things but am struggling to get a 24 bit result.
I thought (logically) something like this at the end of the code, but that doesn't seem to work at all.
Code:
adc #0 ; Add the overflow to highest byte
sta result + 2
Math on the 6502 is definitely not my strong point and is one of those areas that always trips me up.
Any advice is greatly appreciated.
[Edited to reflect that "CLC" was being called prior to the routine - Pointing this out to reflect the context of Garth's reply]