The MIPS instructions set (RISC) have a fixed size for the instructions set as 32 bits. This bits are distributed in different parameters
ParametersOp (6Bits)→ Operation code for the instruction
This field mostly defines the format of the instruction and a major catergory (arithmetic, logic, load, inmediate, …)Rs (5Bits)→ Source 1 registry
Rt (5Bits)→ Source 2 registry
Rd (5Bits)→ Destination registry
Shamt (5Bits)→ Address Shift ammount
This field is used by some instructions that implement shifting any of its valuesFunc (6Bits)→ Variation of the Op instruction selected
This selects the specific operation to be performed (add, sub, addi, …)
The instructions have different formats based on the task they execute. The format used by the instruciton is determined by the Op field (which is common for all three formats)
Type R (Register operations)
This type of instructions perform arithmetic and logic operations. This instructions always have 3 registers
Example
For the instruction
add $1, $2, $3
(assuming thoose registes exist and its code matches its symbolic name).- The instruction will add the
$2
and$3
values and store it in the$1
register
- The add instruction have code
0
Binary format
0x0
→ Code (6Bits):add
(arithmetic instructions)
0x2
→ Rs (5Bits):$2
0x3
→ Rt (5Bits):$3
0x1
→ Rd (5Bits):$1
0x0
→ Shamt (5Bits)
0x20
→ Shamt (5Bits):add
Type L/I (Load/Inmediate)
Used by instructions that perform memory load/storage and conditional jumps. The inmediate value can be used for comparations or offset value
Type J (Jump)
Used by instructions that perform unconditional jump operations