Menu

(Solved) : Pcspim Modify Code Sum 1 10 Globl Main Main Main Global Label Addu S7 0 Ra Save Return Add Q38012253 . . .

pcspim
Modify the code
to sum from 1 to 10

.globl main
main:           #main has to be a global label
   addu   $s7, $0, $ra   #save thereturn address in a global register

   #Initialize variables  
   add        $s3, $0,$0        #i = 0
   addi       $s4, $0,1         #j = 1
   add   $s5, $0, $0   #k = 0 soprogram finds first nonzero value of save  
   la   $s6, save   #$s6 has thestarting address of save

           #Allocate 10-word array save
          .data
          .align2                 #Let’s make sure that it’s aligned
   .globl save
save:   .word 0, 0, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1

   .text
Loop:            
   add   $t1, $s3,$s3   #Temporaryregister $t1 = 2*i
   add   $t1, $t1, $t1   #Doubleagain so temporary register has 4*i
   add   $t1, $t1, $s6   #Add arraystart address so t1 has address of save[i]
   lw   $t0, 0($t1)   #Temporaryregister $t0 has value of save[i]
   bne   $t0, $s5, Exit   #If save[i]!= k, go to Exit

   add   $s3, $s3, $s4  # i = i + j
   j   Loop      # goto Loop
Exit:

                             #Output the value of i to see how far we got
          .data
           .globlmessage1
message1:       .asciiz “nThe valueof i is: “
           #string to print
          .text
       
   li      $v0,4            #print_str (system call 4)
   la      $a0,message1   # takes the address of string as anargument
          syscall
          
   li      $v0,1            #print_int (system call 1)
          add     $a0, $0,$s3       #put value i in $a0 forprinting
          syscall
  
                               #Usual stuff at the end of the main
   addu   $ra, $0, $s7   #restore thereturn address
   jr   $ra     #return to the main program
   add   $0, $0, $0   #nop

Expert Answer


Answer to Pcspim Modify Code Sum 1 10 Globl Main Main Main Global Label Addu S7 0 Ra Save Return Add Q38012253 . . .

OR