The R-Type Instruction

A typical MIPS instruction is a string of 32 binary digits together. An example of a R-type instruction can look like this:

0000 0001 0000 0011 0001 0000 0010 0000

In order to simplify things, the instruction can be segmented as follows:

000000 01000 00011 00010 00000 100010

For the R-type instruction, there are six components.
  • Operation code
  • First source register
  • Second source register
  • Destination register
  • Shift amount
  • Function bits
And as you have already guessed it, each segment of bits correspond to one of the above component.
Component Bit range Example
Opcode
31st to 26th
000000 01000 00011 00010 00000 100010
First source register
21st to 25th
000000 01000 00011 00010 00000 100010
Second source register
16th to 20th
000000 01000 00011 00010 00000 100010
Destination register
11th to 15th
000000 01000 00011 00010 00000 100010
Shift amount
6th to 10th
000000 01000 00011 00010 00000 100010
Function bits
0th to 5th
000000 01000 00011 00010 00000 100010
The syllabus that will be followed dictates the following function bits and their binary representative:
Function bits Binary representative
ADD
100000
SUB
100010
AND
100100
OR
100101
SLT
101010
With some decoding,

000000 01000 00011 00010 00000 100010

SUB $2, $8, $3

Or simply put,

Subtract the contents of $3 from $8 and store it in $2

The I-Type Instruction

An example of a I-type instruction can look like this:

001000 00001 00110 0000000000001010

But this time, the components are different, as shown below:
Component Bit range Example
Opcode
31st to 26th
001000 00001 00110 0000000000001010
Source register
21st to 25th
001000 00001 00110 0000000000001010
Destination register
16th to 20th
001000 00001 00110 0000000000001010
Immediate data
0th to 15th
001000 00001 00110 0000000000001010
With a little decoding,

001000 00001 00110 0000000000001010

ADDI $6, $1, #10

Or simply put,

Add the value of 10 to the contents of $1 and store it in $6