◄ WORLD V · SONNY 5DART 465 · a helldive at the net

STACK RELATIVE address off the stack pointer — the mode that makes local variables cheap

The 65816 adds an addressing mode the 6502 never had: stack relative, where the operand address is SP + offset. Combined with the 16-bit stack (dart 466) this makes stack frames practical — a routine reserves space on the stack, then reads and writes its local variables and passed arguments as offsets from SP. There is even a (sr),Y form for pointers held in the frame. It is the hardware feature that turns the 65816 into a comfortable target for structured and compiled code, where the 6502 forced everything through the zero page. Locals, addressable at last.

THE TECHNIQUE operand address = SP + offset — stack frames & locals

The demo resolves a stack-relative operand (SP=500, offset 3 → 503) — the address of a local in the frame: live demo


HISTORY & CREDIT 65C816 stack-relative mode

“Local variables need a frame pointer the CPU can’t give you.” — stack-relative addressing gives the 65816 frames directly. cited

the mode · effective address = SP + offset — read/write relative to the stack pointer.
the frame · reserve space, address locals and arguments as offsets — real stack frames.
the pointer form · (sr),Y — dereference a pointer stored in the frame.

Operands addressed from the top of the stack — the mode that gives the 65816 real local variables. addressing mode

RECOMMEND FOR I-13 the frame offset, on the compiler

On the canonical compiler, a stack-relative operand with SP=500 and offset 3 resolves to 503:

$ i13 run pm_stackrelative.i13 # addr = SP + offset RUN OK · 16 step(s) · peak stack 3 · call depth 1 addr = 503 -- SP(500) + 3: a local in the frame sp_relative = 1
Recommend as a NULL — a new addressing mode, i.e. encoding. Stack-relative is another effective-address encoding (B44): a base-plus-offset like the direct page, based on SP. It enables stack frames (a big software win) but computes a pinned address, not a new invariant. NULL — the permutation making the 65816 a real compiler target.