2010-09-14 81 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是完全愚蠢的,越野車和錯誤的。我通過火星運行這個代碼,並且它運行得很完美。我現在很高興:)