Reputation: 193
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.
Upvotes: 1
Views: 398
Reputation: 58507
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
.
Upvotes: 1