我想打印一些文件的內容(字符串和浮點數)。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
是的,請參閱下面的答案。我找到了解決方案 –