Hello, this sample code use macro for simplify the using of printf, i hope it's help you:
32_ dd 32.0
;==========================================================================
; printf_
;==========================================================================
; %0 = number of parameters received
; %1 = 1st parameter received
%macro printf_ 1-*
%assign i 0
[section .data use64]
%%str db %1, 10, 0
[section .code use64]
sub rsp, 32
mov rcx, %%str ; printf.string
%if %0 >= 2
mov rdx, %2 ; printf.1st element
%endif
%if %0 >= 3
mov r8, %3 ; printf.2nd element
%endif
%if %0 >= 4
mov r9, %4 ; printf.3nd element
%endif
%if %0 >= 5
sub rsp, ((%0 - 4) * 8) + 8 ; ((nbr_param - 4(param_nostack)) * 8(byte)) + 8(fill_last_element)
%rep (%0 - 4) ; Reapet block of code until all element are store in stack
mov rax, %5 ; Begin loop by 5th element.
mov [rsp + (32 + (i * 8))], rax
%assign i (i + 1)
%rotate 1 ; Rotate element right to left for scanning all element parsing in macro.
%endrep
add rsp, ((%0 - 4) * 8) + 8
%endif
call printf
add rsp, 32
%endmacro
;==========================================================================
; /printf_
;==========================================================================
;==========================================================================
; puts_
;==========================================================================
; %0 = number of parameters received
; %1 = 1st parameter received
%macro puts_ 1-*
[section .data use64]
%%str db %1, 10, 0
[section .code use64]
sub rsp, 32
mov rcx, %%str ; puts.string
call puts
add rsp, 32
%endmacro
;==========================================================================
; /puts_
;==========================================================================
vcvtss2sd xmm0, [32_] ; float32 -> float64
vmovq rax, xmm0
printf_ "float = %f", rax
printf_ "int = %d", 52
puts_ "blabla"
This macro allow to pass multiple parameters:
printf_ "blabla", ..., ...
Enjoy
PS: for understand those macro system, read
http://www.nasm.us/doc/nasmdoc4.html#section-4.1.7.