Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Translate the following loop into C. Assume that the C-level integer i is hel

ID: 3547953 • Letter: 1

Question

1.

Translate the following loop into C. Assume that the C-level integer i is held in register $t1; $t2 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,      St1,      1

            Slti       $t2,      $t1,      100

            Bne      $t2,      $S0,     LOOP


2.


Write a code that reads from variable N multiplies by 5, adds 25 and stores the result invariable M. Both variables are 32-bit (M = 5*N + 25).

N is stored in $t1. M is stored in $s1.

Explanation / Answer

1.

{ // Code in C

i = 0 ;

while(i<100)

{

temp += i;

i++;

}



2.

#code in mips

# $t1 has N

# $s1 has the result M

muli $s1, $t1, 5

addi $s1 , $s0 , 25