Advertisement
math230

# Simple MIPS functions that preserves registers

Jul 20th, 2020
2,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Simple MIPS functions that preserves registers
  2. .data
  3.  
  4. .text
  5.  
  6. .globl main
  7. main:
  8.  
  9.   li $a0, 9
  10.   li $a1, 4
  11.   li $a2, 1
  12.   li $a3, 2
  13.  
  14.   jal leaf1
  15.   nop
  16.   j exit
  17.  
  18. leaf1:
  19. # PROLOGUE
  20.   addi $sp,$sp, -12
  21.   sw $t1, 8($sp)
  22.   sw $t0, 4($sp)
  23.   sw $s0, 0($sp)
  24. #######################
  25.   add $t0, $a0, $a1
  26.   add $t1, $a2, $a3
  27.   sub $v0, $t0, $t1     #return result is placed here
  28. #######################
  29. # EPILOGUE
  30.   lw $s0, 0($sp)
  31.   lw $t0, 4($sp)
  32.   lw $t1, 8($sp)
  33.   addi $sp,$sp, 12
  34.  
  35.   jr $ra
  36.  
  37. exit:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement