Although called a "file", a register file is not related to disk files. A register file is a small set of high-speed storage cells inside the CPU. There are special-purpose registers such as the IR and PC, and also general-purpose registers for storing operands of instructions such as add, sub, mul, etc.
A CPU register can generally be accessed in a single clock cycle, whereas main memory may require dozens of CPU clock cycles to read or write.
Since there are very few registers compared to memory cells, registers also require far fewer bits to specify which register to use. This in turn allows for smaller instruction codes.
For example, the MIPS processor has 32 general-purpose registers, so it takes 5 bits to specify which one to use. In contrast, the MIPS has a 4 gibibyte memory capacity, so it takes 32 bits to specify which memory cell to use. An instruction with 3 operands will require 15 bits if they are all registers, and 96 bits if they are all memory addresses.
MIPS is a load-store architecture, which means that only load and store instructions can access memory. All other instructions (add, sub, mul, div, and, or, etc.) must get their operands from registers and store their results in a register.
Suppose x, y, and sum are variables in a program, and we want to translate the following statement to MAL:
sum = x + y
Since variables represent memory locations, the MIPS processor can only
use them in load and store instructions. The values must be first
loaded into CPU registers using load instructions. We can then add the
values in the CPU registers using
an add instruction, which must also put the result in a register. Finally,
we must use a store instruction to place the result in the variable
# sum = x + y lw $t0, x # Load x from memory into a CPU register lw $t1, y # Load y from memory into a CPU register add $t0, $t0, $t1 # Add x and y sw $t0, sum # Store the result from the CPU register to memory
The MIPS processor has one standard register file containing 32 32-bit registers for use by integer and logic instructions. These registers are called $0 through $31. Table 5.3, “MIPS Registers”.
The MIPS processor has a separate register file for floating point instructions, which contains another 32 32-bit registers called $f0 through $f31.
MIPS assembly language employs a convention for use of registers. This convention is not enforced by the assembler or the hardware, but it must be followed by all MIPS assembly language programmers in order to avoid unexpected behavior of modules written by different people.
Table 5.3. MIPS Registers
|Register Number||Conventional Name||Usage|
|$0||$zero||Hard-wired to 0|
|$1||$at||Reserved for pseudo-instructions|
|$2 - $3||$v0, $v1||Return values from functions|
|$4 - $7||$a0 - $a3||Arguments to functions - not preserved by subprograms|
|$8 - $15||$t0 - $t7||Temporary data, not preserved by subprograms|
|$16 - $23||$s0 - $s7||Saved registers, preserved by subprograms|
|$24 - $25||$t8 - $t9||More temporary registers, not preserved by subprograms|
|$26 - $27||$k0 - $k1||Reserved for kernel. Do not use.|
|$28||$gp||Global Area Pointer (base of global data segment)|
|$f0 - $f3||-||Floating point return values|
|$f4 - $f10||-||Temporary registers, not preserved by subprograms|
|$f12 - $f14||-||First two arguments to subprograms, not preserved by subprograms|
|$f16 - $f18||-||More temporary registers, not preserved by subprograms|
|$f20 - $f31||-||Saved registers, preserved by subprograms|