Every modern processor includes multiple (very small) super-fast memory banks, called registers. The registers are the most easily accessible memory location for the CPU and sit on the top of the memory hierarchy. They are much smaller than local memory and are used to store machine instructions, memory addresses, and certain other values. Data is loaded from the main memory to the registers (via the CPU cache) after which it undergoes various arithmetic operations. The manipulated data is then written back to the memory via the CPU cache.
Processor Registers: Definition and Function
The size of a register usually depends on the CPU type. A 64-bit processor will generally have 64-bit registers as it deals with 64-bit instructions. There are, however, other smaller registers too called half registers for executing shorter instructions.
Other than providing the CPU with a platform to execute machine instructions at a steady pace, the registers also improve the latency in repetitious tasks (just like the cache memory). By storing the memory addresses of frequently accessed data, the performance can be significantly improved.
Physical vs Logical Registers
Modern processors tend to have multiple physical registers associated with every logical register. Programmers and designers interface with the logical registers while their physical counterparts are manipulated indirectly. This helps avoid false data dependencies that may arise from the repeated use of the same register by successive instructions which in turn improves instruction-level parallelism. It also allows speculative execution and branch prediction.
Types of CPU Registers
Modern processors have several different kinds of registers, the main ones being data registers, address registers, general-purpose registers, and special-purpose registers.
General Purpose Registers (GPRs): General purpose registers are a unified kind of register. The can hold memory addresses, data values as well as floating-point values. They are generally used by most modern CPUs as well as GPUs due to their flexibility.
Special Purpose Registers (SPRs): Special-purpose registers are generally used to store the program state. They usually consist of the program counter and the status register. Modern architectures usually combine the two into one register.
Accumulator: The accumulator stores integer values that may be required by the ALU for the execution of a particular instruction. The Accumulator is a General Purpose Register.
Memory Address Registers: The address registers hold the memory addresses of the next address to be executed to the CPU. They are stored in the address register by the Progam Counter. The Address Registers are Special Purpose Registers.
Program counter: The program counter is a kind of SPR. It exists in the Control Unit of the CPU and holds the memory address of the next instruction to be executed. It handles the job of putting the instructions back in order and keeps a track of the number of the executed instructions. The Program Counter is a Special Purpose Register.
Memory Data Registers: After the Program Counter enters the memory address into the MAR, the processor fetches the required instructions and data from the memory (via the cache) and a temporary copy is stored in the data register. The MAR is a Special Purpose Register.
The data registers store data in the form of numeric values such as integers and sometimes, floating-point values. Many architectures have separate registers for FP values. In primitive designs, the data register is also called the accumulator.
Current Instruction Register: The CIR holds a copy of the instruction currently in the MDR. It is split into two parts. One is decoded into micro-ops by the CPU decoder and the other is the memory address of the required data needed for their execution. The Current Instruction Register is a Special Purpose Register.