title: How to write int to file in MIPS?
body: <p>I'm doing a homework where I have to read a non-fixed numbers of integers separated by \n from a text file and sort them in a linked list (and in an array, to compare performance). After that, I have to write the sorted list into another text file, and that's where my problem is. I don't really know how syscall 15 works (write to file). I don't know what kind of input it would print to the file. I mean, I'm guessing they have to be strings, not integers... so I made a little test program and it didn't work. Here it is:</p>
  
  <pre><code>.data   
      archivo: .asciiz "salida.txt"
  .text
  # reservar memoria para 3 chars + \0
  li $v0, 9
  li $a0, 4
  syscall
  move $s0, $v0
  # agregar al array el numero 1 ascii
  addi $t0, $zero, 49
  sw $t0, 0($s0)
  addi $s0, $s0, 4
  # agregar al array el numero 0 ascii
  addi $t0, $zero, 48
  sw $t0, 0($s0)
  addi $s0, $s0, 4
  # agregar al array el numero 0 ascii
  addi $t0, $zero, 48
  sw $t0, 0($s0)
  addi $s0, $s0, 4
  # agregar al array \0 al final
  addi $t0, $zero, 0
  sw $t0, 0($s0)
  
  addi $s0, $s0, -12
  
  # abrir archivo en modo lectura
  li $v0, 13
  la $a0, archivo
  li $a1, 1
  li $a2, 0
  move $s1, $v0
  syscall
  # escribir buffer $s0 en el archivo
  li $v0, 15
  move $a0, $s1
  move $a1, $s0
  addi $a2, $zero, 4
  syscall
  # cerrar archivo
  li $v0, 16
  move $a0, $s1
  syscall
  # finalizar ejecucion
  li $v0, 17
  syscall
  </code></pre>
  
  <p>I tried to allocate enough memory for 3 chars + \0 char, in order to write the number 100 to the file "salida.txt". So, I stored the ascii values of 1, 0, 0 into an array (which is the allocated memory), and then decrement the pointer, to point to the beginning of that memory block. After that, I open the file in write-mode and write 4 characters of the buffer $s0.
  Unfortunately, this only creates the file but writes nothing in it. Any help would be appreciated. Thanks.</p>
  
  <hr>
  
  <p>I also tried writing a variable declared in .data, like this:</p>
  
  <pre><code>.data   
  hola: .asciiz "hola"
  .text
  la $s3, hola
  ...
  # do syscall 15 with move $a1, $s3
  </code></pre>
  
  <p>but this didn't work either.</p>