Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #MIPS assmebly code for string manipulation
- #A string is an array of characters keep in mind
- .data
- msg1:
- .asciiz "Enter a string: "
- msg2:
- .asciiz "Thanks"
- msg3:
- .asciiz "\n"
- buffer:
- .space 100
- buffer2:
- .space 100
- .text
- .globl main
- main:
- #Message printed
- la $a0, msg1
- li $v0, 4
- syscall
- #Read input string in
- li $v0,8 #take in input
- la $a0, buffer #load byte space into address
- li $a1, 100 # allot the byte space for string
- move $t0,$a0 #save string to t0
- syscall
- #If current character is a vowel, don't copy it into the ammended string
- la $t0, buffer
- la $t3, buffer2
- test:
- lb $t2, ($t0) #Character in input string
- beqz $t2, finish #Jumps to end when string is empty
- li $t1, 'a'
- beq $t2, $t1, end
- li $t1, 'e'
- beq $t2, $t1, end
- li $t1, 'i'
- beq $t2, $t1, end
- li $t1, 'o'
- beq $t2, $t1, end
- li $t1, 'u'
- beq $t2, $t1, end
- li $t1, 'A'
- beq $t2, $t1, end
- li $t1, 'E'
- beq $t2, $t1, end
- li $t1, 'I'
- beq $t2, $t1, end
- li $t1, 'O'
- beq $t2, $t1, end
- li $t1, 'U'
- beq $t2, $t1, end
- #To reach this point character can't be a vowel
- sb $t2, ($t3)
- add $t3, 1
- add $t0, 1
- j test
- end:
- #Sets new address and jumps back to the start
- add $t0, 1
- j test
- finish:
- #Print the modified string
- la $a0, buffer2 #reload byte space to primary address
- li $v0,4 # print string
- syscall
- jr $ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement