views:

52

answers:

1

Hello all. I'm having a MIPS issue here. What I'm trying to do is have the user input any number and have the program spell out the name of each digit in the number. So for example, the user inputs 495 and the machine would spell out "Four Nine Five". I'm trying to push each digit of the number onto the stack, then pop each one off. However, the number that gets popped off is not the number that appears to be pushed onto the stack. I'm pretty confused regarding this and I hope someone can help me out! The important section of my code is as follows:

.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
A: 

Solved it. Turned out spim and xspim are completely stupid, buggy and wrong. I ran this code through Mars, and it ran perfectly. I'm happy now :)

Corey Watts