Advertisement
math230

Function, Sound, and I/O in MIPS

Apr 22nd, 2019
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. reply:  .asciiz "The sum is:"
  3.  
  4. .text
  5.  
  6. # call function sum(a, b)
  7.     addi    $a0, $0, 4
  8.     addi    $a1, $0, 3
  9.     jal sum
  10.     add $s0, $zero,$v0  #save returned value
  11.    
  12. #print The Reply
  13.     la  $a0, reply
  14.     li  $v0, 4
  15.     syscall
  16.    
  17. #print the sum
  18.     li  $v0, 1   #v0= 1 will print $a0
  19.     add $a0, $0, $s0  #$a0 = $s0
  20.     syscall     #print $a0
  21.    
  22. #make a triumphant horn
  23.     li  $a0, 32
  24.     li  $a1, 5000
  25.     li  $a2, 40
  26.     li  $a3, 100
  27.    
  28.     li  $v0, 31
  29.     syscall
  30.    
  31.    
  32.     j   exit
  33.        
  34.  
  35. sum:    addi $sp, $sp, -12
  36.     sw   $ra, 0($sp)
  37.     sw   $t0, 4($sp)
  38.  
  39.     add $v0, $a0,$a1
  40.     jr  $ra
  41.  
  42.  
  43. exit:
  44.     li $v0, 10
  45.     syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement