# fpa64.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 fpa64
fpa64:
push r12                      ;r12~rax , deprecable the use of r8 r9 r10   
mov r11, 0      ;i=0
mov r12, 0      ;sum=0       ;low 32 bits of r12
sumLoop:
mov rax, qword[rdi+r11*8]     ;get arr[i]
add r12, rax                 ;update sum in r12d
inc r11                       ;i++
cmp r11, rsi
jb sumLoop                    ;jump if r11<rsi
mov qword[rdx], r12         ;return sum 

# find and return average
mov rax, r12               
cqo                           ;conver dword eax in qword edx:eax
idiv rsi
mov qword[rcx], rax           ;return average
pop r12
ret

