RosettaCodeData/Task/Integer-overflow/6502-Assembly/integer-overflow-6.6502

17 lines
550 B
Plaintext

;adding two 16-bit signed numbers, the first is stored at $10 and $11, the second at $12 and $13.
;The result will be stored at $14 and $15.
;add the low bytes
LDA $10 ;low byte of first operand
CLC
ADC $12 ;low byte of second operand
STA $14 ;low byte of sum
;add the high bytes
LDA $11 ;high byte of first operand
ADC $13 ;high byte of second operand
STA $15 ;high byte of result
BVS HandleOverflow ;only check for overflow when adding the most significant bytes.