Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. .globl main
  2. main:
  3. ###############################################################
  4. # system call to display the author of this code
  5. la $a0,outpAuth # system call 4 for print string needs address of string in $a0
  6. li $v0,4 # system call 4 for print string needs 4 in $v0
  7. syscall
  8. #
  9. # system call to prompt user for input
  10. la $a0,outpPrompt # system call 4 for print string needs address of string in $a0
  11. li $v0,4 # system call 4 for print string needs 4 in $v0
  12. syscall
  13. ###############################################################
  14. # write a system call to read the user's integer value
  15. li $v0, 5
  16. syscall
  17. move $t0, $v0
  18. # We have not studied looping, so you will need to repeat the prompt for input
  19. # and do the calculation as you see fit
  20. la $a0, outpPrompt #asking user to input a number
  21. li $v0, 4 #storing it in $v0 and using system call 4 since used the address $a0
  22. syscall
  23. li $v0, 5 #reading in an integer
  24. syscall
  25. move $t1, $v0 #moving the contents of the user input into register $t1
  26.  
  27. ###############################################################
  28. la $a0,outpPrompt #asks user for input
  29. li $v0, 4 #stores it in $v0
  30. syscall #syscall 4 called since address #a0 is used
  31. li $v0, 5 #int is read in
  32. syscall
  33. move $t2, $v0 #move stores the user int in register $t2
  34. ################################################################
  35. #
  36. # system call to display "The sum of your numbers multiplied by 3 is: "
  37. la $a0,outpStr # system call 4 for print string needs address of string in $a0
  38. li $v0,4 # system call 4 for print string needs 4 in $v0
  39. syscall
  40. ################################################################
  41. # write a system call to display the calculation
  42. add $t3, $t1, $t2 #add the first two user inputs and store them in register $t3
  43. add $t4, $t3, $t0 #take the sum of the last registers and add it to the last user input
  44.  
  45. li $v0, 1
  46. mul $t5, $t4, 3 #multiply the sum of all user inputs by 3 and store in register $t5
  47. add $a0, $zero, $t5 #store that answer and do a syscall to read the int
  48. syscall
  49.  
  50. #
  51. # Exit gracefully
  52. li $v0, 10 # system call for exit
  53. syscall # close file
  54. ################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement