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

MIPS ASSEMBLY

MIPS ASSEMBLY Here is my code : .data prompt: .asciiz "Enter the

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:number of values: " prompt2: .asciiz "Enter integer values, one per line.

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

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!