Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #Dr. Mark Petzold
  2.  
  3. .data
  4. array: .word 1, 3, 5, 7, 9, 11, 13, 15, 17, 19
  5. .word 21, 23, 25, 27, 29, 31, 33, 35, 37, 39
  6. length: .word 20
  7. sum: .word 0
  8. average: .word 0
  9. msg1: .asciiz "Sum = "
  10. msg2: .asciiz "\nAverage = "
  11.  
  12. .text
  13. .globl main
  14. main:
  15. la $t0, array #array starting address
  16. li $t1, 0 #loop index, i = 0
  17. lw $t2, length #length
  18. li $t3, 0 #initialization sum
  19.  
  20.  
  21. sumLoop:
  22. lw $t4, ($t0) #get array[i]
  23. add $t3, $t3, $t4
  24. add $t1, $t1, 1
  25. add $t0, $t0, 4
  26.  
  27. blt $t1, $t2, sumLoop
  28.  
  29. sw $t3, sum #save sum
  30.  
  31. la $a0, msg1
  32. li $v0, 4
  33. syscall
  34. lw $a0, sum
  35. li $v0, 1
  36. syscall
  37.  
  38. li $v0, 10
  39. syscall
  40. .end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement