user2157777
user2157777

Reputation: 49

Recieving user integer, storing, then printing it MIPS Assembly

I can accept user input:

addi $v0, $zero, 4
la $a0, str.num2
syscall
addi $v0, $zero, 5
syscall
add $s1, $zero, $v0

It's in $s1, I just don't know how to get that printed out. How can i do that?

Upvotes: 2

Views: 28049

Answers (1)

m0skit0
m0skit0

Reputation: 25863

Here you have a reference for syscalls in MARS. Following this, the code should go:

# Print message (syscall 4)
addi $v0, $zero, 4
la $a0, str.num2
syscall

# Read number (syscall 5)
addi $v0, $zero, 5
syscall

# Print number (syscall 0)
add $a0, $zero, $v0  # Get number read from previous syscall and put it in $a0, argument for next syscall
addi $v0, $zero, 1   # Prepare syscall 0
syscall              # System call

Always comment your code, specially if it's assembly.

Upvotes: 7

Related Questions