In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere. Most, but not all, modern computer architectures operate on the principle of moving data from main memory into registers, operating on them, then moving the result back into main memory—a so-called load-store architecture. A common property of computer programs is locality of reference: the same values are often accessed repeatedly; and holding these frequently used values in registers improves program execution performance.
Processor registers are at the top of the memory hierarchy, and provide the fastest way for a CPU to access data. The term is often used to refer only to the group of registers that are directly encoded as part of an instruction, as defined by the instruction set. More properly, these are called the "architectural registers". For instance, the x86 instruction set defines a set of eight 32-bit registers, but a CPU that implements the x86 instruction set will often contain many more registers than just these eight.
Allocating frequently used variables to registers can be critical to a program's performance. This action, namely register allocation is performed by a compiler in the code generation phase.
Categories of registers
Registers are normally measured by the number of bits
they can hold, for example, an "8-bit
register" or a "32-bit
register". Registers are now usually implemented as a register file
, but they have also been implemented using individual flip-flops
, high speed core memory
, thin film memory
, and other ways in various machines.
A processor often contains several kinds of registers, that can be classified according to their content or instructions that operate on them:
- User-accessible Registers - The most common division of user-accessible registers is into data registers and address registers.
- Data registers are used to hold numeric values such as integer and floating-point values. In some older and low end CPUs, a special data register, known as the accumulator, is used implicitly for many operations.
- Address registers hold addresses and are used by instructions that indirectly access memory.
- Some processors contain registers that may only be used to hold an address or only to hold numeric values (in some cases used as an index register whose value is added as an offset from some address); others allow registers hold either kind of quantity. A wide variety of possible addressing modes, used to specify the effective address of an operand, exist.
- A stack pointer, sometimes called a stack register, is the name given to a register that can be used by some instructions to maintain a stack (data structure).
- Conditional registers hold truth values often used to determine whether some instruction should or should not be executed.
- General purpose registers (GPRs) can store both data and addresses, i.e., they are combined Data/Address registers.
- Floating point registers (FPRs) store floating point numbers in many architectures.
- Constant registers hold read-only values such as zero, one, or pi.
- Vector registers hold data for vector processing done by SIMD instructions (Single Instruction, Multiple Data).
- Special purpose registers hold program state; they usually include the program counter (aka instruction pointer), stack pointer, and status register (aka processor status word).
- In some architectures, model-specific registers (also called machine-specific registers) store data and settings related to the processor itself. Because their meanings are attached to the design of a specific processor, they cannot be expected to remain standard between processor generations.
- Control and status registers - It has three types. Program counter, instruction registers, Program status word (PSW).
- Registers related to fetching information from RAM, a collection of storage registers located on separate chips from the CPU (unlike most of the above, these are generally not architectural registers):
Hardware registers are similar, but occur outside CPUs.
The table below shows the number of registers of several mainstream architectures. Note that the stack pointer (ESP) is counted as an integer register on x86-compatible processors, even though there are a limited number of instructions that may be used to operate on its contents. Similar caveats apply to most architectures.