BigDumbDinosaur wrote:
johnwbyrd wrote:
For that reason, a 65816-only solution, that may or may not use the Z accumulator, is also of interest.
Code: Select all
; add two 16-bit numbers in zp:
; x and y point to the addends, a points to the sum
; a and x are modified, y is preserved
Code: Select all
org 0
P3 db 0 ; Pointer to third operand
SumLow db 0
Num1 dw 1234 ; First number
Num2 dw 5678 ; Second number
Num3 dw 0 ; Sum
;
; (P1) + (P2) -> (P3)
;
Add
sta P3
clc
lda 0,Y
adc 0,X
sta SumLow
lda 1,Y
adc 1,X
ldx P3 ; Point to sum
sta 1,X
lda SumLow
sta 0,X
rts
;
Start
ldy #Num1 ; Store pointer to first number
ldx #Num2 ; Store pointer to second number
lda #Num3 ; Store pointer to sum
jsr Add ; Add them
end Start