Registers
/images/RISC-V_registers_1.png)
Hardwired Zero (zero - x0) (read-only)
- Used in various operations that require the value 0.
- Instead of explicitly specifying 0, using
x0allows for a shorter bit representation. - If there are 32 registers in total, only 5 bits are needed to represent the address.
Return Address (ra - x1)
- Stores the return address.
- Return address : The location in the code where the program should return after a function call is completed.
Stack pointer (sp - x2)
- Points to the top of the current stack frame
- Used for managing function calls and local variables.
Global pointer (gp - x3)
- Points to a fixed region in memory that holds global variables accessible throughout the program.
Thread pointer (tp - x4)
- Points to thread-specific data, allowing each thread to access its own set of variables.
Temporary (t0-t6 - x5-x7, x28-x31)
- Caller-save registers
Saved Registers (s0-s11 - x8-x9, x18-x27)
- Callee-save registers
Frame pointer (fp - x8)
- Points to the base of the current stack frame
- Used for accessing function parameters and local variables within that frame.
Function Arguments (a0-a7 - x10-x17)
- Used to pass arguments to functions and return values from functions.
pc
- Program counter
- Hidden register