Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. .data
  2.  
  3. prompt: .asciiz "nEnter a number corresponding to a valid month : "
  4. message: .asciiz "n?n"
  5. message1: .asciiz "nThe month selected is Januaryn"
  6. message2: .asciiz "nThe month selected is Februaryn"
  7. message3: .asciiz "nThe month selected is Marchn"
  8. message4: .asciiz "nThe month selected is Apriln"
  9. message5: .asciiz "nThe month selected is Mayn"
  10. message6: .asciiz "nThe month selected is Junen"
  11. message7: .asciiz "nThe month selected is Julyn"
  12. message8: .asciiz "nThe month selected is Augustn"
  13. message9: .asciiz "nThe month selected is Septembern"
  14. message10: .asciiz "nThe month selected is Octobern"
  15. message11: .asciiz "nThe month selected is Novembern"
  16. message12: .asciiz "nThe month selected is Decembern"
  17.  
  18.  
  19.  
  20.  
  21.  
  22. .text
  23.  
  24. main:
  25. #Prompt the user
  26. li $v0,4 #Load immediate, telling the assembler it's output is going to be string
  27. la $a0,prompt #Loads the address $a0, with the prompt from memory
  28. syscall
  29. #Store the information given to use by the user:
  30. li $v0, 5
  31. syscall #code to tell the system we want the integer value from the user
  32. move $t0,$v0 #keep the value temporarily in $t0
  33.  
  34. add $a0, $zero, $t0 # adds into $a0 the input of the user
  35.  
  36. #check to see what the user's input is by jumping to a simple label
  37. beq $t0,1,Jan
  38. beq $t0,2,Feb
  39. beq $t0,3,Mar
  40. beq $t0,4,Apr
  41. beq $t0,5,May
  42. beq $t0,6,Jun
  43. beq $t0,7,Jul
  44. beq $t0,8,Aug
  45. beq $t0,9,Sep
  46. beq $t0,10,Oct
  47. beq $t0,11,Nov
  48. beq $t0,12,Dec
  49.  
  50. #catch if the value entered is not an integer
  51. beq $t0, -2, invalidMessage
  52. #catch every other integer value
  53. li $v0, 4
  54. la $a0, message
  55. syscall
  56.  
  57.  
  58. li $v0,10
  59. syscall
  60.  
  61.  
  62.  
  63.  
  64. #Labels corresponding to the user's input
  65. Jan:
  66. li $v0,4
  67. la $a0, message1
  68. syscall
  69.  
  70. li $v0,10
  71. syscall
  72. Feb:
  73. li $v0,4
  74. la $a0, message2
  75. syscall
  76.  
  77. li $v0,10
  78. syscall
  79.  
  80. Mar:
  81. li $v0,4
  82. la $a0, message3
  83. syscall
  84.  
  85. li $v0,10
  86. syscall
  87.  
  88. Apr:
  89. li $v0,4
  90. la $a0, message4
  91. syscall
  92.  
  93. li $v0,10
  94. syscall
  95.  
  96. May:
  97. li $v0,4
  98. la $a0, message5
  99. syscall
  100.  
  101. li $v0,10
  102. syscall
  103.  
  104. Jun:
  105. li $v0,4
  106. la $a0, message6
  107. syscall
  108.  
  109. li $v0,10
  110. syscall
  111.  
  112. Jul:
  113. li $v0,4
  114. la $a0, message7
  115. syscall
  116.  
  117. li $v0,10
  118. syscall
  119.  
  120. Aug:
  121. li $v0,4
  122. la $a0, message8
  123. syscall
  124.  
  125. li $v0,10
  126. syscall
  127.  
  128. Sep:
  129. li $v0,4
  130. la $a0, message9
  131. syscall
  132.  
  133. li $v0,10
  134. syscall
  135.  
  136. Oct:
  137. li $v0,4
  138. la $a0, message10
  139. syscall
  140.  
  141. li $v0,10
  142. syscall
  143.  
  144. Nov:
  145. li $v0,4
  146. la $a0, message11
  147. syscall
  148.  
  149. li $v0,10
  150. syscall
  151.  
  152. Dec:
  153. li $v0,4
  154. la $a0, message12
  155. syscall
  156.  
  157. li $v0,10
  158. syscall
  159.  
  160. invalidMessage:
  161. li $v0,4
  162. la $a0, message
  163. syscall
  164.  
  165. li $v0,10
  166. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement