Advertisement
DoomProg

Assembly min of three numbers

Mar 19th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. .text
  2.  
  3. # t0 <- min
  4. # a0 <- number1
  5. # a1 <- number2
  6. # a2 <- number3
  7.  
  8. li $a0 , 100 # a number
  9. li $a1 , 56 # another number
  10. li $a2 , 99 # some other number...
  11. jal findMin # call findMin on them
  12. move $a0 , $v0 # save the return address to $a0
  13. li $v0 , 1 # save the print_int code to $v0
  14. syscall # print the min found
  15. j EXIT # call the exit tag
  16.  
  17.  
  18.  
  19. findMin:
  20. move $t0 , $a0
  21. bge $a1 , $t0 ,ELSE # if ( number2 > = min ) check the other
  22. move $t0 , $a1 # else this one is the min so far
  23. ELSE:
  24. bge $a1 , $t0 , END # if (number3 >= min ) the first one is the min
  25. move $t0 , $a2 # else this one is the min
  26. END:
  27. move $v0 , $t0 # make the return value be the min
  28. jr $ra # return
  29. EXIT:
  30. li $v0 , 10 # save the exit code to v0
  31. syscall # exit the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement