簡體   English   中英

MIPS打印整數而不使用任何偽指令

[英]MIPS print integer without use any pseudoinstructions

這是我所做的

num1:.word 1
num2:.word 2
.globl main
.text
main:
lui $t0,0x1001
addi $v0,$0,1  #set commend to print 
addi $s2,$0,5 # add 5 to $s2
sw $s2,4($t0) # store the val in word 2
addi $a0,$t0,4 # add 4 to t0 to start the second word 
syscall # print int 

我希望打印s2的值,但是我得到268500996。此外,如果我想打印單詞1和單詞2,如何在自己的行上輸出每個輸出。

syscall 1 期望$a0包含要打印的值 ,不包含要打印的值的地址。 所以代替:

sw $s2,4($t0) # store the val in word 2
addi $a0,$t0,4 # add 4 to t0 to start the second word 

您應該這樣做:

or $a0, $s2, $0  # $a0 = $s2

要打印換行符,您將打印字符13(回車)和10(換行)。 您可以使用syscall 4( print_string )或兩次調用syscall 11( print_character )來完成此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM