Stacks in Frame Pointers and Local Variables

Learn about frame pointers and local variables using stack.

Stack usage

In addition to storage for the return addresses of CALL instructions, a stack is used to pass additional parameters to functions and store local variables. The stack is also used to save and restore values held in registers when we want to preserve them during some computation or across function calls. For example, suppose we want to do multiplication, but we have other valuable data in registers %RAX and %RDX. The multiplication result will overwrite %RAX and %RDX values, and we temporarily put their values on the stack:

Get hands-on with 1200+ tech skills courses.