Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. .data
  2. display: .asciiz "Please, input the Alphanumeric string:\n"
  3. sparse: .asciiz "Sparse"
  4. intermediate: .asciiz "Intermediate"
  5. plentiful: .asciiz "Plentiful"
  6. space: .asciiz "\n"
  7. str: .space 200 # initialize array with 200 characters space available
  8. temp: .space 7
  9. period: .asciiz "."
  10. .text
  11. .globl main
  12. main:
  13. li $t2, 0 # word_end = 0
  14. li $t3, 0 # word_hex = 0
  15. li $t6, 0 # last_word = 0
  16. li $t1, 0 # word_str = 0
  17. li $t4, 200 # constant used for max
  18. li $t0, 0
  19. li $s4, 0x20 # period
  20. li $s5, 0x2E # space
  21. la $s3, temp
  22. la $a0, display # load address of string to print
  23. li $v0, 4 # instruction to output
  24. syscall # make the syscall
  25.  
  26. la $a0, str
  27. li $a1, 200
  28. syscall
  29.  
  30. for: bgt $t0, 200, flag # for loop, will branch if 200 characters are reached print period
  31. li $v0, 8 # read character, getchar=c
  32. syscall # make the syscall
  33. bne $v0, $s4, str1 # branch if not equal to period
  34. li $t6, 1 # if equal to space, flag for end
  35. move $v0, $s5 # make equal to space so it can still calculate lasr word
  36. j else_if # jump to else if to make last calculation
  37.  
  38. str1: la $a0, str # set register $a0 to str, 200 spaces available for input
  39. li $a1, 200 # Load into register $a1 200, max permitted
  40. sb $v0, ($s3) # store the charater
  41. add $s3, $s3, $t0 # array offset
  42. addi $t2, $t2, 1 # increment word_end by 1
  43. bgt $v0, 70, else_if # branch if greater than 'F'
  44. blt $v0, 48, else_if # branch if less than '0'
  45. bgt $v0, 65, word_hex # branch if greater than 'A'
  46. blt $v0, 57, word_hex # branch if less than '9'
  47. word_hex:
  48. addi $t4, $t4, 1 # add to counter of HEX characters
  49.  
  50. else_if: bne $v0, $s5, else2 # branch if character is not equal to space
  51. subi $t1, $t1, 1 # word_str-1
  52. sub $t5, $t2, $t1 # word_end - word_str-1
  53. bne $t1, $t3 else1 # branch if not equal to word_hex
  54. subi $t5, $t0, 1 # k-1
  55. sll $t5, $t0, 2 # shift of k-1
  56. add $t5 $t5, $s3 # add t5 to base address str
  57. lw $t7, 0($t5) # t7 contains str[k-1]
  58. beq $t7, $s5, else1 # branch if equal to space
  59. strlen1: # now check third condition, strlen1
  60. lbu $t0, 0($s2) # load the next character into t0
  61. beqz $t0, out # check for the null character
  62. addi $s2, $s2, 1 # increment the string pointer
  63. addi $s6, $s6, 1 # increment the count
  64. j strlen # return to the top of the loop
  65. #out:
  66. #bne
  67. #beq temp, 1, else1 # branch if strlen = 1
  68. li $t5, 0 # counter = 0
  69. li $t7, 0 # sum = 0
  70.  
  71. for1: # running through the valid hex values to check if # or letter
  72. subi $t2, $t2, 2 # word end - 2
  73. move $t3, $t2 # word end = i
  74. blt $t3, $t1, tempc # branch if i is less than word str
  75. sll $s6, $t3, 2 # convert the word to byte
  76. add $s6, $s6, $s2 # add to base address of str
  77. lw $s7, 0($s6) # s7 contains str[i]
  78. bgt $s7, 57, letter # branch if greater than '9'
  79. subi $s7, $s7, 48 # if not, subtract 55 because it's a #
  80. j sum # no need to check if letter, go to temp array
  81. letter:
  82. subi $s7, $s7, 55
  83. sum:
  84. sll $t5, $t5, 4 # multiply counter by 4
  85. sllv $t5, $s0, $t5 # num*2^(4*counter)
  86. add $t7, $t5, $t7 # add result + sum, store it in sum
  87. addi $t5, $t5, 1 # counter +1, 16 will be raised to this value
  88. addi $t3, $t3, 1 # decrease i by 1
  89. blt $t7, $t4, for1 # branch back if sum<max
  90. move $t4, $t7 # if not change new max to sum
  91. j for1 # go back to check next valid hex
  92. tempc:
  93. #sprintf
  94. la $a0, temp # load addres of str
  95. li $v0, 4 # print call
  96. syscall # make the syscall
  97. move $a0, $t7 # load sum to print
  98. li $v0, 1 # print call
  99. syscall # make the syscall
  100. li $s5, 0 # j = 0
  101. move $t3, $t1 # i = word str
  102. strlen:
  103. lbu $t1, 0($a0) # load the next character into t1
  104. beqz $t1, plus # check for the null character
  105. addi $a0, $a0, 1 # increment the string pointer
  106. addi $t0, $t0, 1 # increment the count
  107. j strlen # return to the top of the loop
  108. # word str + strlen of temp arr CHECKKKK
  109. plus:
  110. for2: bgt $t3, $t5, out # branch out if i > wordstr + strlen(temparr)
  111. addi $s5, $s5, 1 # j++
  112. sll $t3, $s5, 2 # change word to byte temp array
  113. add $t3, $t3, $s1 # add to base address
  114. lw $t0, 0($t3) # load
  115. sll $t2, $t3, 2 # change word to byte str[i]
  116. add $t2, $t2, $s2 # add to base add str
  117. lw $t5, 0($t2) # load
  118. move $t0, $t5 # move temp array[j++] into str[i]
  119. j for2 # go back to for loop till conditions not met
  120. out:
  121. #K=WORD_STR+STRLEN(TEMP_ARRAY);
  122. sll $s5, $t0, 2
  123. add $s5, $s5, $s2
  124. lw $s0, 0($s5)
  125. move $s0, $s4 # STR[K]=' '
  126. li $t3, 0 # word hex = 0
  127. move $t2, $t0 # word end = k
  128. addi $t1, $t2, 1 # word str = word end ++
  129. else1:
  130. li $t3, 0
  131. move $t1, $t2
  132. else2:
  133. li $t3, 0
  134. flag:
  135. #bne $t6, 1, for
  136. sll $t3, $s5, 2
  137. add $t3, $t3, $s1
  138. lw $t0, 0($t3)
  139. li $t0, 46
  140. move $a0, $t0 # print period
  141. li $v0, 1 # print call
  142. syscall # make the syscall
  143. print: la $a0, str # load addres of str, will print non hex non period character
  144. li $v0, 4 # print call
  145. syscall # make the syscall
  146.  
  147. #find if sparse, intermediate or pletiful
  148. exit:
  149. li $v0, 10 # instruction for exit program
  150. syscall # make the syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement