; mcro.asm , renzo diomedi
;
%macro aver 3
mov eax, 0
mov ecx, dword [%2]   ;length
mov r12, 0
lea rbx, [%1]   ; load effective address of %1 in rbx
%%SumLoop:
add eax, dword [rbx+r12*4]   ; get list[n]
inc r12
loop %%SumLoop
cdq     ; convert a doubleword in a quadword EDX:EAX
idiv dword [%2]
mov dword [%3], eax
%endmacro
;
section .data    ; define constants
DI_0 equ 0
SYS_exit equ 60
;
section .data    ; define variables 
list0 dd 4, 5, 2, -3, 1
len0 dd 5
aver0 dd 0
list1 dd 2, 6, 3, -2, 1, 8, 19
len1 dd 7
aver1 dd 0
;
;
section .text
global _start
_start:
aver list0, len0, aver0
aver list1, len1, aver1
_FINE:
mov rax, SYS_exit
mov rdi, DI_0
syscall
