String Can';在MIPS中不能多次写入文件?
我目前正在尝试学习如何写入文件,但是我似乎不能多次写入文件。如何将多个字符串写入一个文件,或者在本例中多次写入同一字符串?谢谢String Can';在MIPS中不能多次写入文件?,string,file,input,mips,writing,String,File,Input,Mips,Writing,我目前正在尝试学习如何写入文件,但是我似乎不能多次写入文件。如何将多个字符串写入一个文件,或者在本例中多次写入同一字符串?谢谢 .data str_exit: .asciiz "test.txt" str_data: .asciiz "This is a test!" str_data_end: .text file_open: li $v0, 13 la $a0, str_exit li $a1, 1 li $a2,
.data
str_exit: .asciiz "test.txt"
str_data: .asciiz "This is a test!"
str_data_end:
.text
file_open:
li $v0, 13
la $a0, str_exit
li $a1, 1
li $a2, 0
syscall # File descriptor gets returned in $v0
file_write:
move $a0, $v0 # Syscall 15 requieres file descriptor in $a0
li $v0, 15
la $a1, str_data
la $a2, str_data_end
la $a3, str_data
subu $a2, $a2, $a3 # computes the length of the string, this is really a constant
syscall
move $a0, $v0 # Syscall 15 requieres file descriptor in $a0
li $v0, 15
la $a1, str_data
la $a2, str_data_end
la $a3, str_data
subu $a2, $a2, $a3 # computes the length of the string, this is really a constant
syscall
file_close:
li $v0, 16 # $a0 already has the file descriptor
syscall
我已经花了半个多小时试图解决这个问题,但在我发布问题的那一刻,我就自己解决了。我将$a0设置为$v0,因为我在第一次系统调用后使用了$v0,这意味着$a0中的值不正确:\