Question: Instructions: write a code in MIPS that will display two user input integers along with their sum and difference. Problem: When reading the 2nd integer

Instructions: write a code in MIPS that will display two user input integers along with their sum and difference.

Problem: When reading the 2nd integer back, it reads it back 3 times (see screenshot). I am unable to identify the problem.

Screenshot:

Instructions: write a code in MIPS that will display two user input

How you can help: Please help me understand why it is repeating 3 times.

Code:

.data prompt1: .asciiz "Enter the first integer: " prompt2: .asciiz "Enter the second integer: " num1: .asciiz "The first number is: " num2: .asciiz " The second number is: " op1: .asciiz " The sum of both numbers is: " op2: .asciiz " The difference of both numbers is: "

# $s0 = first integer # $s1 = second integer # $s2 = location of sum # $s3 = location of difference

##################################### # Program ##################################### .text .globl main main:

la $a0, prompt1 li $v0, 4 # "Enter the first integer:" syscall

li $v0, 5 syscall # Read first integer move $s0, $v0

la $a0, prompt2 li $v0, 4 # "Enter the second number: " syscall

li $v0, 5 syscall # read integer move $s1, $v0

#******************************************************************************** # Read back both integers. ERROR; second integer repeats itself two times. #********************************************************************************

la $a0, num1 li $v0, 4 # "The first number is:" syscall

li $v0, 1 move $a0, $s0 # print integer syscall

la $a0, num2 li $v0, 4 # "The second number is:" syscall

li $v0, 1 move $a0, $s1 # print integer syscall

#******************************************************************************** # Allow SPIM to perform addition/subtraction operations; COMPLETE #********************************************************************************

add $s2, $s0, $s1 # Adds both integers syscall sub $s3, $s0, $s1 # Subtracts both integers syscall

#******************************************************************************** # Read back both operations. COMPLETE #********************************************************************************

la $a0, op1 li $v0, 4 # "The sum of both numbers is: " syscall

li $v0, 1 move $a0, $s2 # Print sum syscall

la $a0, op2 li $v0, 4 # "The difference of both numbers is: " syscall

li $v0, 1 move $a0, $s3 # Print difference syscall

li $v0, 10 # terminates program. syscall

Thank you!

Console Enter the first integer: 13 Enter the second integer: 9 The first number is: 13 The second number is: 999 The sum of both numbers is: 22 The difference of both numbers is: 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!