I have the following MIPS code. I don't know how to make it such that there are two arrays with a size controlled by a vector.
For instance, the user would enter a size (let's say 5
). The arrays sizes would then be set to 5
. Then the user could enter in numbers for array one, say 10 10 10 10 10
, and then for array 2. Finally, the program will display the sum and averages for both arrays.
This is the code so far:
.data
prompt: .asciiz "Enter 10 Elements: \n"
avg: .asciiz "Average of these numbers is: "
sum: .float 0
count: .float 10
.text
main:
---size of the vector using prompt
la $a0 prompt
li $v0 4
syscall
li $t1, 40 # t1 has count
li $t2, 0 # t2 is iterator
l.s $f12, sum # t3 has sum
while: bge $t2, $t1, end
li $v0, 6
syscall
add.s $f12, $f12, $f0
addi $t2, $t2, 4
b while
end:
la $a0 avg
li $v0, 4
syscall
lwc1 $f10, count
div.s $f12, $f12, $f10
li $v0, 2
syscall
li $v0, 10
syscall
li $v0, 2
lwc1, $f12 sum