1

I am using QTSpim as my MIPS simulator and am having a hard time figuring out how to print out an integer that the user input. So far, my code is:

.data
prompt: .asciiz "Please enter an integer: "

.text
main:
li $v0, 4
la $a0, prompt
syscall

li $v0, 5
move $s0, $v0
syscall

li $v0, 5
move $s1, $v0
syscall

li $v0, 5
move $s2, $v0
syscall

jal order3

li $v0, 1
move $a0, $s0
syscall

li $v0, 10
syscall


swap:
move $t0, $a0
move $a0, $a1
move $a1, $t0
jr $ra

swap1:
move $t0, $a1
move $a1, $a2
move $a2, $t0
jr $ra

order3:
bgt $a0, $a1, swap
bgt $a1, $a2, swap1
bgt $a0, $a1, swap
jr $ra

Every time I try to print out my first integer, it prints out a 5, which it shouldn't. I do not know why this is happening. If anyone could point out the flaw in my code that would be great.

Thanks.

1 Answer 1

1

You're trying to use the result of a syscall before the syscall has been performed:

li $v0, 5
move $s0, $v0
syscall

That should be:

li $v0, 5
syscall
move $s0, $v0

Same for the other two read_int syscalls.

Then there's also the fact that your order3 routine is checking/altering $a0..$a2, while your numbers are in $s0..$s2.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.