title: Build MIPS String by Hand
body: <p>For a homework assignment I am suppose to take a integer and change it into its string representative. I have a basic understanding of MIPS, but I don't really understand why my code doesn't work. I'm wondering if anyone out there could give me some pointers how what I need to do or help on how to create a string from hand. I'm using MARS Simulator 4.2.</p>
  
  <p>Here's my code so far with comments.</p>
  
  <pre class="lang-mips prettyprint-override"><code>#itoa
  #$t0 = initial integer
  #$t1 = place where string is stored
  #This program I'm attempting to by hand create a null ended string from an original integer 2.
  
  
  li $t0, 2              #load integer 2
  la $t1, number         #load memory location for string
  
  
  addi $t0, $t0, 48       #add 48 to 2 to get ASCII character, 50
  sb $t0, ($t1)           #store it in original byte of $t1
  
  
  add $t1, $t1, 1     #increment $t1, to point to next byte
  sb $zero, ($t1)     #store #zero in the next byte
  
  move $a0, $t1           #move the hopefully finished string to print out
  li $v0, 1
  syscall               #print out string
  
  
  #exit program
  li $v0, 10
  syscall
  
  .data
   number: .space 1024
  </code></pre>
  
  <p>I'm basically just trying change 2 to it's ASCII value, add a 0 to represent the null string end, and then print that string out.</p>
  
  <p>Thanks For Any Help.</p>