title: Pig Latin in MIPS Assembly
body: <p>In my MIPs Assembly Programming class I've been tasked with writing a program that converts a string into simplified pig latin.</p>
  
  <p>Simplified pig latin assumes all words in the string are at least 2 characters long, and every word has its first letter shifted to the end followed by "ay". Also, assume there are no punctuation marks of any kind.</p>
  
  <p>So, "stackoverflow is great" becomes "tackoverfloway siay reatgay".</p>
  
  <p>I've taken a stab at this program and I'm nearly completed.  It works fine, except that for some reason I have a line break in the middle of the last word every time.</p>
  
  <p>For example:</p>
  
  <blockquote>
    <p>tackoverflowsay siay reat<br>
    gay</p>
  </blockquote>
  
  <p>Instead of:</p>
  
  <blockquote>
    <p>tackoverflowsay siay reatgay </p>
  </blockquote>
  
  <p>I've tried decuding what would be causing this line break in the last exit portion of my program but I don't see it.  Do I have a pre-mature null terminated string?  If I do, I don't see it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>####################################################
  #  Text Segment
  ####################################################
          .text
          .globl main
  main:
          la $t0, char
          la $t1, buffer
          lb $t3, space
  
          la $a0, prompt
          li $v0, 4
          syscall
  
          la $a0, buffer
          li $a1, 200
          li $v0, 8
          syscall
  
          lb $t2, ($t1)           # Load first char
          addi $t1, $t1, 1
  
  loop:
          lb $t4, ($t1)           # Load next character into $t4
  
          addi $t1, $t1, 1
          beqz $t4, exit          # Reached end of string, exit?  
          beq $t3, $t4, loop2     # If $t4 = " " char, second loop
  
          move $a0, $t4           # else, lets keep printing chars
          li $v0, 11
          syscall
  
          j loop
  
  loop2:
          move $a0, $t2
          li $v0, 11
          syscall
  
          la $a0, aystr
          li $v0, 4
          syscall
  
          lb $t2, ($t1)   
          addi $t1, $t1, 1    
  
          j loop
  exit:
  
          move $a0, $t2
          li $v0, 11
          syscall
  
          la $a0, aystr
          li $v0, 4
          syscall
  
          li $v0, 10
          syscall         # Cya...
  
  ####################################################
  #  Data Segment
  ####################################################
  
          .data
  prompt: .asciiz "Enter Phrase: "
  result: .asciiz "Pig Latin: "
  space:  .ascii " "
  aystr:  .asciiz "ay "
  char:   .byte 1
  buffer: .byte 200
  </code></pre>