I managed to solve the exercise this way:
.data
vect1: .float
.space 256
vect2: .float
.space 256
num1: .word
.space 4
num2: .word
.space 4
average: .float
.space 4
numag: .word
.space 4
i: .word
.space 4
count: .word
.space 4
sum: .float
.space 4
fnum: .float
.space 4
str1: .asciiz "The average is: "
.align 2
str2: .asciiz "\n"
.align 2
str3: .asciiz "In vector 2 there are "
.align 2
str4: .asciiz " elements major of "
.align 2
x: .float
.space 4
str5: .asciiz "Number of elements: "
.align 2
str6: .asciiz "Element: "
.align 2
.text
.globl main
main:
# read_vect1_float(vect1,num1);
lwc1 $f12,vect1
lw $a0,num1
jal read_vect1_float
# leggi_vet2_float(vect2,num2);
lwc1 $f13,vect2
lw $a1,num2
jal read_vect2_float
# sum=0.0;
mtc1 $zero,$f1
cvt.s.w $f1,$f1
# for(i=0;i<num1;i++)
li $t0,0
for:
# sum=sum+vect1[i];
move $t3,$t0
sll $t3,$t3,2
lwc1 $f2,vect1($t3)
add.s $f1,$f1,$f2
addi $t0,$t0,1
blt $t0,$t1,for
# fnum=(float)num1;
mtc1 $t1,$f3
cvt.s.w $f3,$f3
# sum=sum/fnum;
div.s $f1,$f1,$f3
# average=sum;
swc1 $f1,average
# cout<< "The average is: " << average;
li $v0,4
la $a0,str1
syscall
li $v0,2
lwc1 $f12,average
syscall
# cout << "\n";
li $v0,4
la $a0,str2
syscall
# count=0;
li $t4,0
sw $t4,count
# for(i=0;i<num2;i++)
li $t0,0
for2:
move $t3,$t0
sll $t3,$t3,2
lwc1 $f2,vect2($t3)
# if(vect2[i]>average)
c.le.s $f2,$f1
bc1t next
# count=count+1;
addi $t4,$t4,1
addi $t0,$t0,1
blt $t0,$t2,for2
next:
# numag=count;
sw $t4,numag
# cout << "In vector 2 there are ";
li $v0,4
la $a0,str3
syscall
# cout << numag;
li $v0,1
lw $a0,numag
syscall
# cout << " elements major of "
li $v0,4
la $a0,str4
syscall
# cout << average;
li $v0,2
lwc1 $f12,average
syscall
# cout << "\n";
li $v0,4
la $a0,str2
syscall
li $v0,10
syscall
read_vect1_float:
# cout << "Number of elements: ";
li $v0,4
la $a0,str5
syscall
# cin >> num1;
li $v0,5
syscall
sw $v0,num1
lw $t1,num1
# for(i=0;i<num1;i++)
li $t0,0
forsub1:
# cout=<< "Element: " ;
li $v0,4
la $a0,str6
syscall
# cin >> x;
li $v0,6
syscall
swc1 $f0,x
# vect1[i]=x;
move $t4,$t0
sll $t4,$t4,2
swc1 $f0,vect1($t4)
addi $t0,$t0,1
blt $t0,$t1,forsub1
jr $ra
read_vect2_float:
# cout << "Number of elements: ";
li $v0,4
la $a0,str5
syscall
# cin >> num2;
li $v0,5
syscall
sw $v0,num2
lw $t2,num2
# for(i=0;i<num2;i++)
li $t0,0
forsub2:
# cout=<< "Element: " ;
li $v0,4
la $a0,str6
syscall
# cin >> x;
li $v0,6
syscall
swc1 $f0,x
# vect2[i]=x;
move $t4,$t0
sll $t4,$t4,2
swc1 $f0,vect2($t4)
addi $t0,$t0,1
blt $t0,$t2,forsub2
jr $ra
I would like to know if the exercise as fixed goes well or you can do some improvement.