There is a segmentation fault when I am calling the printf function from function, but it works perfectly fine when being called from the main:
CODE:
extern printf
SECTION .data
msg: db "Hello", 0 ; Zero is Null terminator
fmt: db "%lf", 10, 0 ; printf format string follow by a newline(10) and a null terminator(0), "\n",'0'
d1: dq 13.0
d2: dq 15.0
result : dq 0
SECTION .text
global main
main:
push rbp ; Push stack
; mov rdi,fmt ; set the format for print
; mov rsi,msg ; set first parameter
; mov rax,1 ; one floating point
; movq xmm0, [d1]
; call printf
call get_input
pop rbp ; Pop stack
mov rax,0 ; Exit code 0
ret ; Return
get_input:
mov rdi,fmt ; set the format for print
mov rsi,msg ; set first parameter
mov rax,1 ; one floating point
movq xmm0, [d1]
call printf
ret
MAKE FILE:
nasm -g -f elf64 -F dwarf printf.s -o printf.o
gcc -g -Wall -o printf printf.o