我正在尝试使用MIPS Syscall 13来简单地打开文件,以便可以读取一些字符串并将它们打印到控制台,但是当我打开文件时,文件描述符始终返回-1。 我检查了文件扩展名,一切似乎都井井有条。 在与源代码相同的目录中有一个名为“ cards.dat”的文件。 这是我的代码。 如果有人可以提供帮助,将不胜感激。
.data
filename: .asciiz "cards.dat" #file name
textSpace: .space 1050 #space to store strings to be read
.text
main:
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
move $a0, $v0 # load file descriptor
li $v0, 14 #read from file
la $a1, textSpace # allocate space for the bytes loaded
li $a2, 1050 # number of bytes to be read
syscall
la $a0, textSpace # address of string to be printed
li $v0, 4 # print string
syscall