Question: THIS CODE WORKS WITHIN THE RANGE AND OUTSIDE THE RANGE BUT IT DOES NOT WORK ON THE EDGE. CHANGE THIS CODE SO WHEN I ADD

 THIS CODE WORKS WITHIN THE RANGE AND OUTSIDE THE RANGE BUT

THIS CODE WORKS WITHIN THE RANGE AND OUTSIDE THE RANGE BUT IT DOES NOT WORK ON THE EDGE. CHANGE THIS CODE SO WHEN I ADD 20 + 30 OR 10 + 10 WHICH WOULD BE ON EDGE, IT GIVES ME THE CORRECT OUTPUT. PLEASE UNDERSTAND THE QUESTION FIRST AND THEN ANSWER

.data

prompt1: .asciiz "Please enter the first number: "

prompt2: .asciiz "Please enter the second number: "

within: .asciiz " is within the range. "

outside: .asciiz " is outside the range. "

edge: .asciiz " is on the edge. "

lower: .word 20

upper: .word 50

.text

.globl main

main:

# Prompt user for first number

li $v0, 4 # system call code for print string

la $a0, prompt1 # address of first string

syscall # print prompt1

# Read first number into $t0

li $v0, 5 # system call code for read integer

syscall # read first number into $v0

move $t0, $v0 # move first number to $t0

# Prompt user for second number

li $v0, 4 # system call code for print string

la $a0, prompt2 # address of second string

syscall # print prompt2

# Read second number into $t1

li $v0, 5 # system call code for read integer

syscall # read second number into $v0

move $t1, $v0 # move second number to $t1

# Add two numbers and store the result in $t2

add $t2, $t0, $t1

# Load lower bound into $t3

lw $t3, lower

# Load upper bound into $t4

lw $t4, upper

# Compare the result with lower bound

blt $t2, $t3, outside_label

# Compare the result with upper bound

bgt $t2, $t4, outside_label

# Result is within the range

li $v0, 4 # system call code for print string

la $a0, within # address of within string

syscall # print within

b end_label

outside_label:

# Result is outside the range

li $v0, 4 # system call code for print string

la $a0, outside # address of outside string

syscall # print outside

b end_label

edge_label:

# Result is on the edge

li $v0, 4 # system call code for print string

la $a0, edge # address of edge string

syscall # print edge

end_label:

# End of program

li $v0, 10 # system call code for exit

syscall # exit program

here are two groups of control instructions. The first one is "branch", and the second one is "jump". branch" is conditional transfers of control. "jump" is unconditional transfers of control. his lab will focus on "branch". MIPS branch instructions are beg, bne, bgt, blt etc. You can find all the ranching instructions on Mars. his lab you are required to write an assembly program to practice branching. rogram details - 1. Prompt the user to enter two numbers. 2. Set the range value (the lower bound is 20 and the upper bound is 50 ). 3. Add these two numbers. 4. Display whether the answer is within the range, outside the range, or on the edge. Example 1: Please enter the first number: 18 Please enter the second number: 10 28 is within the range. Example 2: Please enter the first number: 8 Please enter the second number: 10 18 is outside the range. Example 3: Please enter the first number: 20 Please enter the second number: 30 50 is on the edge

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!