To practice using base addressing to implement arrays in PCSpim. You will also use loops.
Read lab lecture notes.
## ## Program Name: loop1.s ## ## - will calculate the sum of the elements in "array". ## - "count" holds the number of elements in "array". ## ## ## - Output format must be ## "sum = 15" ## ## t0 - point to array elements in turn ## t1 - contains count of elements ## t2 - contains sum ## ## t3 - each word from array in turn ## ################################################# # # # text segment # # # ################################################# .text .globl __start __start: # execution starts here # Put your answer between dashed lines. # #------------------Your code starts next line--------------- #-----------------Your code ends above this line---------------- la $a0,endl # syscall to print out li $v0,4 # a new line syscall li $v0,10 # Exit syscall # Bye! ################################################# # # # data segment # # # ################################################# .data array: .word 3,4,2,6 count: .word 4 ans1: .asciiz "sum = " endl: .asciiz "\n" ## ## end of file loop1.s
## ## Program Name: loop2.s ## ## - will calculate the sum of all elements in the array "numbers" ## whose value is less than or equal to 1000. ## - "numbers" is an array with 5 integer elements. ## - "count" holds the number of elements in "numbers". ## ## ## - Output format must be ## "sum = 11" ## ## t0 - points to array elements in turn ## t1 - contains a count of elements ## t2 - contains sum ## ## t3 - each word from the array "numbers" in turn ## ################################################# # # # text segment # # # ################################################# .text .globl __start __start: # execution starts here # Put your answer between dashed lines. # #------------------Your code starts next line--------------- #-----------------Your code ends above this line---------------- la $a0,endl # syscall to print out li $v0,4 # a new line syscall li $v0,10 # Exit syscall # Bye! ################################################# # # # data segment # # # ################################################# .data numbers: .word 3,2000,2,6,3000 count: .word 5 ans1: .asciiz "sum = " endl: .asciiz "\n" ## ## end of file loop2.s