MIPS:写入和读取文件 [英] MIPS: Write AND read a file
问题描述
我正在尝试在MIPS中合并两个不同的程序,以便在文件上写入内容,然后通过简单的菜单进行读取. 写作做得很好,流畅.阅读有点麻烦,因为我看不到任何输出.如果与写作部分分开,则阅读部分本身可以工作. 有人可以告诉我我做错了什么吗? 谢谢!
I'm trying to merge two different programs in MIPS in order to write something on a file and then read it through a simple menu. Writing is done good and smooth. Reading is a bit more problematic, since I can't see any output. The reading part itself works, if separated from the writing part. Can someone enlight me on what I'm doing wrong? thanks!
<pre>
.data
fout: .asciiz "test.txt"
reservedspace: .space 1024
cont: .asciiz "reading file... "
buffer: .asciiz "some text to test the program."
##################################################
.text
main:
menu:
getinput:
li $v0, 5
syscall
move $s0, $v0
beq $s0, 0, create
beq $s0, 1, read
beq $s0, 2, delete
beq $s0, 3, show
beq $s0, 4, exit
j getinput
#######################################
create:
#write on file
#open
li $v0, 13
la $a0, fout
li $a1, 1
li $a2, 0
syscall
move $s6, $v0
#write
li $v0, 15
move $a0, $s6
la $a1, buffer
li $a2, 30
syscall
#close
li $v0, 16
move $a0, $s6
syscall
j menu
search:
li $v0, 13
la $a0, fout
li $a1, 0
li $a2, 0
syscall
move $s6, $v0
li $v0, 14
move $a0, $s6
la $a1, reservedspace
li $a2, 1024
syscall
li $v0, 4
la $a0, cont
syscall
close:
li $v0, 16
move $a0, $s6
syscall
j menu
delete:
show:
exit:
li $v0, 10 #Terminate Program
syscall
<code>
推荐答案
由于未打印已阅读的内容,因此看不到任何输出.
从文件中读取文本后,应将其存储在您提供的缓冲区(reservedspace
)中.
因此,例如,您可以使用以下命令打印该缓冲区的内容:
You are not seeing any output because you are not printing what you have read.
After reading the text from the file it should be stored in the buffer you provided (reservedspace
).
So, you can for example print the contents of that buffer with
la $a0, reservedspace
li $v0, 4
syscall
这篇关于MIPS:写入和读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!