Abstract


2 main purposes

  1. Storing values during computations like Memory Address & value
  2. Configuring CPU to carry out computations

Registers have no datatypes

For example, add in MIPS assumes the data is in 2’s Complement (补码) and addu assumes the data is unsigned binary number.

The data stored in the register is interpreted according to the instruction that uses it.

Register Allocation

Register Spilling

  • When there are more variables than the available registers can hold (due to the limited number of registers), we encounter a situation known as register spilling
  • To handle this, some variables are temporarily saved to memory (usually the stack frame) and restored later when they are needed again

Memory Register


Memory Address Register

Memory Data Register

  • A register temporarily stores data that is being transferred to or retrieved from memory

Common Registers


Instruction Register

  • Holds the actual Instruction that is currently being executed by the CPU

Program Counter

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

Stack Registers


Stack Pointer

offset($sp)

Used to access a memory location relative to the current top of the stack.

; Decrement the stack pointer by 8 (allocate 8 bytes on the stack)
sub $sp, 8 
 
; Move the value at the memory location (sp + 4) into the eax register
mov 4($sp), %eax 

Frame Pointer

  • Maintains a reference point for the current Stack Frame
  • At the beginning of a function (prologue), the frame pointer is typically set to the stack frame
  • Throughout the function: The FP remains relatively unchanged, offering a stable reference point which is used to access data inside the new stack frame via displacement addressing mode

Optional!

The usage of FP is ISA dependent!

FP isn’t necessary for operation on the stack, it exists to provide convenience to the compiler.

Terminologies


Register Width

Register File

  • A collection of Register that CPU can use to quickly store and retrieve Data

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

References