Register Usage Conventions - 2024.2 English

MicroBlaze Processor Reference Guide (UG984)

Document ID
UG984
Release Date
2024-11-27
Version
2024.2 English

The register usage convention for MicroBlaze is given in the following table.

Table 1. Register Usage Conventions
Register Type Enforcement Purpose
R0 Dedicated HW Value 0
R1 Dedicated SW Stack Pointer
R2 Dedicated SW Read-only small data area anchor
R3-R4 Volatile SW Return Values/Temporaries
R5-R10 Volatile SW Passing parameters/Temporaries
R11-R12 Volatile SW Temporaries
R13 Dedicated SW Read-write small data area anchor
R14 Dedicated HW Return address for Interrupt
R15 Dedicated SW Return address for Sub-routine
R16 Dedicated HW Return address for Trap (Debugger)
R17 Dedicated HW/SW Return address for Exceptions HW, if configured to support hardware exceptions, else SW
R18 Dedicated SW Reserved for Assembler/Compiler Temporaries
R19 Non-volatile SW Must be saved across function calls. Callee-save
R20

Dedicated

or

Non-volatile

SW Reserved for storing a pointer to the global offset table (GOT) in position independent code (PIC). Non-volatile in non-PIC code. Must be saved across function calls. Callee-save.
R21-R31 Non-volatile SW Must be saved across function calls. Callee-save.
RPC Special HW Program counter
RMSR Special HW Machine Status Register
REAR Special HW Exception Address Register
RESR Special HW Exception Status Register
RFSR Special HW Floating-Point Status Register
RBTR Special HW Branch Target Register
REDR Special HW Exception Data Register
RPID Special HW Process Identifier Register
RZPR Special HW Zone Protection Register
RTLBLO Special HW Translation Look-Aside Buffer Low Register
RTLBHI Special HW Translation Look-Aside Buffer High Register
RTLBX Special HW Translation Look-Aside Buffer Index Register
RTLBSX Special HW Translation Look-Aside Buffer Search Index
RPVR0-12 Special HW Processor Version Register 0 through 12

The architecture for MicroBlaze defines 32 general purpose registers (GPRs). These registers are classified as volatile, non-volatile, and dedicated.

  • The volatile registers (also known as caller-save) are used as temporaries and do not retain values across the function calls. Registers R3 through R12 are volatile, of which R3 and R4 are used for returning values to the caller function, if any. Registers R5 through R10 are used for passing parameters between subroutines.
  • Registers R19 through R31 retain their contents across function calls and are hence termed as non-volatile registers (a.k.a callee-save). The callee function is expected to save those non-volatile registers, which are being used. These are typically saved to the stack during the prologue and then reloaded during the epilogue.
  • Certain registers are used as dedicated registers and programmers are not expected to use them for any other purpose.
    • Registers R14 through R17 are used for storing the return address from interrupts, sub-routines, traps, and exceptions in that order. Subroutines are 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)
    • floating-point status register (rfsr), branch target register (rbtr)
    • exception data register (redr)
    • memory management registers (rpid, rzpr, rtlblo, rtlbhi, rtlbx, rtlbsx)
    • processor version registers (0-12)

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 or from a general purpose register by using mts and mfs instructions respectively.