0

I've just written my first MIPS addition program. My output is expected ($t0 + $t1 = $t2), but I have a question regarding some strange behavior that I believe should be avoidable.

On the lines where I gather the user input (li $v0, 5), the value of the $v0 service call gets set to the value of my user input. So for example, if I enter "10" as user input, $v0 is assigned the value 10, which is the service code to terminate the program.

Is there something I can do to ensure that my user input doesn't affect the service calls on the $v0 registry? Side Note: is my Assembly terminology correct here?

.data
prompt1: .asciiz "Give me an integer: "
prompt2: .asciiz "Give me another integer: "
result: .asciiz "The sum of the two inputted numbers is: "

.text
main:
# Service call to Print String, then show prompt1
li $v0,4
la $a0, prompt1
syscall

# Get first int from user
li $v0, 5
syscall
# Move the user's input to $t1
move $t0, $v0
syscall

# Service call to Print String, then show prompt2
li $v0, 4
la $a0, prompt2
syscall

# Get second int from user
li $v0, 5
syscall
# Move the user's input to $t1
move $t1, $v0
syscall

# $t2 = $t1 + $t0
add $t2, $t1, $t0
syscall

# Print result string
li $v0, 4
la $a0, result
syscall

# System service code to print an integer, then move sum value to $a0
li $v0, 1
move $a0, $t2
syscall

# End program
li $v0, 10
syscall

Thanks for the assistance in advance.

zcoon
  • 174
  • 11
  • You should set `$v0` to the desired system call number prior to each `syscall` instruction. – Michael Sep 03 '16 at 21:19
  • @Michael I'm fairly certain I am doing that, but another `syscall` is being executed at the time the user's input is submitted without there being a second `syscall` in the program. – zcoon Sep 03 '16 at 21:21
  • 1
    But you seem to be using `syscall` in ways that make no sense. What is `move $t0, $v0`/`syscall` supposed to do? – Michael Sep 03 '16 at 21:21
  • @Michael I thought that was necessary to execute blocks of code. Could you elaborate on the proper times to use `syscall`? (Keep in mind this my first mips program so I appreciate any advice) – zcoon Sep 03 '16 at 21:24
  • 2
    `syscall` is used to perform a system call (e.g. `print_string` or `read_int`), with the system call number given in `$v0`. It's not something you sprinkle throughout your code after every single instruction. – Michael Sep 03 '16 at 21:25
  • @Michael Got it. I removed some of the unnecessary `syscall`s. The program works properly now and I understand the use of `syscall`. Thank you very much. – zcoon Sep 03 '16 at 21:29

0 Answers0