【发布时间】:2016-04-22 08:44:39
【问题描述】:
我想将一些内容(字符串和浮点数)打印到文件中。
这就是我目前实现的:
.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),但主要问题是它们只提供代码,并没有涵盖我上面的问题.
【问题讨论】:
标签: assembly printing io mips system-calls