Search code examples
mipssystem-callsmars-simulator

MIPS won't read my .txt file to the buffer


I've been trying to get this code working for quite some time now. Is there anyone that can explain to me why the buffer stays empty after the syscall. The .txt file, the .asm file and the mars.jar are all in the same directory. I've tried specifying a full path to the file but that didn't work either.

.data
fin:    .asciiz "input.txt"
        .align 2
buffer: .space 2048

.text
# Open file
li      $v0, 13     # System call for opening files
la      $a0, fin    # load file name adress in $a0
li      $a1, 0      # Open for writing
li      $a2, 0      # mode is ignored
syscall             # open a file (file descriptor returned in $v0)
move    $s3, $v0    # save file descriptor to $s3

# Read from file to buffer
li      $v0, 14     # system call for read from file
move    $a0, $s3    # file descriptor
la      $a1, buffer # address of buffer to which to load the contents
li      $a2, 2048   # hardcoded max number of characters
syscall             # read file

# Close file
li      $v0, 16     # system call for close file
move    $a0, $s3    # file descriptor to close
syscall             # close file

Solution

  • I've found the solution. You have to specify the full path from root to file to get it to work. Hope this helps someone else in the future.