问题描述
我目前正在尝试学习如何写入文件,但是我似乎无法多次写入文件。我将如何将多个字符串写入一个文件,或者在这种情况下,将同一个字符串多次写入?谢谢。
.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,this is really a constant
syscall
file_close:
li $v0,16 # $a0 already has the file descriptor
syscall
解决方法
我已经尝试了半个多小时来解决这个问题,但在我发布问题的那一刻,我就自己解决了。我将 $a0 设置为 $v0,因为我在第一次系统调用后使用了 $v0,其中的值不正确,这意味着 $a0 中的值不正确:\