我正在尝试使用 mips 指令对文件进行一些访问。
我想逐行读取文件,而不是一次读取所有文件,因此此代码(1)不起作用。
我也想写入文件而不是覆盖!
谁能帮我?
代码:
打开要写入的文件
li $v0, 13 # system call for open file
la $a0, file # 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
从文件中读取
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, 40 # hardcoded buffer length
syscall # read from file
关闭文件
li $v0, 16 # system call for close file
move $a0, $s6 # file descriptor to close
syscall # close file