Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. Q1:
  2.  
  3. A: .word
  4. C: .word 10
  5. Index: .word 0
  6. list: .word 1, 2, 3, 4, 5, 0, 0, 0, 0, 0
  7.  
  8.  
  9. .text
  10.  
  11. li $t0, 10 # t0 is a constant 10 li $t1, 0 # t1 is our counter (i) loop:
beq $t1,$t0, end #if t1==10 we are done
  12. dsll $t3, $t1, 3
ld $t4 , list($t3)
  13. daddi $t5, $t5, t4
  14. sd $t5, result
  15. addi$t1,$t1,1 #add1tot1
j loop # jump back to the top end:
  16.  
  17. end:
  18. halt
  19.  
  20.  
  21. Q2:
  22.  
  23. .data
  24. C: .word 10
  25. Index: .word 0
  26. list: .word 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
  27.  
  28.  
  29. .text
  30.  
  31. main:
  32. ld r1, C(r0)
  33. ld r2, Index(r0)
  34. beq $r1,$r2, end; if (r1 = r2) then exit
  35. ld $t1, Index(r0)
  36. dsll $t1, $t1, 3; $t1 = 8 * $t1, save value into r4
  37. ld r4,list($t1)
  38. daddi $t1, $t1, 8
  39. ld r5,list($t1)
  40. daddy r3, r4, r5, ; add value at current index and next index together, save value into r3
  41. daddi $t1, $t1, 8
  42. sd r3, list($t1)
  43. daddi r2, r2, 1
  44. sd r2, Index(r0)
  45. j main
  46.  
  47. exit:
  48. halt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement