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

register set is also given for you to look up register nanes 1: add 2 lw 3: addi

ID: 3888716 • Letter: R

Question

register set is also given for you to look up register nanes 1: add 2 lw 3: addi 3, (20%) Consider the below C code snippet: char al3] for (int i- 0i3; m) ali)- alil+32 (1), (14%) Complete the corresponding MIPS assembly code by adding three instructions. Assume that the base address of the array a is in SO addi addi LOOP beq add Ss1, S0, 0 Stl, SO, 3 #i-0 # St 1-3 for loop termination Ss1. St1·DONE S12, SsI, Ss0 # this calculates the memory address of the current element addi SsI, Ss1, LOOP DONE: (2) (6%) If the array a is initialized as {A','B','C), what are the elements of the array a after above code is run?

Explanation / Answer

//Set lower and upper limit of array

addi $s1,$0,0 #i=0

addi $t1,$0,3 #$t1 = 3 upper limit of an array

LOOP

beq $s1,$t1,DONE #Ends if s1 and t1 equal i.e., loop condition(i<3)

add $t2,$s1,$s0 #t2 has address current array index ( assume addr of $s0 is 1000 t2 will have 1000 in first iter and 1001 in 2nd iter

lw $t3,0($t2) #load content of address in t2 into $t3 value of a[i]

add $t3, $t3,32 # t3= a[i](t3)+32

sw $t3,0(t2) #a[i]=t3

addi $s1,$s1,1 #i=i+1/i++

j LOOP

DONE