title: MIPS assembly - removing vowels from an input string
body: <p>The following is my code for a MIPS assembly program that is intended to remove vowels from an input string and then print the new string.  As it stands, the program simply does not remove the vowels and just reprints the same string that was input.</p>
  
  <pre><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      $t0, 0          # add a null to the bottom of the stack
      subu    $sp, $sp, 4
      sw      $t0, ($sp)
      li      $t1, 0          # initiate index
  
  pushloop:
      lbu     $t0, str($t1)   # (I think the program is placing a zero in $t0 here, thus causing it to branch immediately to poploop, which then branches to the end since only the null has been pushed onto the stack)
      beqz    $t0, poploop    # once we reach null char, finish
      subu    $sp, $sp, 4
      sw      $t0, ($sp)
      addiu   $t1, $t1, 1
      j       pushloop
      nop
      # $t1 is not reset
  
  poploop:
      lw      $t0, ($sp)
      addu    $sp, $sp, 4
      beqz    $t0, done       # once we reach null char, finish
      nop
      # check if vowel
      li      $t2, 0x61       # a
      beq     $t0, $t2, vowel
      nop
      li      $t2, 0x65       # e
      beq     $t0, $t2, vowel
      nop
      li      $t2, 0x69       # i
      beq     $t0, $t2, vowel
      nop
      li      $t2, 0x6F       # o
      beq     $t0, $t2, vowel
      nop
      li      $t2, 0x75       # u
      beq     $t0, $t2, vowel
      nop
      # if not a vowel, store it at current index in string
      sb      $t0, str($t1)
      j       decrement
      nop
  vowel:  # if vowel, remove character
      li      $t0, 0
      sb      $t0, str($t1)
  decrement:
      addiu   $t1, $t1, -1        # decrement index
      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"
  </code></pre>