我正在嘗試編寫一個程序,該程序從.dat文件中讀取與LED模擬器中顯示的不同顏色對應的字符; x = off,R = red等。我的問題是,我無法弄清楚我在打開.dat文件時做了什麼錯誤。我環顧四周,嘗試了所有我能想到的,但每次組裝並運行時,我都會在$ v0中得到-1表示錯誤。這裏是我的開/讀碼/關閉文件:用MIPS彙編閱讀文件
.data
fin: .asciiz "maze1.dat" # filename for input
buffer: .asciiz ""
.text
#open a file for writing
li $v0, 13 # system call for open file
la $a0, fin # board file name
li $a1, 0 # Open for reading
li $a2, 0
syscall # open a file (file descriptor returned in $v0)
move $s6, $v0 # save the file descriptor
#read from file
li $v0, 14 # system call for read from file
move $a0, $s6 # file descriptor
la $a1, buffer # address of buffer to which to read
li $a2, 1024 # hardcoded buffer length
syscall # read from file
# Close the file
li $v0, 16 # system call for close file
move $a0, $s6 # file descriptor to close
syscall # close file
文件maze1.dat是在同一目錄MIPS計劃。任何幫助或建議非常感謝。