Silver_Smoulder

[ASM] Project 1 Complete - No EC 'VSlobodovP1.asm'

Oct 31st, 2019
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #Name: VSlobodovP1.asm
  2.  
  3. #1) Prompt user for sentinel value
  4.  
  5. #2) Store sentinel in t0.
  6.  
  7. #3) Begin loop.
  8. #a) prompt user for integer value
  9. #b) store it in t3 #skip this step, as the program instructions ask us not to save the number. we can just keep it in v0 until we're done with it
  10. #c) If t3>0 add 1 to s0, if t2<0 add 1 to s1, if t2 = 0 add 1 to s2.
  11. #d) If t3>0 add it to t1, if t3<0 add it to t2. We can combine this with 3c.
  12. #e) Set t3 = 0.
  13. #f) go back to the start of the loop
  14. #g) exit the loop if sentinel is entered
  15.  
  16. #4) Output
  17. #a) Output sums
  18. #b) Output counters
  19. #c) Comparison and ouput phases
  20. # i) Compare positive and negative, if positive go to ii, else go to iii
  21. # ii) compare positive and zeroes, output
  22. # iii) compare negative and zeroes, output
  23.  
  24. #5) Terminate
  25.  
  26. .text
  27. .globl main
  28.  
  29. main:
  30.  
  31. prompt:
  32. #prompt user for the sentinel value and store
  33. li $v0, 4
  34. la $a0, prompt_sentinel
  35. syscall
  36.  
  37. li $v0, 5
  38. syscall #see 1
  39.  
  40. move $t0, $v0 #see 2
  41.  
  42. #initialize our values
  43. li $s0, 0
  44. li $s1, 0
  45. li $s2, 0
  46. li $t1, 0
  47. li $t2, 0
  48.  
  49. loop:
  50. li $v0, 4
  51. la $a0, prompt_integer
  52. syscall
  53.  
  54. li $v0, 5
  55. syscall #see 3a
  56.  
  57. beq $v0, $t0, output #see 3g
  58. bgtz $v0, adds0
  59. bltz $v0, adds1
  60. beqz $v0, adds2 #see 3c
  61.  
  62. adds0:
  63. add $s0, $s0, 1 #see 3c
  64. add $t1, $t1, $v0 #see 3d
  65. li $t3, 0 #see 3e
  66. j loop #see 3f
  67.  
  68. adds1:
  69. add $s1, $s1, 1 #see 3c
  70. add $t2, $t2, $v0 #see 3d
  71. li $t3, 0 #see 3e
  72. j loop #see 3f
  73.  
  74. adds2:
  75. add $s2, $s2, 1 #see 3c, 3d unnecessary, snce adding 0 is superfluous
  76. li $t3, 0 #see 3e
  77. j loop #see 3f
  78.  
  79. output:
  80. li $v0, 4
  81. la $a0, output_sums_posi
  82. syscall
  83.  
  84. move $a0, $t1
  85. li $v0, 1
  86. syscall #see 4a
  87.  
  88. li $v0, 4
  89. la $a0, output_sums_nega
  90. syscall
  91.  
  92. move $a0, $t2
  93. li $v0, 1
  94. syscall #see 4a
  95.  
  96. li $v0, 4
  97. la $a0, output_counter_posi
  98. syscall
  99.  
  100. move $a0, $s0
  101. li $v0, 1
  102. syscall #see 4b
  103.  
  104. li $v0, 4
  105. la $a0, output_counter_nega
  106. syscall
  107.  
  108. move $a0, $s1
  109. li $v0, 1
  110. syscall #see 4b
  111.  
  112. li $v0, 4
  113. la $a0, output_counter_zero
  114. syscall
  115.  
  116. move $a0, $s2
  117. li $v0, 1
  118. syscall #see 4b
  119.  
  120. #testing phase 4c
  121. bgt $s0, $s1, output_ii
  122. j output_iii #see 4ci
  123.  
  124. output_ii:
  125. bgt $s0, $s2, output_posi
  126. j output_zero#see 4cii
  127.  
  128. output_iii:
  129. bgt $s1, $s2, output_nega
  130. j output_zero #see 4ciii
  131.  
  132. #output phase 4c
  133. output_posi:
  134. li $v0, 4
  135. la $a0, posi_big
  136. syscall
  137. j exit
  138.  
  139. output_nega:
  140. li $v0, 4
  141. la $a0, nega_big
  142. syscall
  143. j exit
  144.  
  145. output_zero:
  146. li $v0, 4
  147. la $a0, zero_big
  148. syscall
  149. j exit
  150.  
  151. exit:
  152. li $v0, 4
  153. la $a0, terminate
  154. syscall
  155.  
  156. li $v0, 10
  157. syscall #see 5
  158.  
  159. .data
  160. prompt_sentinel:
  161. .asciiz "Please input the sentinel for this program: "
  162. prompt_integer:
  163. .asciiz "Please input your integer: "
  164. output_sums_posi:
  165. .asciiz "\nThe sum of the positive numbers is: "
  166. output_sums_nega:
  167. .asciiz "\nThe sum of the negative numbers is: "
  168. output_counter_posi:
  169. .asciiz "\nThe number of positive numbers entered is "
  170. output_counter_nega:
  171. .asciiz ", the number of negative numbers entered is "
  172. output_counter_zero:
  173. .asciiz ", and the number of zeroes entered is "
  174. posi_big:
  175. .asciiz ".\nThe majority of the numbers entered were positive."
  176. nega_big:
  177. .asciiz "\nThe majority of the numbers entered were negative."
  178. zero_big:
  179. .asciiz "\nThe majority of the numbers entered were zeroes."
  180. terminate:
  181. .asciiz "\nThe program is now closing. Have a nice day."
Advertisement
Add Comment
Please, Sign In to add comment