Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. .data
  2. str: .asciiz "\n Please enter the number of items you are purchasing (should be less than or equal to 20): "
  3. str1: .asciiz "\n Sorry too many items to purchase! Please enter number of items you are purchasing"
  4. str2: .asciiz "\n Please enter the price of item "
  5. str3: .asciiz "\n Please enter the number of coupons that you want to use. "
  6. str4: .asciiz "\n Please enter the number of coupons that you want to use.It has to equal the same amount of items"
  7. str5: .asciiz "\n Please enter the amount of coupon "
  8. str6: .asciiz "\n This coupon is not acceptable"
  9. str7: .asciiz "\n Your total charge is: $"
  10. str8: .asciiz "\n Thank you for shopping with us."
  11. str9: .asciiz ":\t"
  12. str11: .asciiz"\n Has to be greater than 0"
  13. str10: .asciiz"sum of coupon:"
  14. priArr: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  15. couArr: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  16. .text
  17.  
  18. main: li $t1, 20
  19. li $t2, 1
  20. li $t3, 0
  21. li $t5, 10
  22. la $s0, priArr
  23. la $s1, couArr
  24.  
  25. li $v0, 4
  26. la $a0, str
  27. syscall
  28.  
  29. li $v0, 5
  30. syscall
  31.  
  32. add $s3, $0, $v0 #moving user input to $s3
  33.  
  34. bgt $s3, $t1, error1 # checking if the number of items is less than 20
  35. blt $s3,$t3,error4 # checking if less than 0
  36.  
  37. add $a1, $s3, $0 # moving number of items to $a1
  38.  
  39. jal FillPriceArray #jumps to subroutine to fill array with prices
  40. #--------------------------------------------------------------------------------------
  41.  
  42. add $s2, $0, $v1 #adds price sum to s2
  43.  
  44.  
  45. la $s0, priArr
  46.  
  47. li $v0, 4 #asks for how many coupons
  48. la $a0, str3
  49. syscall
  50.  
  51. li $v0, 5 #loads integer into $v0
  52. syscall
  53.  
  54. bgt $v0, $s3, error2 #if input >= limit, go to error
  55. blt $v0,$s3,error2
  56. add $t4, $v0, 0 #adds input to t4
  57.  
  58. add $a3, $t4, $0 #adds input to a3
  59.  
  60. jal FillCouponArray #jumps to subroutine to fill array with coupon
  61.  
  62. add $s5, $v1, $0 #adds coupon input to s5
  63.  
  64. sub $t7, $s2, $s5 #subtracts price sum and coupons and puts it into t7
  65. li $v0, 4 #prints output
  66. la $a0, str7
  67. syscall
  68.  
  69. li $v0, 1 #prints dollar amount
  70. add $a0, $t7, $0
  71. syscall
  72.  
  73.  
  74. exit: li $v0, 10
  75. syscall
  76. #-----------------------------------------------------------------------------------
  77. FillPriceArray:
  78. li $t0, 10 #adds limit($a1) to $t0
  79. li $t1, 1 #adds counter to $t1
  80. li $t2, 0 #adds loop counter to $t2
  81. add $t3, $a1, $0 #adds input to t3
  82.  
  83. read:
  84. beq $t3, $t2, end
  85.  
  86. li $v0, 4 #asks for price of item
  87. la $a0, str2
  88. syscall
  89.  
  90. li $v0, 1 #prints counter
  91. add $a0, $t1, $0
  92. syscall
  93.  
  94. li $v0, 4 #prints colon and tab
  95. la $a0, str9
  96. syscall
  97.  
  98. li $v0, 5 #loads integer into $v0
  99. syscall
  100.  
  101. blt $v0,$t2,error6
  102.  
  103. sw $v0, 0($s0) #stores the integer into array1
  104.  
  105. add $t1, $t1, 1 #adds 1 to counter
  106. add $t2, $t2, 1 #adds 1 to loop counter
  107. add $s0, $s0, 4 #increments array
  108. add $t4, $t4, $v0 #adds number to sum
  109.  
  110. j read
  111.  
  112. end:
  113.  
  114. add $v1, $t4, $0
  115. jr $ra
  116.  
  117. #-----------------------------------------------------------------------------------
  118. FillCouponArray: li $t0, 10 #adds 10 into t0
  119. li $t1, 1 #adds counter to $t1
  120. li $t2, 0 #adds loop counter to $t2
  121. add $t4, $a3, $0 #adds coupon input to t4
  122.  
  123. read1: beq $t4, $t2, end1 #beg of loop
  124.  
  125. lw $v0, 0($s0) #stores word from price array into $v0 // might have to move outside loop
  126.  
  127. add $t5, $0, $v0 #stores price into $t5
  128.  
  129. li $v0, 4 #outputs please enter amount of coupon
  130. la $a0, str5
  131. syscall
  132.  
  133. li $v0, 1 #prints counter
  134. add $a0, $t1, $0
  135. syscall
  136.  
  137. li $v0, 4 #prints colon and tab
  138. la $a0, str9
  139. syscall
  140.  
  141. li $v0, 5 #loads integer into $v0
  142. syscall
  143.  
  144. blt $v0,$t2,error5
  145.  
  146. add $t3, $v0, $0 #adds input to t3
  147.  
  148. bgt $t3, $t0, error3 #if input is > 10
  149.  
  150. bge $t3, $t5, error3 #if input is >= price number
  151.  
  152. sw $t3, 0($s1) #stores the integer into array1
  153.  
  154. add $t6, $t6, $v0 #adds number to sum
  155.  
  156. increment:
  157. add $t1, $t1, 1
  158. add $t2, $t2, 1
  159. add $s0, $s0, 4 #increments array
  160. add $s1, $s1, 4 #increments array 2
  161.  
  162. j read1
  163.  
  164. end1: add $v1, $t6, $0 #adds coupon sum to v2
  165.  
  166. jr $ra #returns back to addresss
  167.  
  168.  
  169.  
  170. #-----------------------------------------------------------------------------------
  171. error1: li $v0, 4 #outputs too many items to purchase
  172. la $a0, str1
  173. syscall
  174.  
  175. j main
  176. #-----------------------------------------------------------------------------------
  177. error2: li $v0, 4 #outputs too many coupons
  178. la $a0, str4
  179. syscall
  180.  
  181. jr $ra
  182. #-----------------------------------------------------------------------------------
  183. error3: li $v0, 4 #outputs coupon is not acceptable
  184. la $a0, str6
  185. syscall
  186.  
  187. sw $0, 0($s1)
  188.  
  189. j increment
  190. #-----------------------------------------------------------------------------------
  191. error4:
  192.  
  193. li $v0, 4
  194. la $a0, str11
  195. syscall
  196.  
  197. j main
  198. #-----------------------------------------------------------------------------------
  199. error5:
  200. li $v0, 4
  201. la $a0, str11
  202. syscall
  203.  
  204. j read1
  205. #-----------------------------------------------------------------------------------
  206. error6:
  207. li $v0, 4
  208. la $a0, str11
  209. syscall
  210.  
  211. j read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement