; sumave.asm
; Data declarations
; Note, none needed for this example.
; If needed, they would be declared here as always.
section .data
; **********************************************************
section .text
; --------------------------------------------------
; Function to find integer sum and integer average
; for a passed list of signed integers.
;
;Call: callee0x0(lst, len, &sum, &ave);
;
;
;
;
;Arguments Passed:
; 1) rdi - address of array
; 2) rsi - length of passed array
; 3) rdx - address of variable for sum
; 4) rcx - address of variable for average
;
;
;Returns:
; sum of integers (via reference)
; average of integers (via reference)
global sumave
sumave:
push r12
; -----
; Find and return sum.
mov r11, 0   ; i=0
mov r12d, 0  ; sum=0
sumLoop:
mov eax, dword [rdi+r11*4] 
add r12d, eax
inc r11
cmp r11, rsi
jb sumLoop;    get lst[i]
mov dword [rdx], r12d    ; return sum
; -----
; Find and return average.
mov eax, r12d
cdq
idiv esi
mov dword [rcx], eax
pop r12
ret
