MIPS编程问题

时间:2010-09-14 02:57:12

标签: assembly loops stack mips

我在这里遇到MIPS问题。我要做的是让用户输入任何数字,并让程序拼出数字中每个数字的名称。因此,例如,用户输入495并且机器将拼出“Four Nine Five”。我试图将数字的每个数字推到堆栈上,然后将每个数字都弹出。但是,弹出的数字不是看似被推入堆栈的数字。我对此非常困惑,希望有人能帮助我!我的代码的重要部分如下:

.text
main: li $v0, 5
syscall
move $t0, $v0
# store 10 into a register, because you can't divide by a constant
li $s1, 10

# now the input number is stored in $a0.  Time to divide by 10 a few times,
#and store each digit in a stack:
DivideLoop: # $s3 = $s0 / 10
div $t0, $s1
# this is the remainder of the division
mfhi $t3
mflo $t2
# move stack over by 4
addi $sp, $sp, -4
# store remainder in stack
sw $t3, 0($sp)
move $t0, $t2
beq $t2, $zero, PrintLoop
j DivideLoop

# This loop prints each digit
PrintLoop:
# check if stack is empty.  If so, branch to exit.
beq $sp, $zero, Exit
# put first word of stack into register $t0
lw $t0, 0($sp)
addi $sp, $sp, 4

1 个答案:

答案 0 :(得分:0)

解决了它。原来spim和xspim完全是愚蠢的,错误的和错误的。我在火星上运行了这段代码,它运行得很好。我现在很高兴:)

相关问题