Given Instructions:
addi $t0,$s6,4
add $t1.$s6,$0
sw $t1, 0($t0)
lw $t0,0($t0)
add $s0,$t1,$t0
The instruction type and fields are as follows:
Instructionaddi $t0,$s6,4:
Instructions | Type | OP | RS | RT | RD | immediate |
addi $t0,$s6,4 | I-type | 8 | 22 | 8 | | 4 |
The above instruction is I-type , since, it has immediate value of 4. The opcode of addi instruction is 8. The value of source register is 22 and the target register is 8. The immediate value 4 will be added to the value of source register and the result will be stored in target register.
Instruction :add $t1.$s6,$0
Instructions | Type | OP | RS | RT | RD | immediate |
add $t1,$s6, $0 | R-type | 0 | 22 | 0 | 9 | |
The above instruction is R-type , since the values are added by the registers. The value of opcode is 0 and the value of source register is 22. The value of destination register is 9.
Instructions:sw $t1, 0($t0)
lw $t0,0($t0)
Instructions | Type | OP | RS | RT | RD | immediate |
sw $t1, 0($t0) | I-type | 43 | 8 | 9 | | 0 |
lw $t0, 0($t0) | I-type | 35 | 8 | 8 | | 0 |
Both the above instructions are I-Type , because they have immediate type addressing.
Sw instruction will store the data at the specified address with the possible offset, from a source register. The Opcode is 43 and the value of source and target registers are 8 and 9 respectively.
Lw instruction loads the word to the specified address. The Opcode is 35 and the value of source and target registers are 8 and 8 respectively.
Instruction: add $s0,$t1,$t0
Instructions | Type | OP | RS | RT | RD | immediate |
add $s0,$t1,$t0 | R-type | 0 | 9 | 8 | 16 | |
The above instruction is R-type , since the values are added by the registers. The value of opcode is 0 and the value of source register is 9. The value of target register is 8 and the destination register has 16.