In: Computer Science
MIPS Program
I'm trying to write a program that will take in two numbers from the user and output the sum at the end. However, I keep getting very wrong answers. For example, I add 2 and 2 and get 268501000. Help would be appreciated.
.data #starts data use
userIn1:
.word 4 #sets aside space for input
userIn2:
.word 4 #sets aside space for input
total:
.word 4 #sets space aside for input
request:
.asciiz "Enter an integer value: "
echoStr:
.asciiz "The total is: "
.text #starts string use
.globl main
main:
#prints request for 1st number
la $a0, request #loads string into argument
li $v0, 4 #request to print set in register $v0
syscall #execute
#takes in user input
la $a0, userIn1 #pointer to info
li $v0, 5 #request for user input set in register
$v0
syscall
#prints request for 2nd number
la $a0, request #loads string into argument
li $v0, 4 #request to print set in register $v0
syscall #execute
#takes in user input
la $a1, userIn2 #pointer to info
li $v0, 5 #request for user input set in register
$v0
syscall
#NEXT CHUNK IS PROBABLY ISSUE
#adds numbers together
add $t0, $a0, $a1 #adds numbers together
sw $t0, total #stores total
syscall
#prints out awknowledgement
la $a0, echoStr #stores string in $a0 argument
spot
li $v0, 4 #request to print set in register $v0
syscall
#prints out user input
la $a0, total #calls user input and stores it as
argument 0
li $v0, 1 #request to print set in register $v0
syscall
#to properly exit program
li $v0, 10
syscall
.data #end of data use
endl: .asciiz "\n"
Program:
.data #starts data use
userIn1:
.word 4 #sets aside space for input
userIn2:
.word 4 #sets aside space for input
total:
.word 4 #sets space aside for input
request:
.asciiz "Enter an integer value: "
echoStr:
.asciiz "The total is: "
.text #starts string use
.globl main
main:
#prints request for 1st number
la $a0, request #loads string into argument
li $v0, 4 #request to print set in register $v0
syscall #execute
#takes in user input
la $a0, userIn1 #pointer to info
li $v0, 5 #request for user input set in register $v0
syscall
move $t1,$v0 #store integer 1 in $t1
#prints request for 2nd number
la $a0, request #loads string into argument
li $v0, 4 #request to print set in register $v0
syscall #execute
#takes in user input
la $a1, userIn2 #pointer to info
li $v0, 5 #request for user input set in register $v0
syscall
move $t2,$v0 #store integer 2 in $t2
#NEXT CHUNK IS PROBABLY ISSUE
#adds numbers together
add $t0, $t1, $t2 #adds numbers together
sw $t0, total #stores total
#prints out awknowledgement
la $a0, echoStr #stores string in $a0 argument spot
li $v0, 4 #request to print set in register $v0
syscall
#prints out user input
lw $a0, total #calls user input and stores it as argument 0
li $v0, 1 #request to print set in register $v0
syscall
#to properly exit program
li $v0, 10
syscall
.data #end of data use
endl: .asciiz "\n"
Output: