1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Operand
Operand Location
Physical location in computer
Registers
Memory
Constants (also called immediates)
Registers
It is faster than memory and RISC-V has 32 32-bit registers. Can use either name (i.e., ra, zero) or x0, x1, etc. Using name is preferred. Registers used for specific purposes:
zero always holds the constant value 0.
the saved registers, s0-s11, used to hold variables
the temporary registers, t0-t6, used to hold intermediate values during a larger computation
Why 12-bit Constant (Immediate)?
Instruction size constraint
RISC-V uses fixed 32-bit instruction encoding (for the base ISA).
The I-type format (used by addi) allocates:
7 bits → opcode
5 bits → destination register
5 bits → source register
3 bits → funct3
12 bits → immediate
2. Balance between compactness and usefulness • 12 bits signed immediate is enough for: • small constants • stack pointer/frame pointer adjustments • offset addressing for loads/stores • For larger constants, RISC-V provides lui (load upper immediate) and auipc (add upper immediate to PC). Combining these with addi lets you construct 32-bit constants efficiently
Why 12-bit Constant (Immediate)?
Instruction size constraint: RISC-V uses fixed 32-bit instruction encoding (for the base ISA).
Balance between compactness and usefulness: 12 bits signed immediate is enough for small constants, stack pointer/frame pointer adjustments and offset addressing for loads/stores.
For larger constants, RISC-V provides lui (load upper immediate) and auipc (add upper immediate to PC). Combining these with addi lets you construct 32-bit constants efficiently
zero
Register Number: x0
Usage: Hardwired to Constant value 0
ra
Register Number: x1
Usage: Return address
sp
Register Number: x2
Usage: Stack Pointer
gp
Register Number: x3
Usage: Global Pointer
tp
Register Number: x4
Usage: Thread Pointer
t0-2
Register Number: x5-7
Usage: Temporaries
s0/fp
Register Number: x8
Usage: Saved register / Frame pointer
s1
Register Number: x9
Usage: Stack Pointer
a0-1
Register Number: x10-11
Usage: Function arguments / return values
a2-7
Register Number: x12-17
Usage: Function arguments
s2-11
Register Number: x18-27
Usage: Saved registers (to hold variables)
t3-6
Register Number: x28-31
Usage: Temporaries