Specifications

Table Of Contents
Altera Corporation 7–7
October 2007 Nios II Processor Reference Handbook
Application Binary Interface
Debuggers can use the knowledge of how the function prologs work to
disassemble the instructions to reconstruct state when doing a back trace.
Preferably, debuggers can use information stored in the DWARF2
debugging information to find out what a prolog has done.
The instructions found in a Nios II function prolog perform the following
tasks:
Adjust the SP (to allocate the frame)
Store registers to the frame.
Assign the SP to the FP
Example 7–1 shows an example of a function prolog.
Example 7–1. A function prolog
/* Adjust the stack pointer */
addisp, sp, -120/* make a 120 byte frame */
/* Store registers to the frame */
stw ra, 116(sp)/* store the return address */
stw fp, 112(sp)/* store the frame pointer*/
stw r16, 108(sp)/* store callee-saved register */
stw r17, 104(sp) /* store callee-saved register */
/* Set the new frame pointer */
mov fp, sp
Prolog Variations
The following variations can occur in a prolog:
If the function’s frame size is greater than 32,767 bytes, extra
temporary registers will be used in the calculation of the new SP as
well as for the offsets of where to store callee-saved registers. This is
due to the maximum size of immediate values allowed by the Nios II
processor.
If the frame pointer is not in use, the move of the SP to FP will not
happen.
If variable arguments are used, there will be extra instructions to
store the argument registers to the stack.
If the function is a leaf function, the return address will not be saved.
If optimizations are on, especially instruction scheduling, the order
of the instructions may change and may become interlaced with
instructions located after the prolog.