Convert the following code to MIPS then convert to Cprogram

Convert the following code to MIPS, then convert to C-program. The numbers on the left in the square brackets are the memory address, while the numbers on the right is the content of the memory address. Both are in hex. (0.5 times 2 = 1 mk) [0x00400000] 0x20080000 [0x00400004] 0x0089502A

Solution

0x20080000 = 00100000000010000000000000000000
Here the first 6 bits are: 001000.
And this means its ADDI instruction.
And the pattern is: ADDI rt, rs, immediate
So, the binary instruction is:
001000 00000 01000 0000000000000000
001000 is ADDI.
00000 is $t0 is the target register.
01000 is $zero is the source register.
0000000000000000 is the immediate value.
So, the instruction is: $t0 <- $zero + 0, i.e., $t0 <- 0
And its C equivalent code is: var1 = 0;

0x0089502A = 00000000100010010101000000101010
Here the first 6 bits are: 000000.
And this means its a SPECIAL instruction.
So, picking the last 6 bits, 101010 means its a SLT instruction.
And the pattern is: SLT rd, rs, rt
So, the binary instruction is:
000000 00100 01001 01010 00000 101010
000000 is SPECIAL.
00100 is $a0 is the source register.
01001 is $t1 is the target register.
01010 is $t2 is the destination register.
00000 is 0
101010 is SLT (Set on Less Than)
So, the instruction is: $t2 <- $a0 < $t1
And its C equivalent code is:
if(var2 < var3)
var1 = 1;

 Convert the following code to MIPS, then convert to C-program. The numbers on the left in the square brackets are the memory address, while the numbers on the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site