You can't know the last line was repeated with this code. The link you gave clearly says in the Result column for file read that $v0
contains the number of bytes read. But your code immediately clobbers $v0
to close the file.
If you change your code to print only the characters actually read, the appearance of repeated information ought to go away.
If you are using the print string syscall
, then just add one byte to the buffer (to prevent overrun) and then write a null terminator after the characters read. Something like:
syscall # (your code) read from file
la $a0, fBuffer # load 32-bit buffer address
add $a0, $a0, $v0 # calculate address of byte after file data
sb $zero, 0($a0) # set that byte to zero