Service Calls Executing Based on User Input

折月煮酒 提交于 2019-12-25 04:26:32

问题


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.

来源:https://stackoverflow.com/questions/39311412/service-calls-executing-based-on-user-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!