I changed your program a little bit so that you can take both formats from the command prompt
; -----------------------------------------------------------------------------
; 64-bit program that treats all its command line arguments as floating point
; number and displays their average as a floating point number. This program
; uses a data section to store intermediate results, not that it has to, but
; only to illustrate how data sections are used.
; -----------------------------------------------------------------------------
global main
extern atof
extern printf
section .data
count: dq 0
sum: dq 0
format: db "%g", 10, 0
error: db "There are no cmds to average", 10, 0
section .text
main:
sub rsp,8
dec rdi ;argc-1, da wir den programm namen ignorieren
jz nothingToAverage ;wenn rdi == 0
mov [count], rdi ;speichere args in [count]
pxor xmm8,xmm8
accumulate:
push rdi ;sichere reg vor atoi aufruf
push rsi
mov rdi, [rsi+rdi*8] ;argv[rdi] c alignment beachten!
call atof ;rax enthält den wert von arg
pop rsi ;wiederherstellen der reg nach
pop rdi ;aufruf von atoi
addpd xmm8,xmm0 ;summieren der werte
dec rdi ;argc runterzählen
jnz accumulate ;wiederhole wen argc != 0
average:
movq xmm0,xmm8
movq xmm1,[count]
cvtsi2sd xmm1,[count]
divsd xmm0, xmm1
mov rdi, format ;erste arg für printf
mov rax, 1 ;printf hat var args es gibt 1 nicht
call printf ;printf(format, sum/count)
add rsp, 8 ;wiederherstellen des stackpointers
ret
nothingToAverage:
mov rdi, error
xor rax, rax
call printf
add rsp,8
ret
I hope this is what you want. This is using ATOF though