Specifications
Stacks
The stack grows downward (i.e. towards lower addresses). The stack pointer points to the last used slot.
The frame pointer points to the saved frame pointer near the top of the stack frame.
The figure below shows an example of the structure of a current frame. In this case, function a() calls
function b(), and the stack is shown before the call and after the prologue in the called function has
completed.
Figure 7-1: Stack Pointer, Frame Pointer and the Current Frame
In function a()
Just prior to calling b()
In function b()
Just after executing prologue
Incoming
stack
arguments
Other saved
registers
Space for
outgoing
stack
arguments
Allocated and freed by a()
(i.e. the calling function)
Allocated and freed by b()
(i.e. the current function)
Stack pointer
Outgoing
stack
arguments
Higher addresses
Stack pointer
Lower addresses
Space for
stack
temporaries
Return address
Saved frame
pointer
Frame pointer
Each section of the current frame is aligned to a 32-bit boundary. The ABI requires the stack pointer be
32-bit aligned at all times.
Frame Pointer Elimination
The frame pointer is provided for debugger support. If you are not using a debugger, you can optimize
your code by eliminating the frame pointer, using the -fomit-frame-pointer compiler option. When
the frame pointer is eliminated, register fp is available as a temporary register.
Call Saved Registers
The compiler is responsible for generating code to save registers that need to be saved on entry to a
function, and to restore the registers on exit. If there are any such registers, they are saved on the stack,
from high to low addresses, in the following order: ra, fp, sp, gp, r25, r24, r23, r22, r21, r20, r19, r18,
r17, r16, r15, r14, r13, r12, r11, r10, r9, r8, r7, r6, r5, r4, r3, and r2. Stack space is not allocated for
registers that are not saved.
7-4
Stacks
NII51016
2015.04.02
Altera Corporation
Application Binary Interface
Send Feedback