previous | start | next

Stack Frame Setup Code

Function f that is called by main must set up its own stack frame:

  1. save main's frame pointer on the stack
  2. make the top of the stack be the bottom of f's stack frame
  3. If memory space for local variables is needed, adjust the top of f's stack frame
1. save main's frame pointer on the stack
 
    pushl %ebp

2. make the top of the stack be the bottom of f's stack frame

   movl %esp, %ebp

3. adjust top of f's stack frame if necessary. (Suppose for example,
   memory space for 2 local int variables is needed)

   subl $8, %esp


previous | start | next