我想打印一些文件的内容(字符串和浮点数)。Mips-打印到文件
这是我到目前为止已经实现:
.data:
line_break: .asciiz "\n"
buffer: .space 1024
.text:
main:
addi $t0, $zero, -1
jal open_file # open the file to write to
beq $v0, $t0, create_file # if return value -1 --> file not available --> create the file
move $s6, $v0 # save the file descriptor
[...]
ulw $t0, print_initiaton_message # save the print_initiaton_message in a temp
sw $t0, buffer # put print_initiaton_message on buffer
li $v0, 15 # syscall to write to file
move $a0, $s6 # move file descriptor to $a0
la $a1, buffer # target to write from
li $a2, 1024 # amount to be written
syscall # syscall to write in file
[...]
s.s $f12, buffer
li $v0, 15 # syscall to write to file
move $a0, $s3 # move file descriptor to $a0
la $a1, buffer # target to write from
li $a2, 4 # amount to be written
syscall # syscall to write in file
[...]
的基本思想是把必要的信息在缓冲区中,然后执行系统调用。
它似乎工作 - 因为正确创建文件,然后打开和关闭。还有一个在它的内容,但没有预期的结果:
’®)@
PÀ<@
[...]
在第一的位置,应该有一个字符串,然后换行,接着是浮点。
现在我的问题: - 我如何才能实现我的输出格式? - 如果我的输入超过缓冲区大小,那么缓冲区大小是什么意思,会发生什么? - 写入的金额是多少?
我试图通过几个系统调用引用(即this one),查找示例(和found this或that),但主要问题是它们只提供代码,并未涵盖上述问题。
根据MIPS指令参考([可在此获得](http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html))sw将$ t0的内容保存到指定的地址,缓冲区。我想将previos子过程的输出保存到缓冲区,以便我可以打印它。 –
什么数据类型是缓冲区的输出?如果输出是字符串,则需要将该字符串复制到缓冲区中。如果输出是单个整数,则需要首先将整数格式化为字符串。 – Zack
是的,请参阅下面的答案。我找到了解决方案 –