2010-09-14 62 views
0

我在这里遇到MIPS问题。我想要做的是让用户输入任意数字并让程序拼出数字中每个数字的名称。例如,用户输入495,机器将拼出“四九五”。我试图将数字的每个数字推入堆栈,然后弹出每个数字。但是,弹出的数字不是看起来被推入堆栈的数字。我对此很困惑,希望有人能帮助我!我的代码的重要部分如下:MIPS编程问题

.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 

回答

0

解决了它。原来spim和xspim是完全愚蠢的,越野车和错误的。我通过火星运行这个代码,并且它运行得很完美。我现在很高兴:)