MicroBlaze Processor Reference Guide www.xilinx.com 67
UG081 (v6.0) June 1, 2006 1-800-255-7778
Stack Convention
R
Certain registers are usedas dedicatedregisters and programmers are notexpected to
use them for any other purpose.
Registers R14 through R17 are used forstoring thereturn addressfrominterrupts,
sub-routines,traps, andexceptions inthat order. Sub-routinesare called using the
branch and link instruction, which saves the current Program Counter (PC) onto
register R15.
Small data area pointers are used for accessing certain memory locations with 16
bit immediate value. These areas are discussed in the memory model section of
this document. The read only small data area (SDA) anchor R2 (Read-Only) is
used to access the constants such as literals. The other SDA anchor R13 (Read-
Write) is used for accessing the values in the small data read-write section.
Register R1 stores the value of the stack pointer and is updated on entry and exit
from functions.
Register R18 is used as a temporary register for assembler operations.
MicroBlaze includes special purpose registers such as: program counter (rpc),
machine status register (rmsr), exception status register (resr), exception address
register (rear), and floating point status register (rfsr). These registers are not mapped
directly to the register file and hence the usage of these registers is different from the
general purpose registers. The value of a special purpose registers can be transferred
to a general purpose register by using mts and mfs instructions (For more details
refer to the “MicroBlaze Application Binary Interface” chapter).
Stack Convention
The stack conventions used by MicroBlaze are detailed in Figure 3-1
The shaded area in Figure 3-1 denotes a part of the caller function’s stack frame, while the
unshaded area indicates the callee function’s frame. The ABI conventions of the stack
frame define the protocol for passing parameters, preserving non-volatile register values
and allocating space for the local variables in a function. Functions which contain calls to
other sub-routines arecalled as non-leaf functions, These non-leaffunctions haveto create
a new stack frame area for its own use. When the program starts executing, the stack
pointer will have the maximum value. As functions are called, the stack pointer is
decremented by the number of words required by every function for its stack frame. The
stack pointer of a caller function will always have a higher valueas compared to the callee
function.