180k views
1 vote
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f , g , h , i , and j are assigned to registers $s0 , $s1 , $s2 , $s3 , and $s4 , respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7 , respectively.sll $t0, $s0, 2 # $t0 = f * 4add $t0, $s6, $t0 # $t0 = &A[f]sll $t1, $s1, 2 # $t1 = g * 4add $t1, $s7, $t1 # $t1 = &B[g]lw $s0, 0($t0) # f = A[f]addi $t2, $t0, 4lw $t0, 0($t2)add $t0, $t0, $s0sw $t0, 0($t1)

2 Answers

2 votes

Final answer:

The corresponding C statement for the given MIPS assembly instructions involves assigning values, adding, and dereferencing pointers.

Step-by-step explanation:

The MIPS assembly instructions given above can be translated to the following C statement:

f = A[f];

t2 = t0 + 4;

t0 = t0 + f;

*t1 = t0;

These instructions involve operations such as shifting, adding, and loading from memory. The C statement assigns values to the variables and dereferences a pointer to store a value in memory.

User Ajay Pal Singh
by
4.0k points
4 votes

Answer / Explanation:

Before we answer this question, let us try to understand the meaning of some basic terms as this we help us in better understand the answer provided:

MIPS: This can be refereed to as the assembly language assigned to MIPS processor.

The abbreviated word MIPS means Microprocessor without Interlocked Pipeline Stages and it is a reduced-instruction set architecture.

Now, going back to the question, the answer goes thus:

sll $t0, $s0, 2 // $t0 = f * 4;

add $t0, $s6, $t0 // $t0 = &A[f];

sll $t1, $s1, 2 // $t1 = g * 4;

add $t1, $s7, $t1 // $t1 = &B[g];

lw $s0, 0($t0) // f = A[f];

addi $t2, $t0, 4 // $t2 = &A[f + 1];

We therefore note that:

// Note here f is still of the original value.

w $t0, 0($t2) // $t0 = A[f + 1];

add $t0, $t0, $s0 // $t0 = A[f + 1] + A[f]; // Here assumes a nop.

sw $t0, 0($t1) // B[g] = A[f + 1] + A[f];

Now, considering for the overall register:

Overall:

B[g] = A[f + 1] + A[f];

f = A[f];

It can now therefore be concluded that the two statements in the narrative in the question cannot swap order.

User Siva Kandaraj
by
4.2k points