title: Reading from file in a loop
body: <p>I am trying to read from a file with a buffer of 255 bytes.</p>
  
  <pre><code>li $v0, 13                  # open a file
  li $a1, 0                   # file flag (read)
  la $a0, filename            # load file name
  add $a2, $zero, $zero       # file mode (unused)
  syscall
  
  loop:               # loop through the bytes until the # of bytes read is zero or an error
  move $a0, $v0               # load file descriptor
  li $v0, 14                  # read from file
  la $a1, textBuffer          # allocate space for the bytes loaded
  li $a2, 255                 # number of bytes to be read
  syscall
  
  blez $v0, loop_done     # is # of bytes read zero or an error?
  
  la $a0, textBuffer          # address of string to be printed
  li $v0, 4                   # print string
  syscall
  
  j loop
  
  loop_done:
  
  li $v0, 16
  syscall             # close file
  </code></pre>
  
  <p>However it is just printing the first 255 bytes, not the entire content of the file. I am not sure how to move the position over when reading a file, if it isn't automatically done. </p>
  
  <p>textBuffer and filename are </p>
  
  <pre><code>filename: .asciiz "data.txt"
  textBuffer: .word 255
  </code></pre>
  
  <p>in the data section</p>