Specifications

Table Of Contents
7–4 Altera Corporation
Nios II Processor Reference Handbook User Guide October 2007
Stacks
Figure 7–1. Stack Pointer, Frame Pointer and the Current Frame
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
Because, in the normal case, the frame pointer is the same as the stack
pointer, the information in the frame pointer is redundant. Therefore, to
achieve most optimal code, eliminating the frame pointer is desirable.
However, when the frame pointer is eliminated, because debuggers have
issues locating the stack properly, debugging without a frame pointer is
difficult to do. When the frame pointer is eliminated, register fp becomes
available as a temporary.
Call Saved Registers
Implementation note: the compiler is responsible for saving registers that
need to be saved in a function. If there are any such registers, they are
saved on the stack in this order from high addresses: ra, fp, r2, r3, r4,
r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19,
r20, r21, r22, r23, r24, r25, gp, and sp. Stack space is not allocated for
registers that are not saved.
In Function a()
Just prior to calling b()
In Function b()
Just after executing prolog
incoming
stack
arguments
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)
fp and sp
outgoing
stack
arguments
Higher addresses
fp and sp
Lower addresses
space for
stack
temporaries