我正在使用MARS MIPS模擬器,並且想在程序中打印換行符。在MIPS中打印換行
.data
space: .asciiz "\n"
.text
addi $v0, $zero, 4 # print_string syscall
la $a0, space # load address of the string
syscall
除了打印換行的,它打印UUUU
。我做錯了什麼?
我正在使用MARS MIPS模擬器,並且想在程序中打印換行符。在MIPS中打印換行
.data
space: .asciiz "\n"
.text
addi $v0, $zero, 4 # print_string syscall
la $a0, space # load address of the string
syscall
除了打印換行的,它打印UUUU
。我做錯了什麼?
在打印值的代碼塊之後初始化新行。
,所以它讀取:
addi $v0, $zero, 4 # print_string syscall
la $a0, space # load address of the string
syscall
.data
space: .asciiz "\n"
.text
如果你只是想打印一個換行符,它更簡單(及略微更高效的內存),使用系統調用11打印單個字符來做到這一點。
.text
main: addi $a0, $0, 0xA #ascii code for LF, if you have any trouble try 0xD for CR.
addi $v0, $0, 0xB #syscall 11 prints the lower 8 bits of $a0 as an ascii character.
syscall
謝謝。它簡單而有用。 – 2014-10-24 17:02:07
試試這個..我的作品
.data
newLine .asciiz "\n"
.text
(your code)
la $a0, newLine
addi $v0, $0, 4
syscall
我正在使用MIPS 4.5。 – Chon 2015-08-17 16:30:05
我來到這裏,試圖找到你問同樣的問題的答案。自從你問這個問題已經有一段時間了。無論如何,無論如何,任何人都可能會看到這種飼料。
除了「space」是Mips中的保留字外,其他所有代碼都適合您的代碼。我認爲它被用來創建數組。所以,如果你用其他詞替換空格,我使用了「換行符」。它按照預期的方式工作。
.data
newline: .asciiz "\n"
.text
li $v0, 4 # you can call it your way as well with addi
la $a0, newline # load address of the string
syscall
它適用於我(使用MARS 4.1) – gusbro 2012-03-26 16:05:29
我使用4.2,它不工作。 – gzg 2012-03-26 16:08:14
適用於4.2的我也適用... – gusbro 2012-03-26 16:26:36