Find limit of recursion: Difference between revisions

m
Line 13:
Reading the current stack pointer is unreliable, as there is no requirement that the stack be "aligned" in any way. Unlike the 8086 and Z80, which require all pushes/pops to be exactly two bytes, the 6502's stack will likely contain both 1 byte registers and 2 byte return addresses. It's much easier to use a stack canary. Pick a value that is unlikely to be used in your program.
 
<lang 6502asm>;beginning of your program
;beginning of your program
lda #$BE
sta $0100
Line 22 ⟶ 21:
ldx #$ff
txs ;stack pointer is set to $FF
 
 
;later...
 
lda $0100 ;if this no longer equals $BE the stack has overflowed
1,489

edits