我尝试使用以下代码来打开要写入的新文件,然后从内存缓冲区向其中写入文本,然后将其关闭。我相信txt文件应在自动保存MARS脚本的目录中创建,但是没有文件。 $ v0不是负数,因此我认为没有发生错误。有谁知道可能是什么问题?
.data
fout: .asciiz "testout.txt" # filename for output
buffer: .asciiz "The quick brown fox jumps over the lazy dog."
.text
###############################################################
# Open (for writing) a file that does not exist
li $v0, 13 # system call for open file
la $a0, fout # output file name
li $a1, 1 # Open for writing (flags are 0: read, 1: write)
li $a2, 0 # mode is ignored
syscall # open a file (file descriptor returned in $v0)
move $s6, $v0 # save the file descriptor
###############################################################
# Write to file just opened
li $v0, 15 # system call for write to file
move $a0, $s6 # file descriptor
la $a1, buffer # address of buffer from which to write
li $a2, 44 # hardcoded buffer length
syscall # write to file
###############################################################
# Close the file
li $v0, 16 # system call for close file
move $a0, $s6 # file descriptor to close
syscall # close file
###############################################################
答案 0 :(得分:0)
问题的原因在路径:fout: .asciiz "testout.txt"
中。它必须是带有双\\
而不是\
的完整路径:
fout:.asciiz "C:\\Users\\Angry\\Desktop\\testout.txt"