Posted by: Margaret Rouse
|“By convention, stacks usually grow down. This means that the stack starts at a high address in memory and progressively gets lower.” — Ian Wienand
I have to take a minute here to plug Ian Wienand’s free online book “Computer Science from the Bottom Up.” If you’re interested in looking underneath the hood, this is the book to help you understand what you’re seeing.
Mr. Wienand explains the concept of a stack as clearly as anyone I’ve ever heard or read:
A stack is generic data structure that works exactly like a stack of plates; you can push an item (put a plate on top of a stack of plates), which then becomes the top item, or you can pop an item (take a plate off, exposing the previous plate).
Stacks are fundamental to function calls. Each time a function is called it gets a new stack frame. This is an area of memory which usually contains, at a minimum, the address to return to when complete, the input arguments to the function and space for local variables.