In: Computer Science
Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x2fff0004.
Loop: lw $t0, 4($s0)
addi $t1, $t1, -15
sll $t1, $t1, 2
beq $t1, $s1, Exit
addi $s0, $s0, 4
j Loop
Exit: …
Please find the answer below::
LW $t0 0x0004 $s0
For the instruction, the format is as below
Binary: 10001110000010000000000000000100
Hex: 0x8e080004
2. addi $t1, $t1, -15
Instruction is as below
ADDI $t1 $t1 0xFFF1
Binary: 00100001001010011111111111110001
Hex: 0x2129fff1
3.
sll $t1, $t1, 2
Binary: 00000000000010010100100010000000
Hex: 0x00094880
4.
BEQ $t1 $s1 0x0002
Binary: 00010001001100010000000000000010
Hex: 0x11310002
5.
ADDI $s0 $s0 0x0004
Binary: 00100010000100000000000000000100
Hex: 0x22100004
6.
j Loop
Address of loop is : 0x2fff0004
IN binary it is:
101111111111110000000000000100
Converting to 26 bit it will be :
11111111111100000000000001
Adding 000010 as MSD for jump
SO complete instruction will be : 00001011111111111100000000000001
In hexa decimal it will be : 0xbffc001