liveBook · Manning

Stack pointer

As explained in Classic Game Programming on the NES: Make your own retro video game

A stack pointer is a processor state value identifying the current top position of the processor stack.

A stack pointer is a processor state value identifying the current top position of the processor stack. During NES startup, the 6502 initializes it by loading $FF into the X register and transferring that value to the S register with txs. The stack begins at the selected location; each value pushed onto it decreases the stack-pointer offset by 1. section 5.12

cld          #1
ldx #$FF
txs          #2

The two-instruction setup clears decimal mode, loads $FF into X, and transfers X to the stack-pointer register. section 5.12

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Explains the S-register setup and the decreasing offset caused by stack pushes, without detailing stack operations themselves.
Examples
Uses cld, ldx #$FF, and txs as the concrete initialization sequence.
What you can do after
Operate/configure it by loading $FF into X and transferring X to S during NES startup.
How it connects
Connects the stack pointer to the X register, the S register, and stack pushes.

Also explained in

Compare how 4 books explain stack pointer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.