A MIPS processor consists of an integer processing unit (the CPU) and a collection of coprocessors that perform ancillary tasks or operate on other types of data such as floating point numbers (see Figure 2). SPIM simulates two coprocessors. Coprocessor 0 handles traps, exceptions, and the virtual memory system. SPIM simulates most of the first two and entirely omits details of the memory system. Coprocessor 1 is the floating point unit. SPIM simulates most aspects of this unit.
Figure 2: MIPS R2000 CPU and FPU
The MIPS (and SPIM) central processing unit contains 32 general purpose 32-bit registers that are numbered 0--31. Register n is designated by $n. Register $0 always contains the hardwired value 0. MIPS has established a set of conventions as to how registers should be used. These suggestions are guidelines, which are not enforced by the hardware. However a program that violates them will not work properly with other software. Table 2 lists the registers and describes their intended use.
Register Name Number Usage zero 0 Constant 0 at 1 Reserved for assembler v0 2 Expression evaluation and v1 3 results of a function a0 4 Argument 1 a1 5 Argument 2 a2 6 Argument 3 a3 7 Argument 4 t0 8 Temporary (not preserved across call) t1 9 Temporary (not preserved across call) t2 10 Temporary (not preserved across call) t3 11 Temporary (not preserved across call) t4 12 Temporary (not preserved across call) t5 13 Temporary (not preserved across call) t6 14 Temporary (not preserved across call) t7 15 Temporary (not preserved across call) s0 16 Saved temporary (preserved across call) s1 17 Saved temporary (preserved across call) s2 18 Saved temporary (preserved across call) s3 19 Saved temporary (preserved across call) s4 20 Saved temporary (preserved across call) s5 21 Saved temporary (preserved across call) s6 22 Saved temporary (preserved across call) s7 23 Saved temporary (preserved across call) t8 24 Temporary (not preserved across call) t9 25 Temporary (not preserved across call) k0 26 Reserved for OS kernel k1 27 Reserved for OS kernel gp 28 Pointer to global area sp 29 Stack pointer fp 30 Frame pointer ra 31 Return address (used by function call)
Table 2: MIPS registers and the convention governing their use.
Register Name | Number | Usage |
BadVAddr | 8 | Memory address at which address exception occurred |
Status | 12 | Interrupt mask and enable bits |
Cause | 13 | Exception type and pending interrupt bits |
EPC | 14 | Address of instruction that caused exception |
Figure 3: The Status register.
Figure 3 describes the bits in the Status register that are implemented by SPIM. The interrupt mask contains a bit for each of the five interrupt levels. If a bit is one, interrupts at that level are allowed. If the bit is zero, interrupts at that level are disabled. The low six bits of the Status register implement a three-level stack for the kernel/user and interrupt enable bits. The kernel/user bit is 0 if the program was running in the kernel when the interrupt occurred and 1 if it was in user mode. If the interrupt enable bit is 1, interrupts are allowed. If it is 0, they are disabled. At an interrupt, these six bits are shifted left by two bits, so the current bits become the previous bits and the previous bits become the old bits. The current bits are both set to 0 (i.e., kernel mode with interrupts disabled).
Figure 4: The Cause register.
Number | Name | Description |
0 | INT | External interrupt |
4 | ADDRL | Address error exception (load or instruction fetch) |
5 | ADDRS | Address error exception (store) |
6 | IBUS | Bus error on instruction fetch |
7 | DBUS | Bus error on data load or store |
8 | SYSCALL | Syscall exception |
9 | BKPT | Breakpoint exception |
10 | RI | Reserved instruction exception |
12 | OVF | Arithmetic overflow exception |
Byte # | |||
0 | 1 | 2 | 3 |
Byte # | |||
3 | 2 | 1 | 0 |
Format | Address Computation |
(register) | contents of register |
imm | immediate |
imm (register) | immediate + contents of register |
symbol | address of symbol |
symbol ± imm | address of symbol + or - immediate |
symbol ± imm (register) | address of symbol + or - (immediate + contents of register) |