Find limit of recursion: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 13: | 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. |
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> |
<lang 6502asm>;beginning of your program |
||
;beginning of your program |
|||
lda #$BE |
lda #$BE |
||
sta $0100 |
sta $0100 |
||
Line 22: | Line 21: | ||
ldx #$ff |
ldx #$ff |
||
txs ;stack pointer is set to $FF |
txs ;stack pointer is set to $FF |
||
;later... |
|||
lda $0100 ;if this no longer equals $BE the stack has overflowed |
lda $0100 ;if this no longer equals $BE the stack has overflowed |