Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MIPS ASSEMBLY Here is my code : .data prompt: .asciiz Enter the number of values: prompt2: .asciiz Enter integer values, one per line.

MIPS ASSEMBLY

image text in transcribed

Here is my code :

.data prompt: .asciiz "Enter the number of values: " prompt2: .asciiz "Enter integer values, one per line. " even: .asciiz "The even numbers are: " newline: .asciiz " " average: .asciiz "The average of the even numbers is: " error : .asciiz "Not in range" MSG4: .asciiz "," .text .globl main main: # print prompt li $v0, 4 la $a0, prompt syscall # read number of values li $v0, 5 syscall move $t0, $v0

######################################################### # check if number of values is between 1 and 10 li $t1, 1 bge $t0, $t1, input li $v0, 4 la $a0, error syscall li $v0, 10 syscall ##############################################31###########

input:

# print prompt li $v0, 4 la $a0, prompt2 syscall # loop to read values and print even numbers li $t2, 0 # count of even numbers li $t1, 0 # sum of even numbers

loop: bgt $t0, 0, read_value j calculate_average

read_value: # 48read value li $v0, 5 syscall move $s0, $v0 # check if value is even li $t1, 2 rem $t3, $s0, $t1 bne $t3, $0, next_value

# increment count of even numbers addi $t2, $t2, 1

# print "The even numbers are: " beq $t2, 1, print_even

# print comma li $v0, 4 la $a0, MSG4 syscall

print_even: li $v0, 4 la $a0, even syscall next_value: # decrement t0 addi $t0, $t0, -1 j loop calculate_average: # check if there were any even numbers beq $t2, $0, exit # divide sum by count to get average li $t3, 1000000 div $t1, $t3 mflo $t1 li $v0, 4 la $a0, newline syscall li $v0, 4 la $a0, average syscall li $v0, 2 move $a0, $t1 syscall

exit: # exit program li $v0, 10 syscall

####################################################

the problem is if i ask foe example to print 3 values, it only reads in 1 value and does not give the count of even numbers or the average properly.

Here is an exampe of the output:image text in transcribed

Also, I have bolded the line of code I suspect might be wrong

Thanks

Write the following in MIPS assembly and match the output exactly as shown below The program should prompt the user and read an integer value indicating n, which is the number of values to be entered. If the n value is not between 1 and 10 , then you should print an appropriate error message and exit. Otherwise, you should prompt the user and read each of the n values. You should then print the values that were even, separated by com-mas. If one or more values were even, then print the average of the even values. Enter the number of values: 5 Enter 5 integer values, one per line. 2 7 10 4 The even numbers are: 2,10,4 The average of the even numbers is: 2.66666675 Enter the number of values: 3 Enter integer values, one per line. 4 The even numbers are: 5

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

List seven advantages of DC motors with respect to AC motors.

Answered: 1 week ago

Question

Define Administration and Management

Answered: 1 week ago