微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

不能在 MIPS 中多次写入文件?

如何解决不能在 MIPS 中多次写入文件?

我目前正在尝试学习如何写入文件,但是我似乎无法多次写入文件。我将如何将多个字符串写入一个文件,或者在这种情况下,将同一个字符串多次写入?谢谢。

.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 中的值不正确:\

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。