Question

In: Computer Science

MIPS Program I'm trying to write a program that will take in two numbers from the...

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"

Solutions

Expert Solution

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:


Related Solutions

Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two integers. Ideally, the program would ask for the user to type in the two integers. Then, the program would calculate the hamming distance. Afterward, it would ask if you'd like to find another hamming distance. If the user says yes, it would loop back to the beginning and ask for two new integers. Below is the code that I've created so far. Guidance with...
I'm trying to write a feet to meters and centimeters program and I'm looking for a...
I'm trying to write a feet to meters and centimeters program and I'm looking for a little help so I can see how close I got. It should do the following: Write a convertToMetric class that has the following field: standard - holds a double, standard length value in feet. The class should have the following methods: Constructor - that accepts a length in feet (as a double) and stores it in the standard field. setStandard - accepts a standard...
Write a MIPS Assembly program that computes the sum of all the odd numbers from 1...
Write a MIPS Assembly program that computes the sum of all the odd numbers from 1 ..99 and print out the answer.
Write a MIPS program that asks the user for 2 numbers. Output the sum of the...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the 2 numbers. The difference between the 2 numbers (num1-num2) and (num2-num1) The value that is 305 more than the 1st number. The value that is 305 less than the 2nd number
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
Write a MIPS assembly program to calculate the Fibonacci numbers from 1..n using the recursive method....
Write a MIPS assembly program to calculate the Fibonacci numbers from 1..n using the recursive method. The definition of a Fibonacci number is F(n) = F(n-1) + F(n-2). The implementation must follow the following guidelines: Prompt the user for a number n Allocate heap memory to hold the exact number of elements in the Fibonacci sequence for n Implement recursive Fibonacci method as a subprogram Print the Fibonacci sequence array
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Write MIPs program that will read two intergers from the user and compute for the sum...
Write MIPs program that will read two intergers from the user and compute for the sum and difference of the two intergers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
I'm trying to write a program that reads 3 heights of kids and puts them in...
I'm trying to write a program that reads 3 heights of kids and puts them in ascending order using if and else statements but i'm having trouble #include<stdio.h> int main() { int k1,k2,k3; printf("Enter height of kid #1 >"); scanf("%d",&k1); printf("Enter height of kid #2 >"); scanf("%d",&k2); printf("Enter height of kid #3 >"); scanf("%d",&k3); if(k3>k2>k1) { printf("In ascending order %d %d %d",k3,k2,k1); } else if(k3>k1>k2) { printf("In ascending order %d %d %d",k3,k1,k2); } else if(k2>k3>k1) { printf("In ascending order %d...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT