;suav.asm
;
section .data
section .text
;
;  call: suav(arr3, len, &somma, &media)
;  arguments passed:
;  rdi = address of array 
;  rsi = length of passed array 
;  rdx = address of variable for sum 
;  rcx = address of variable for average 
;
global suav
suav:
;
push qword[r8] 
mov r9, 0                      ;i=0
mov qword[r8], 0                      
;
sumLoop:
movsd xmm0, qword[rdi+r9*8]    ;get arr3[i]
movsd qword[r8], xmm0
addsd xmm1, qword[r8]           
inc r11                         ;i++
cmp r11, rsi
jb sumLoop                      ;jump if r11<rsi
movsd qword[rdx], xmm1          ;return the sum 
;
movsd xmm2, qword[rsi]               
divsd xmm1, xmm2 
movsd qword[rcx], xmm1          ;return average
;
pop qword[r8]
ret

