Skip to content

Instantly share code, notes, and snippets.

@niconii
Created May 7, 2016 06:50
Show Gist options
  • Save niconii/3d03445ba8c6346cf23a5844160ab647 to your computer and use it in GitHub Desktop.
Save niconii/3d03445ba8c6346cf23a5844160ab647 to your computer and use it in GitHub Desktop.
Accessing byte at offset from stack pointer on 6502
tsx ; transfer stack pointer to X register
stx scratch ; store X in RAM
ldx #$01 ; load 0x01 into X
stx scratch+1 ; store X in RAM
ldx offset ; load offset into X
lda (scratch,x) ; perform an indirect load from *(scratch + X) into A
1+2+2+2+2+2 bytes = 11 bytes
2+3+2+3+3+6 cycles = 19 cycles
; clobbers two of the 6502's three general-purpose registers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment