Advertisement
Alhiris

Untitled

Jan 13th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. .data
  2. n: .word 5
  3. v: .word 2, 4, 9, 15, 3
  4. .text
  5.  
  6.  
  7.  
  8.  
  9. main:
  10. li $t0,2
  11. subu $sp,4
  12. sw $t0,0($sp)
  13. li $v0,0
  14.  
  15. jal suma_patrate
  16.  
  17. addu $sp,4
  18.  
  19. move $a0,$v0
  20. li $v0,1
  21. syscall
  22.  
  23. li $v0,10
  24. syscall
  25.  
  26. modifica:
  27.  
  28.  
  29. suma_patrate:
  30. subu $sp,4 #push for $fp
  31. sw $fp,0($sp) #store $fp
  32. addi $fp,$sp,4 #Change $fp to point properly
  33. subu $sp,8 #push for $s0, $ra
  34. sw $s0,0($sp) #storing $s0
  35. sw $ra,4($sp) #for recursivity
  36.  
  37. # sp:($s0)($ra)($fp)fp:($t0)
  38.  
  39. lw $s0,0($fp) #Loading last s0 or t0
  40. subu $s0,1 #preparing to be added
  41. blez $s0,exitSum#if value not good exit
  42. subu $sp,4
  43. sw $s0,0($sp) #Preparing the 0($fp)
  44. jal suma_patrate
  45. addu $sp,4 #Erasing that 0($fp)
  46. mul $s0,$s0,$s0 #squared
  47. add $v0,$v0,$s0 #adding
  48.  
  49. exitSum: #exitting, getting variables back
  50. lw $s0,0($sp)
  51. lw $ra,4($sp)
  52. lw $fp,8($sp)
  53. addu $sp,12
  54. jr $ra #jumping back
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement