phiral.net
Home

What is a stack frame?

           ---------------------
           | top of stack      |
           --------------------|
           | arguments         |
           ---------------------
           | return address    |
           ---------------------     pushl %ebp
           | saved base pointer|     movl %esp, %ebp
           --------------------- <--- %ebp            
           | local variables   |
           --------------------|
           | saved registers   |
           ---------------------
           | bottom of btack   |
           ---------------------

A stack frame is section of the stack that contains the arguments,
local variables, return address, saved base pointer and register contents
for a functions, as well as a pointer to the previous stack frame. Functions 
store their temporary data in the stack. A special register storing the address of the 
bottom of the stack, esp the stack pointer register, is used a program stores 
values in offsets off this stack pointer. When a function is called, esp moves 
down to provide enough space to store its local temporary variables. Values stored are often 
local variables and the return address. When the function returns, the stack pointer 
is moved back up to save space on the stack, the data there remains until it is overwritten
by another function needing the space.