title: How to remove newline in MIPS?
body: <p>So I am busy writing a MIPS program that will take an input string, and then print all possible UNIQUE permutations of that string.  (AKA if the word is LoOp, LoOp and LOop are the same).</p>
  
  <p>In order to do this, I know I need to NOT have a newline character on the end of my input string, but I don't know to make sure it's not added.  Here is what I have so far:</p>
  
  <pre><code>.data
  
  
  newLine:
      .asciiz "\n"
  promptUser:
      .asciiz "Enter a 20 letter or less word:\n"
  word:
      .space 21
  
  .text
  
  main:
  
      la $a0, promptUser
      li $v0, 4       # Ask User for Input
      syscall
  
      la $a0, word
      li $a1,21       # Max number of characters 20
      li $v0,8
      syscall         # Prompting User
  
      la $a0,newLine      # Newline   
      li $v0, 4
      syscall
  
      la $a0, word        # Printing Word
      li $v0, 4
      syscall
  </code></pre>
  
  <p>The only time a '\n' isn't included is when the number of letters entered is exactly 20.  Any suggestions??</p>
  
  <p>FIX:</p>
  
  <p>This works:</p>
  
  <pre><code>    li $s0,0        # Set index to 0
  remove:
      lb $a3,word($s0)    # Load character at index
      addi $s0,$s0,1      # Increment index
      bnez $a3,remove     # Loop until the end of string is reached
      beq $a1,$s0,skip    # Do not remove \n when string = maxlength
      subiu $s0,$s0,2     # If above not true, Backtrack index to '\n'
      sb $0, word($s0)    # Add the terminating character in its place
  skip:
  </code></pre>