; intfunct_64.asm this is a main and a function in one file ; call integer function long int sum(long int x, long int y) ; compile: nasm -f elf64 -l intfunct_64.lst intfunct_64.asm ; link: gcc -m64 -o intfunct_64 intfunct_64.o ; run: ./intfunct_64 > intfunct_64.out ; view: cat intfunct_64.out ; result: 5 = sum(2,3) extern printf section .data x: dq 2 y: dq 3 fmt: db "%ld = sum(%ld,%ld)",10,0 section .bss z: resq 1 section .text global main main: push rbp ; set up stack mov rdi, [x] ; pass arguments for sum mov rsi, [y] call sum ; coded below mov [z],rax ; save result from sum mov rdi, fmt ; print mov rsi, [z] mov rdx, [x] ; yes, rdx comes before rcx mov rcx, [y] mov rax, 0 ; no float or double call printf pop rbp ; restore stack mov rax,0 ret ; end main sum: ; function long int sum(long int x, long int y) ; so simple, do not need to save anything mov rax,rdi ; get argument x add rax,rsi ; add argument y, x+y result in rax ret ; return value in rax ; end of function sum ; end intfunct_64.asm