Advertisement
Alhiris

Untitled

Jan 13th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. .data
  2. n: .word 5
  3. v: .word 2, 4, 9, 15, 3
  4. .text
  5.  
  6. suma_patrate:
  7. subu $sp,4 #push for $fp
  8. sw $fp,0($sp) #store $fp
  9. addi $fp,$sp,4 #Change $fp to point properly
  10. subu $sp,8 #push for $s0, $ra
  11. sw $s0,0($sp)
  12. sw $ra,4($sp) #for recursivity
  13.  
  14. # $sp =($s0),($ra),($fp),fp:($t0)
  15.  
  16. lw $s0,0($fp)
  17. subu $s0,1
  18. sw $s0,0($fp) #Changing parameter now $s0 will be changed
  19. beq $s0,$0,exitSum
  20. mul $s0,$s0,$s0
  21. add $v0,$s0,$0
  22.  
  23. jal suma_patrate
  24.  
  25.  
  26.  
  27. exitSum:
  28. lw $s0,0($sp)
  29. lw $ra,4($sp)
  30. lw $fp,8($sp)
  31. addu $sp,12
  32. jr $ra
  33.  
  34.  
  35. main:
  36. li $t0,5
  37. subu $sp,4
  38. sw $t0,0($sp)
  39. li $v0,0
  40.  
  41. jal suma_patrate
  42.  
  43. addu $sp,4
  44.  
  45. move $a0,$v0
  46. li $v0,1
  47. syscall
  48.  
  49. li $v0,10
  50. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement