In: Computer Science
For the following MIPS instructions, (1) show its format or type (I-format, R- format, or J- format); (2) translate them into binary using the follow procedure (Note: $s0-$s7 are the 16-23th registers, $t0-$t7 are the 8-15th registers). For example,
addi $s0, $s1, 2 # the op code of addi is 0010002
Format (?):
lw $s1, 4($s1) # the op code of lw is 1000112
Format (?):
bne $s1, $t1, loop # the value of loop here is 00102 and
# the op code of bne is 0001012
Format (?):
jal leaf # the value of leaf here is 0x2000016
# the op code of jal is 0000112
Format (?):
sub $t1, $s6, $0 # the op code of add is 0 and the funct code is 1000102
Format (?):
addi $s0, $s1,
2
I-format
ADDI $s1
$s0
immediate
001000 10001 10000
0000000000000010
Binary = 00100010001100000000000000000010
---------------------------------------------------------------------------------
lw $s1,
4($s1)
I-Format
LW
$s1
$s1
offset
100011 10001 10001
0000000000000100
Binary = 10001110001100010000000000000100
---------------------------------------------------------------------------------
bne $s1, $t1, loop
I-Format:
BNE
$s1 $t1
offset
000101 10001 01001
0000000000000010
Binary = 00010110001010010000000000000010
---------------------------------------------------------------------------------
jal
leaf
0x20000 >> 2 =
0x01000
J-Format
JAL
target
000011 00000000000001000000000000
Binary : 00001100000000000001000000000000
---------------------------------------------------------------------------------
sub $t1, $s6, $0
R-type
opcode $s6
$zero $t1
shamt SUB
000000 10110 00000
01001 00000 100010
Binary: 00000010110000000100100000100010