; exnl8.asm example call funstions and procedures in another file extern printf extern jprt ; in exnl8f.asm extern diff extern ssq section .data ; Data section, initialized variables msg: db "nasm exnl8.asm running", 0 ; C string needs 0 msg2: db "exnl8.asm finished", 0 fmt: db "%s", 10, 0 fmti db "diff = %d", 10, 0 fmtf: db "ssq = %f", 10, 0 af: dq 1.1 bf: dq 3.3 ai: dq 13 bi: dq 27 section .bss ; variable and array section cf: resq 1 ci: resq 1 tmp: resq 1 section .text ; Code section. global main main: push rbp ; set up stack frame, must be aligned mov rdi,fmt ; address of format, required register rdi mov rsi,msg ; address of data mov rax,0 ; or can be xor rax,rax call printf ; Call C function call jprt ; call no parameter procedure mov rdi,[ai] ; first integer parameter value mov rsi,[bi] ; second integer paramenter value call diff ; function return in rax mov [tmp],rax ; save result and print result using macro ; print mov rdi, fmti ; address of format string mov rsi, [tmp] ; int value mov rax, 0 ; 0 floating point arguments to printf call printf ; Call C function movq xmm0, qword[af] ; first double parameter value movq xmm1, qword[bf] ; second double parameter value call ssq ; function return in xmm2 movq qword[tmp], xmm2 ; save result and print result ; print mov rdi, fmtf ; address of format string movq xmm0, qword[tmp] ; first floating point in fmt mov rax, 1 ; 1 floating point arguments to printf call printf ; Call C function mov rdi,fmt mov rsi,msg2 mov rax,0 call printf pop rbp ; restore stack mov rax,0 ; normal, no error, return value ret ; return ; function definitions in file exnl8f.asm