![Intel NIOS II Owner Reference Manual Download Page 149](http://html1.mh-extra.com/html/intel/nios-ii/nios-ii_owner-reference-manual_2071826149.webp)
Figure 13.
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.
7.4.1. 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.
7.4.2. 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.3. Further Examples of Stacks
There are a number of special cases for stack layout, which are described in this
section.
7. Application Binary Interface
NII-PRG | 2018.04.18
Nios II Processor Reference Guide
149