【发布时间】:2017-09-27 03:57:02
【问题描述】:
我正在尝试从用户输入的数字开始倒数,并希望显示介于数字和 0 之间的所有整数。我相信我的输出会下降,但随后会进入无限循环1. 似乎永远不会归零。
我刚开始学习汇编,所以如果这是一个不好的问题,我会提前道歉。
谢谢
这是我的代码:
.globl main
.data
msg: .asciiz "Input a number: "
x: .word 1
.text
main:
li $v0,4 # display the first message
la $a0, msg
syscall
li $v0, 5 # call for an input read, stores in $v0
syscall
move $t0, $v0 # move the input to a temporary register
lw $t1, x # loads x into $t1 registers
# Show Output
doLoop:
sub $v0, $t0, $t1 # subtracts 1 from given input stores in $v0
move $s0, $v0
li $v0, 1 # Prepares to print integer
move $a0, $v0
syscall
bgt $a0, 0, doLoop
li $v0,10 # load the "exit" number into register $v0
syscall
【问题讨论】:
-
google“mips 调试”并放入您使用的模拟器(MARS 或 SPIM?)。然后观察自己,寄存器中的值是如何演变的,以及为什么你的循环测试不起作用。
-
我正在使用 MARS,谢谢!