0

So i want to swap the vowals with vowals+consonants everytime i found them.

a = ab
e = ec
i = id
o = of
u = ug

For example:
The message is: "Hello", the return message must be: "Hecllof".

This is the code that i have until now:

.data
string: .asciiz "halla"
a: .ascii "a"
a1: .asciiz "b"
tam: .word 5

.text 

main:
    lw $t6, tam #string length
    lb $t1, string($t0) #read bit by bit

    lb $s0, a #save in register the char that we want to search
    lb $s1, a1 #save in register the char that we want to replace

    beq $t0, $t6, done

    beq $t1, $s0, continua #if the char of (bit by bit) its like the char of chars, swap it
    bne $t1, $s0, store #if not, saves

continua:
    sb $s1, string($t0) #do the swap 
    addi $t0, $t0, 1 #+1 in the index
    j main 

store:
    sb $t1, string($t0) #saves
    addi $t0, $t0, 1 #+1 in the index
    j main
done:
    la $a0, string
    li $v0, 4
    syscall
    li $v0, 10
    syscall

My code only replaces one byte (if i want to replace a with ab it doesnt replace, only replaces it with "b")
How can i improve my code?

Thank you.

2
Contributors
1
Reply
9
Views
4 Weeks
Discussion Span
Last Post by rproffitt
0

While I've written in some dozen or more assembly languages what I want to point out is what looks to be a fatal flaw in your design. Ready?

The string is fixed in size at 5 characters or bytes so you may not swap in 2 characters without overflowing that string's memory allotment.

Why not loop through your input string and on your system output the characters you want if they match and if not, just output the unaltered character?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.