A register file is a small, fast memory made of registers. It holds a CPU's general-purpose registers, such as R0–R7.
Its parts:
- Storage: k load enable registers, each n bits wide, for k × n bits in total.
- Address: log₂ k bits pick one register. 8 registers need 3 address bits; 32 need 5.
- Write port: a write address, n data bits and a write enable W. At a rising edge with W = 1, only the addressed register loads the data.
- Read port: a read address selects a register, whose value appears on n output bits. Most register files have two read ports and one write port, so an instruction like ADD R1, R2, R3 can read two operands and write one result each cycle.
How it is built:
- Write: a decoder turns the write address into one-hot lines, each ANDed with W to form that register's load enable.
- Read: for each output bit, a k:1 multiplexer picks that bit from the addressed register. A second read port needs a second, independent set of MUXes.
Reading is combinational and writing happens at the edge. So a read of the register being written shows the old value until the edge; see read during write.
Compared with main memory (ram), a register file is tiny but can be read and written in the same cycle with very little delay, which is why the CPU's working values live there.