I need help with this code please its supposed to take 'n' numbers and take the average of all of the numbers in MIps assembly code   the problem is that it is not working here is the code:   .dataprompt: .asciiz "Enter the number of real numbers: ".text.globl mainmain:li $v0, 4la $a0, promptsyscallli $v0, 5syscallmove $t0, $v0li $t1, 0loop:beq $t0, $t1, endli $v0, 6syscalladdi $t1, $t1, 1j loopend:li $v0, 10syscall # Initialize $t0 to hold the sumadd $t0, $zero, $zero # Initialize $t1 to hold the countadd $t1, $zero, $zero # Start the looploop2:    # Load the current number    lw $t2, 0($a0)     # Add the current number to the sum    add $t0, $t0, $t2     # Increment the counter    addi $t1, $t1, 1     # Move to the next number   addi $a0, $a0, 4    # Continue the loop if there are more numbers   bne $t1, $a1, loop2    # Calculate the average   div $t0, $t1    # Move the result to $v0,  mflo $v0

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter3: Assignment, Formatting, And Interactive Input
Section3.4: Program Input Using Cin
Problem 9E
icon
Related questions
Question
100%

I need help with this code please its supposed to take 'n' numbers and take the average of all of the numbers in MIps assembly code

 

the problem is that it is not working

here is the code:

 

.data
prompt: .asciiz "Enter the number of real numbers: "
.text
.globl main
main:
li $v0, 4
la $a0, prompt
syscall
li $v0, 5
syscall
move $t0, $v0
li $t1, 0
loop:
beq $t0, $t1, end
li $v0, 6
syscall
addi $t1, $t1, 1
j loop
end:
li $v0, 10
syscall


# Initialize $t0 to hold the sum
add $t0, $zero, $zero

# Initialize $t1 to hold the count
add $t1, $zero, $zero

# Start the loop
loop2:
    # Load the current number
    lw $t2, 0($a0)

    # Add the current number to the sum
    add $t0, $t0, $t2

    # Increment the counter
    addi $t1, $t1, 1

    # Move to the next number
   addi $a0, $a0, 4

   # Continue the loop if there are more numbers
   bne $t1, $a1, loop2

   # Calculate the average
   div $t0, $t1

   # Move the result to $v0
,  mflo $v0

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr