The frame pointer is a register which holds the address of the bottom of the stack frame. In the x86 ISA, this register is known as ebp. The 'b' here stands for 'base', because the frame pointer is also known as the base pointer. In the Linux/x86 ABI, the frame pointer points to the bottom-most byte of the saved frame pointer of the previous stack frame. Conceptually, imagine foo() has called bar() (keep in mind that the stack grows downwards):

     |           ...             |
     |    rest of the stack      |
     |           ...             |
100: |    saved frame pointer    |
104: |    foo()'s stack frame    |
     |           ...             |
132: | return address from bar() |
136: |  100 [saved fp for foo()] | <-- bar()'s frame pointer points here
140: |    bar()'s stack frame    |
     |           ...             |

The frame pointer is useful because unlike the stack pointer, it does not change over the course of execution of the function. Therefore, all items in the stack (local variables, arguments, etc.) are at a fixed offset from the frame pointer. Without it, one would have to access stack items using the stack pointer, from which the offset of a given item changes as the function executes. When writing assembly code, manually doing the math for changing offsets from the stack pointer is a recipe for failure. However, it's pretty trivial for a compiler to do, and on register-starved architectures like x86, freeing up a register for the rest of the code to use can be a significant performance improvement. (In gcc, the option is -fomit-frame-pointer). However, this rather severely hampers debugging, both in terms of manually inspecting the stack and in terms of following function call chains, and thus it is not recommended.

Log in or register to write something here or to contact authors.