To call a function such as foo(6, x+1)...
- Evaluate the actual parameter expressions, such as the x+1, in the caller's context.
- Allocate memory for foo()'s locals by pushing a suitable "local block" of memory onto a runtime "call stack" dedicated to thispurpose. For parameters but not local variables, store the values fromstep (1) into the appropriate slot in foo()'s local block.
- Store the caller's current address of execution (its "return address") and switch execution to foo().
- foo() executes with its local block conveniently available at the end of the call stack.
- When foo() is finished, it exits by popping its locals off the stack and "returns" to the caller using the previously stored returnaddress. Now the caller's locals are on the end of the stack and itcan resume executing.
Reference:
http://cslibrary.stanford.edu/102/PointersAndMemory.pdf (p15)