繁体   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