gpt4 book ai didi

mips - 使用 mars 工具访问 mips 中的文件

转载 作者:行者123 更新时间:2023-12-02 03:46:29 24 4
gpt4 key购买 nike

我正在尝试使用 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

最佳答案

I want to read file line by line not all of the file at a time so this code(1) does not work.



将数据块读入缓冲区(例如几千字节)。然后逐行处理该缓冲区(通过查找换行符),并在到达缓冲区末尾时从文件中读取更多数据。

Also I want to write to the file and not overwrite!



打开文件(系统调用 13)时,将标志 ( $a1 ) 设置为 9。这对应于“只写与创建和追加”(见 this MARS syscall reference)。

关于mips - 使用 mars 工具访问 mips 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16648068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com