Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NES ca65 Cheat Sheet

This cheat sheet is only for the ca65 assembler, and probably not compatible with others

adc - Add to the accumulator

lda #1 ; A = 1
adc #1 ; A = 2
ldx #5 ; X = 5
stx $01 ; memory address $01 = 5
adc $01 ; A = 7

sbc - Subtract from the accumulator

8-bit subtraction:

sec ; set the carry flag
lda #5
sbc #1 ; subtract one from the A register, A = 4

Read more

dec - Decrement a value in a memory address by one

lda #5
sta $01 ; Memory address $01 holds the value 5
dec $01 ; Memory address $01 holds the value 4

asl - Left-bit shift the accumulator

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

pha - Push accumulator onto the stack

lda #1 ; A = 1
pha    ; A = 1, $01FF = 1

pla - Pull (pop) value from stack into the accumulator

lda #1 ; A = 1

txs - Set the value of the stack pointer

Typically you'll just do this once to setup a descending stack

txs #$ff

ora - Logical inclusive OR performed on the accumulator

lda #%10101010
ora #%11110000
; A = 11111010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment