我试图创建一个名为“exit.txt”的文件,并在其上写入一些数据。我尝试了不同的标志和模式,但这似乎不起作用。这是我正在使用的代码:在MIPS上创建并写入文件
str_exit: .asciiz "/home/LinuxPc/Desktop/exit.txt"
file_write:
li $v0, 13
la $a0, str_exit
li $a1, 1
la $a2, 0
syscall
有什么办法可以使它工作? 谢谢!
我试图创建一个名为“exit.txt”的文件,并在其上写入一些数据。我尝试了不同的标志和模式,但这似乎不起作用。这是我正在使用的代码:在MIPS上创建并写入文件
str_exit: .asciiz "/home/LinuxPc/Desktop/exit.txt"
file_write:
li $v0, 13
la $a0, str_exit
li $a1, 1
la $a2, 0
syscall
有什么办法可以使它工作? 谢谢!
您将代码打开为写入模式下的文件,但您没有写入任何文件。 在这里做了如何打开/写一个例子/关闭文件:
.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
file_close:
li $v0, 16 # $a0 already has the file descriptor
syscall
除了gusbro的答案(写作之前打开文件流),它可以帮助设置标志和模式打开的文件请拨打电话:
li $a1, 0x41
li $a2, 0x1FF
这将标志设置为十六进制值0x41,告诉调用先创建文件。模式设置为十六进制值0x1FF,该值被转换为二进制值 0000 0000 0001 1111 1111,它设置文件许可: (...)0 111(n)111(g)111(其他)。
令人惊叹!这正是我需要的。 – Ahmad 2016-01-22 16:54:54