Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. .text
  6.  
  7. start: li $s0, 0 # i = 0
  8. li $t2, 15 # n = 15
  9. li $s1, 0 # x = 0
  10. li $s2, 0 # y = 0
  11.  
  12. cycle1: sltu $t4, $s0, $t2 # if (i >= n) <---------------------
  13. beq $t4, 0, res # goto res ------------ |
  14. # else | |
  15. li $s1, 0 # x = 0 | |
  16. subu $t3, $t2, $s0 # t3 = n - i | |
  17. | |
  18. cycle2: sltu $t6, $s1, $t3 # if (x >= t3) <-------+--------- |
  19. beq $t6, 0, cycle1End # goto cycle1End------+--- | |
  20. # else | | | |
  21. lw $t0, 0($s1) # t0 = ram[x] | | | |
  22. addiu $s2, $s1, 1 # y = x + 1 | | | |
  23. lw $t1, 0($s2) # t1 = ram[y] | | | |
  24. sltu $t5, $t1, $t0 # if (t0 >= t1) | | | |
  25. beq $t5, 0, cycle2End # goto cycle2End -+--|--- | |
  26. # else | | | | |
  27. move $s3, $t0 # s3 = t0 | | | | |
  28. move $t0, $t1 # t0 = t1 | | | | |
  29. move $t1, $s3 # t1 = s3 | | | | |
  30. sw $t0, 0($s1) # ram[x] = t0 | | | | |
  31. sw $t1, 0($s2) # ram[y] = t1 | | | | |
  32. | | | | |
  33. cycle2End: addiu $s1, $s1, 1 # x++ <--------------+--+--- | |
  34. b cycle2 # goto cycle2 --------+--+------ |
  35. | | |
  36. cycle1End: addiu $s0, $s0, 1 # i++ <--------------|--- |
  37. b cycle1 # goto cycle1 --------+------------
  38. |
  39. res: b res # finish! <-----------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement