![Intel NIOS II Owner Reference Manual Download Page 152](http://html1.mh-extra.com/html/intel/nios-ii/nios-ii_owner-reference-manual_2071826152.webp)
Given the function prologue algorithm, when doing a back trace, a debugger can
disassemble instructions and reconstruct the processor state of the calling function.
Note:
An even better way to find out what the prologue has done is to use information
stored in the DWARF-2 debugging fields of the executable and linkable format (.elf)
file.
The instructions found in a Nios II function prologue perform the following tasks:
•
Adjust the stack pointer (to allocate the frame)
•
Store registers to the frame
•
Set the frame pointer to the location of the saved frame pointer
Example 4. A function prologue
/* Adjust the stack pointer */
addi sp, sp, -16 /* make a 16-byte frame */
/* Store registers to the frame */
stw ra, 12(sp) /* store the return address */
stw fp, 8(sp) /* store the frame pointer*/
stw r16, 4(sp) /* store callee-saved register */
stw r17, 0(sp) /* store callee-saved register */
/* Set the new frame pointer */
addi fp, sp, 8
Related Information
Register Usage
on page 147
7.4.4.1. Prologue Variations
The following variations can occur in a prologue:
•
If the function’s frame size is greater than 32,767 bytes, extra temporary registers
are used in the calculation of the new stack pointer as well as for the offsets of
where to store callee-saved registers. The extra registers are needed because of
the maximum size of immediate values allowed by the Nios II processor.
•
If the frame pointer is not in use, the final instruction, recalculating the frame
pointer, is not generated.
•
If variable arguments are used, extra instructions store the argument registers on
the stack.
•
If the compiler designates the function as a leaf function, the return address is not
saved.
•
If optimizations are on, especially instruction scheduling, the order of the
instructions might change and become interlaced with instructions located after
the prologue.
7.5. Arguments and Return Values
This section discusses the details of passing arguments to functions and returning
values from functions.
7. Application Binary Interface
NII-PRG | 2018.04.18
Nios II Processor Reference Guide
152