Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago