Datapath Elements (Cont.)

Register File
A register file is a collection of registers in which any register can be read or written by specifying the number of the register in the file.

The register file has 2 read ports and 1 write port because each R-format instruction requires to read 2 data words from the register file and write 1 data word into the register file like
   sub  $a0, $t1, $t0    # $a0 = $t1 - $t0
The register file outputs the contents of the registers corresponding to the Read register inputs on the outputs; no other control inputs are needed. In contrast, a register write must be indicated by the write control signal.

The inputs carrying the register number to the register file are all 5 bits wide to specify one of 32 registers (32=25), whereas the lines carrying data values are 32 bits wide.

Writes are edge-triggered, so that all the write inputs must be valid at the clock edge.

Since writes to the register file are edge-triggered, our design can legally read and write the same register within a clock cycle. The read will get the value written in an earlier clock cycle, while the value written will be available to a read in a subsequent clock cycle.