; fp_sabso.asm

; rdi - address of array
; rsi - length of passed array
; rdx - address of variable for sum
; rcx - address of variable for average

section .data
posi dd -1

section .text
global fp_sabso
fp_sabso:

push r12 
push rbx       
mov r11, 0      ;i=0
mov r12d, 0      ;sum=0

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 eax, r12d                 ;sum in eax

cmp eax, 0
jl Posit

Posit:
cdq
imul dword[posi]

mov ebx, eax 
mov dword[rcx], ebx 

fine: 
pop rbx
pop r12
ret

