Submersed24
Submersed24

Reputation: 49

Syscall print int

I am just wondering why this doesn't work:

Print Integer:   li $v0, 1
             li, $a0, $v0     #with $v0 being an added up value
             syscall

But, this works:

Print Integer:  li $v0, 1
        li, $a0, 100
        syscall

Is there any register that I can use to print an integer that has been altered by an algorithm? I always thought $v0 was the register that stores returns.

Upvotes: 0

Views: 845

Answers (1)

Michael
Michael

Reputation: 58487

First of all, you've got a syntax error here:

li, $a0, $v0

There should be no comma after li.

Secondly, the purpose of the li pseudo-instruction is to load immediates (e.g. 1, 0x42, or 12345). If you want to move (copy) the contents of one register to another, use move (as in move $a0, $v0).

And finally, you assigned $v0 the value 1 on the first line of your code, so even if you correctly said move $a0, $v0 you'd always get $a0 = 1. If you want the previous value of $v0 you have to do move $a0, $v0 before li $v0, 1.

Upvotes: 2

Related Questions