Abstract
- A group of D Flip-flops
- Accessible via Instruction
2 main purposes
- Storing values during computations like Memory Address & value
- Configuring CPU to carry out computations
Registers have no datatypes
For example,
add
in MIPS assumes the data is in 2’s Complement (补码) andaddu
assumes the data is unsigned binary number.The data stored in the register is interpreted according to the instruction that uses it.
Register Allocation
Memory Register
Memory Address Register
- Register that points to Memory Address that contains the data required by the current Instruction that is being executed
Memory Data Register
Common Registers
Instruction Register
- Holds the actual Instruction that is currently being executed by the CPU
Program Counter
- Also known as Instruction Address Register, Instruction Pointer
- For modern computers, it is the Register that indicates the Virtual Address of the next Instruction to be executed for the current Process (进程)
Stack Pointer
- A Register that holds the Memory Address of the top of the Stack Segment in the current execution context. Here is the Diagram
offset($sp)
Used to access a memory location relative to the current top of the stack.
Frame Pointer
- Maintains a reference point within the current Stack Frame
- At the beginning of a function (prologue), the Frame Pointer is typically set to the current value of the Stack Pointer, establishing the base of the current stack frame
- Throughout the function: The FP remains relatively unchanged, offering a stable reference point
Control & Status Registers (CSRs)
- There are multiple such registers in the CPU, the main purpose is storing information about the current state of the processor or device
- CSRs are typically used to control various aspects of the processor’s operation, such as interrupt handling, memory management, and power management etc
Terminologies
Register Width
Register File
Memory Mapped Register
- Register that can be accessed via a Main Memory location
- This means that the register can be accessed using the same Instruction and addressing modes as memory.
- Often used to control hardware devices, such as IO Device (Like the UART in XV6) and memory controllers
XV6-RISCV Memory Mapped Registers