lda #1 ; A = 1
adc #1 ; A = 2
ldx #5 ; X = 5
stx $01 ; memory address $01 = 5
adc $01 ; A = 7
8-bit subtraction:
sec ; set the carry flag
lda #5
sbc #1 ; subtract one from the A register, A = 4
lda #5
sta $01 ; Memory address $01 holds the value 5
dec $01 ; Memory address $01 holds the value 4
lda #1 ; A = 1 (00000001)
asl ; A = 2 (00000010)
asl ; A = 4 (00000100)
The leftmost bit of the accumulator is set to the carry flag
lda #%10000000 ; A = 128 (10000000), carry flag = 0
asl ; A = 0 (00000000), carry flag = 1
lda #1 ; A = 1
pha ; A = 1, $01FF = 1
lda #1 ; A = 1
Typically you'll just do this once to setup a descending stack
txs #$ff
lda #%10101010
ora #%11110000
; A = 11111010