Stacks in Frame Pointers and Local Variables

Learn about frame pointers and local variables using stack.

Stack usage

In addition to storing return addresses, a stack is used to pass additional parameters to functions (if we have more than 8 parameters) 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 call some function, but at the same time, we have valuable data in registers x0 and x1. The function code may overwrite x0 and x1 values, so we temporarily save their current values on the stack:

Get hands-on with 1200+ tech skills courses.