接收用户整数,存储,然后打印MIPS汇编

时间:2013-03-11 17:05:26

标签: assembly mips

我可以接受用户输入:

addi $v0, $zero, 4
la $a0, str.num2
syscall
addi $v0, $zero, 5
syscall
add $s1, $zero, $v0

它在$ s1中,我只是不知道如何打印出来。我怎么能这样做?

1 个答案:

答案 0 :(得分:7)

Here您在MARS中有系统调用的参考。在此之后,代码应该是:

# Print message (syscall 4)
addi $v0, $zero, 4
la $a0, str.num2
syscall

# Read number (syscall 5)
addi $v0, $zero, 5
syscall

# Print number (syscall 0)
add $a0, $zero, $v0  # Get number read from previous syscall and put it in $a0, argument for next syscall
addi $v0, $zero, 1   # Prepare syscall 0
syscall              # System call

始终注释您的代码,特别是如果它是汇编代码。