Specifications
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 7-1: 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 7-2
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.
Arguments and Return Values
This section discusses the details of passing arguments to functions and returning values from functions.
Arguments
The first 16 bytes to a function are passed in registers r4 through r7. The arguments are passed as if a
structure containing the types of the arguments were constructed, and the first 16 bytes of the structure
are located in r4 through r7.
A simple example:
int function (int a, int b);
NII51016
2015.04.02
Prologue Variations
7-7
Application Binary Interface
Altera Corporation
Send Feedback