# fpa.asm
; rdi - address of array
; rsi - length of passed array
; rdx - address of variable for sum
; rcx - address of variable for average
section .note.GNU-stack 
section .data
section .text
global fpa
fpa:
push r12                      ;r12~rax , deprecable the use of r8 r9 r10   
mov r11, 0      ;i=0
mov r12d, 0      ;sum=0       ;low 32 bits of r12
sumLoop:
mov eax, dword[rdi+r11*4]     ;get arr[i]
add r12d, eax                 ;update sum in r12d
inc r11                       ;i++
cmp r11, rsi
jb sumLoop                    ;jump if r11<rsi
mov dword[rdx], r12d          ;return sum 
# find and return average
mov eax, r12d                
cdq                           ;conver dword eax in qword edx:eax
idiv esi
mov dword[rcx], eax           ;return average
pop r12
ret

