title: How to identify end of file correctly
body: <p>I have to create a disassembler, read a <code>file.dump</code> and convert it to assembly.<br>
  I'm testing reading a txt file first. Here is my code:  </p>
  
  <pre><code> .data
  INPUT_FILE:   .asciiz "C:\\Users\\myPath\\teste.txt"
  BUFFER: .space 1024
  ERROR_MSG: .asciiz "ERROR OPENING FILE :( "
  .text
      # Open File
      li $v0, 13                  # Syscall for Open a File
      la $a0, INPUT_FILE          # Specify which file to open
      li $a1, 0                   # 0 = Read
      li $a2, 0
      syscall                    # Open the file (File Descriptor -&gt; V0)
  
      blt $v0, $zero, Error_Opening_File      #Check if File was correctly opened
      move $s6, $v0               # Save the descriptor into s6  
  
  read_file:
      # Read File
      li $v0, 14                 # Syscal for Read from file
      move $a0, $s6               # Pass the file descriptor to argument a0
      la $a1, BUFFER             # Address of Buffer to read
      la $a2, 4                  # Hardcoded Buffer size
      syscall
  
      blt $v0, $zero, Error_Opening_File
  
  
      # Write
      li $v0, 4       # Syscall for Print String
      la $a0, BUFFER
      syscall
  
      j read_file
  
      li $v0, 10
      syscall
  
  Error_Opening_File:
      li $v0, 4
      la $a0, ERROR_MSG
      syscall
  </code></pre>
  
  <p>It's reading "correctly", but it never stops... When it reaches the last part of text, it just keeps repeating that last part.    </p>
  
  <p>Reading the documentation of <code>Syscall 14 (read from file)</code> </p>
  
  <blockquote>
    <p>$v0 contains number of characters read (0 if end-of-file, negative if error). See note below table  </p>
  </blockquote>
  
  <p>How may I make sure when it hits the end ?<br>
  How to make my code read piece by piece 'till there is nothing else to read? </p>
  
  <p>Thinking that in the future I'll need to read an assembly code dumped into text-binary.  </p>