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

20 pt) An array of 100 words is allocated starting at the address \'arr 00\' (de

ID: 3901979 • Letter: 2

Question

20 pt) An array of 100 words is allocated starting at the address 'arr 00' (declared as 'arr100: word :100' i n the data segment). Fill in the comment area in the following MIPS codes using the pseudo- syntax with ‘goto". Use variables temp for Sto, and x for Sal in comments. li Ss0,1 #1 1, initialization lw $t0, arr 100($zero) # temp lw $al , arri00($s0) ble Sal, StO, skip move St0, Sal #x- skip: sra Ss0, Ss0, 2 addi $s0, Ss0, 1 blt Ss0,100, p or the codes shown above, write a C code without 'goto.

Explanation / Answer

Comment the above code

#This is a program to find largest number in an array
#temp keep first element of the array
#compare with all other elements in the array
#if less than temp then change temp into element in a1
#here s0 is taken as counter for 100 elements
li $s0,1               #i=1,Initialization
lw $t0,arr100($zero)   #temp=first element of arr100
p0:
   sll $s0,$s0,2        # i=4
   lw $a1,arr100($s0)   #x=second element of the array
   ble $a1,$t0,skip     #if (x<=temp) goto skip
   move $t0,$a1         #temp=x
skip:
   sra $s0,$s0,2        #i=1
   addi $s0,$s0,1       #i=2
   blt $s0,100,p0      #if(i<100)goto p0

---------------------------------------------------------------------------------

C code

for(int i=1;i<=100;i++){
       int temp=arr100[i];
       int x=arr100[i+1];
       if(x>temp){
           temp=x;
       }
   }