liveBook · Manning

Stack pointer

As explained in Modern C, Third Edition

A stack pointer is a processor register that identifies the current top of a function-call stack area.

A stack pointer is a processor register that identifies the current top of a function-call stack area. On this machine, %rsp points to the highest memory address available for the current function's data, while %rbp marks the stack area's base. section 13.5

Function entry in assembler

The fgoto function saves the caller's base pointer, copies %rsp into %rbp, and subtracts 48 from %rsp: pushq %rbp; movq %rsp, %rbp; subq $48, %rsp. This reserves space for fgoto's automatic objects. The function then addresses objects such as n with offsets relative to %rbp. section 13.5

How Modern C, Third Edition covers it

How deep it goes
Traces register roles and three setup instructions, but stops short of a general stack implementation.
Examples
Uses the fgoto function and annotated optimized and unoptimized assembler listings to show stack-pointer setup.
What you can do after
Understand how an assembler function reserves stack space and locates its local objects during entry.
How it connects
Connects stack pointer with base pointer, processor registers, automatic variables, local storage, and assembler.

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 Modern C, Third Edition. The section links point to the parts of the book it draws on.