MIPS 不会将我的 .txt 文件读取到缓冲区

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

我已经尝试让这段代码工作很长一段时间了。有没有人可以向我解释为什么缓冲区在系统调用后保持为空。 .txt 文件、.asm 文件和 mars.jar 都在同一个目录中。我试过指定文件的完整路径,但这也不起作用。

.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

我找到了解决办法。您必须指定从根目录到文件的完整路径才能使其正常工作。希望这对以后的其他人有所帮助。