So i have my mips code that i want to do the follow thing:

When i get a vowal (aeiou) it prints the next consonant from vowal (bfjpv).

My code works 80% but when i do that it deletes the next char where i replace.
Like:

Bruno it must print Bruvnop but it only prints Bruvop (it deletes the next char from where i replace). My guess is i need to do +1 in the array, but i might be wrong (i already try it but it doesnt work)..

Here is my code:

 .text
    .globl  main

main:
    # display prompt
    li      $v0, 4
    la      $a0, prompt
    syscall
    # accept input string
    li      $v0, 8
    la      $a0, str
    li      $a1, 82
    syscall

    li      $t1, 0          # initiate index
    li      $t3, 0          # vowel count

poploop:
    lb $t0 str($t1)

    # check if vowel
    li      $t2, 'a'       # a
    beq     $t0, $t2, TESTEa
    JA:
    li      $t2, 'e'       # e
    beq     $t0, $t2, TESTEe
    JE:
    li      $t2, 'i'       # i
    beq     $t0, $t2, TESTEi
    JI:
    li      $t2, 'o'       # o
    beq     $t0, $t2, TESTEo
    JO:
    li      $t2, 'u'       # u
    beq     $t0, $t2, TESTEu
    JU:

    # if not a vowel, store it at current index in string less vowel count

    sb $t0, str($t1)
    j next
    nop

TESTEa: # if vowel, inc count
    sb $t2, str($t1)
    addi $t1, $t1, 1
        li $t0, 'b'
    sb $t0, str($t1)
    j JA
TESTEe:
    sb $t2, str($t1)
    addi $t1, $t1, 1
    lb $t2 str($t1)
    move $t2, $a1
        li $t0, 'f'
    sb $t0, str($t1)
    addi $t1, $t1, 1
    sb $t2, str($t1)
    j JE
TESTEi:
    sb $t2, str($t1)
    addi $t1, $t1, 1
    lb $t2 str($t1)
    move $t2, $a1
        li $t0, 'j'
    sb $t0, str($t1)
    addi $t1, $t1, 1
    sb $t2, str($t1)
    j JI
TESTEo:
    sb $t2, str($t1)
    addi $t1, $t1, 1
        li $t0, 'p'
    sb $t0, str($t1)
    j JO
TESTEu:
    sb $t2, str($t1)
    addi $t1, $t1, 1
    lb $t2 str($t1)
    move $t2, $a1
        li $t0, 'v'
    sb $t0, str($t1)
    addi $t1, $t1, 1
    sb $t2, str($t1)
    j JU
next:
    addi $t1, $t1, 1

    beqz $t0, done       # once we reach null char, finish
    nop
    j poploop
    nop

done:   
    li $v0, 4
    la $a0, str
    syscall
    li $v0, 10         # exit program
    syscall
    nop

    .data
str: .space 82
prompt: .asciiz "Input a string:\n"

The lack of comments means I have to decode each line to figure out what it does. Example? Lines 95 to 97 (and others.) Not everyone codes for this so your comments matter more than ever. And in a decade, how will you know what this did?

When posting for help on assembly, I think each line or close to each line needs a comment about what it is doing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.