Translate the following loop into C. Assume that the C-level integer i is held in register $t1, $s2 holds the C-level integer called result, and $s0 holds the base address of the integer MemArray.

addi$t1, $0, $0
Loop: lw$s1, 0($s0)
add$s2, $s2, $s1
addi$s0, $s0, 4
addi$t1, $t1, 1
slti$t2, $t1, 100
bne$t2, $s0, Loop

Respuesta :

Answer:

What this loop is doing, is the sum of the elements of an array(located in $s0). The program does the following:

initializes $t1 = 0

loads the actual value of the array

sums the value of the actual position of the array with the total

then, it moves the pointer of the array, for it to get the next value on the next iteration

increase the counter($t1)

check if ($t1 reached 100)

if $t1 had not reached 100, it does all over again.

So, translating the code into C, that would be:

for(i=0;i<100;i++){

  result=result+ MemArray[i];

}

Explanation:

Loops are program statements that are used to perform repeated operations

The loop that represents the assemble language operation is:

for(i=0;i<100;i++){

 result=result+ MemArray[i];

}

From the program instructions, we have the following highlight

The program adds up the elements in the array $s0 of 100 elements

Given that the base address of the integer MemArray.

Then the array in the C program would be MemArray.

Hence, the required loop is:

for(i=0;i<100;i++){

 result=result+ MemArray[i];

}

Read more about loops at:

https://brainly.com/question/14284157