Silver_Smoulder

[ASM] Basic Arithmetic

Oct 16th, 2019
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. .globl main
  2. .text
  3.  
  4. main:
  5. li $v0, 4 #output the string
  6. la $a0, first_int
  7. syscall
  8.  
  9. li $v0, 5 #read in the number
  10. syscall
  11.  
  12. move $t0, $v0 #store first integer in t0
  13.  
  14. li $v0, 4 #output the string
  15. la $a0, second_int
  16. syscall
  17.  
  18. li $v0, 5 #read in the number
  19. syscall
  20.  
  21. move $t1, $v0 #store first integer in t1
  22.  
  23. add $t2, $t0, $t1 #add t0 and t1 and store it in t2
  24.  
  25. li $v0, 4 #output the string
  26. la $a0, result
  27. syscall
  28.  
  29. move $a0, $t2 #put the integer into a0
  30. li $v0, 1 #output the integer
  31. syscall
  32.  
  33. li $v0, 10 #end the program
  34. syscall
  35.  
  36. .data
  37. first_int:
  38. .asciiz "Please enter your first integer: "
  39. second_int:
  40. .asciiz "Please enter your second integer: "
  41. result:
  42. .asciiz "The sum of your integers is: "
  43.  
  44.  
  45. --------------------------------------------------------------------------------------------------------------
  46.  
  47. .globl main
  48. .text
  49.  
  50. main:
  51. li $v0, 4 #output the string
  52. la $a0, first_int #m
  53. syscall
  54.  
  55. li $v0, 5 #read in the number
  56. syscall
  57.  
  58. move $t0, $v0 #store first integer in t0, M
  59.  
  60. li $v0, 4 #output the string
  61. la $a0, second_int #n
  62. syscall
  63.  
  64. li $v0, 5 #read in the number
  65. syscall
  66.  
  67. move $t1, $v0 #store second integer in t1, N
  68.  
  69. add $s0, $t0, $t0 #add n+m
  70. sub $s1, $t0, $t1 #subtract m-n
  71. add $s2, $t0, 3 #subtract m+3
  72. sub $s3, $t1, 4 #add n-4
  73.  
  74. mul $s4, $t0, $t1 #multiply mn
  75.  
  76. div $s5, $t1, $t0 #divide n by m and get quotient
  77. rem $s6, $t1, $t0 #divide n by m and get the remainder
  78.  
  79.  
  80. #print out the line, then store the integer from the 's' registers to a0,
  81. #then print integer, then repeat
  82. li $v0, 4 #iteration 1
  83. la $a0, newline
  84. syscall
  85. move $a0, $s0
  86. li $v0, 1
  87. syscall
  88.  
  89. li $v0, 4 #iteration 2
  90. la $a0, newline
  91. syscall
  92. move $a0, $s1
  93. li $v0, 1
  94. syscall
  95.  
  96. li $v0, 4 #iteration 3
  97. la $a0, newline
  98. syscall
  99. move $a0, $s2
  100. li $v0, 1
  101. syscall
  102.  
  103. li $v0, 4 #iteration 4
  104. la $a0, newline
  105. syscall
  106. move $a0, $s3
  107. li $v0, 1
  108. syscall
  109.  
  110. li $v0, 4 #iteration 4
  111. la $a0, newline
  112. syscall
  113. move $a0, $s4
  114. li $v0, 1
  115. syscall
  116.  
  117. li $v0, 4 #iteration 4
  118. la $a0, newline
  119. syscall
  120. move $a0, $s5
  121. li $v0, 1
  122. syscall
  123.  
  124. li $v0, 4 #iteration 4
  125. la $a0, newline
  126. syscall
  127. move $a0, $s6
  128. li $v0, 1
  129. syscall
  130.  
  131. li $v0, 10 #end the program
  132. syscall
  133.  
  134.  
  135. .data
  136. first_int:
  137. .asciiz "Please enter your first integer: "
  138. second_int:
  139. .asciiz "Please enter your second integer: "
  140. result:
  141. .asciiz "The sum of your integers is: "
  142. newline:
  143. .asciiz "\n"
Advertisement
Add Comment
Please, Sign In to add comment