Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #MIPS assmebly code for string manipulation
  2. #A string is an array of characters keep in mind
  3.  
  4. .data
  5. msg1:
  6. .asciiz "Enter a string: "
  7. msg2:
  8. .asciiz "Thanks"
  9. msg3:
  10. .asciiz "\n"
  11. buffer:
  12. .space 100
  13.  
  14. buffer2:
  15. .space 100
  16.  
  17. .text
  18. .globl main
  19. main:
  20. #Message printed
  21. la $a0, msg1
  22. li $v0, 4
  23. syscall
  24.  
  25. #Read input string in
  26. li $v0,8 #take in input
  27. la $a0, buffer #load byte space into address
  28. li $a1, 100 # allot the byte space for string
  29. move $t0,$a0 #save string to t0
  30. syscall
  31.  
  32. #If current character is a vowel, don't copy it into the ammended string
  33. la $t0, buffer
  34. la $t3, buffer2
  35.  
  36. test:
  37. lb $t2, ($t0) #Character in input string
  38. beqz $t2, finish #Jumps to end when string is empty
  39.  
  40. li $t1, 'a'
  41. beq $t2, $t1, end
  42.  
  43. li $t1, 'e'
  44. beq $t2, $t1, end
  45.  
  46. li $t1, 'i'
  47. beq $t2, $t1, end
  48.  
  49. li $t1, 'o'
  50. beq $t2, $t1, end
  51.  
  52. li $t1, 'u'
  53. beq $t2, $t1, end
  54.  
  55. li $t1, 'A'
  56. beq $t2, $t1, end
  57.  
  58. li $t1, 'E'
  59. beq $t2, $t1, end
  60.  
  61. li $t1, 'I'
  62. beq $t2, $t1, end
  63.  
  64. li $t1, 'O'
  65. beq $t2, $t1, end
  66.  
  67. li $t1, 'U'
  68. beq $t2, $t1, end
  69.  
  70. #To reach this point character can't be a vowel
  71. sb $t2, ($t3)
  72. add $t3, 1
  73. add $t0, 1
  74. j test
  75.  
  76.  
  77. end:
  78. #Sets new address and jumps back to the start
  79. add $t0, 1
  80. j test
  81.  
  82. finish:
  83.  
  84. #Print the modified string
  85. la $a0, buffer2 #reload byte space to primary address
  86. li $v0,4 # print string
  87. syscall
  88.  
  89. jr $ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement