Software - INC and DEC techniques
Typical 16-bit increment
Overflow (incrementing to $0000) sets the Z flag is set (i.e. BEQ branches).
;
INC NUML
BNE LABEL
INC NUMH
LABEL
Typical 16-bit decrement
;
LDA NUML
BNE LABEL
DEC NUMH
LABEL DEC NUML
16-bit decrement, test for zero
;
LDA NUML
BNE LABEL
LDA NUMH
BEQ ZERO ; branch when NUM = $0000 (NUM is not decremented in that case)
DEC NUMH
LABEL DEC NUML
Add 255
;
LDA NUML
BEQ LABEL
INC NUMH
LABEL DEC NUML
Subtract 255
;
INC NUML
BEQ LABEL
DEC NUMH
LABEL
Constant time increment
6 cycles
A = high byte, X = low byte
Overflow (incrementing to $0000) sets the carry
CPX #$FF
INX
ADC #$00
Constant time decrement
6 cycles
A = high byte, X = low byte
Underflow (decrementing to $FFFF) clears the carry
CPX #$01
DEX
SBC #$00
page_revision: 1, last_edited: 1200461216|%e %b %Y, %H:%M %Z (%O ago)





