; intfunc.asm call integer function int sum(int x, int y) ; ; compile: nasm -f elf intfunc.asm ; link: gcc -o intfunc.o ; run: intfunc ; result: 5 = sum(2,3) extern printf section .data x: dd 2 y: dd 3 z: dd 1 fmt: db "%d = sum(%d,%d)",10,0 global main main: push ebp mov ebp,esp push ebx push dword [y] ; push arguments for sum push dword [x] call sum ; coded below add esp,8 mov [z],eax ; save result from sum push dword [y] ; print push dword [x] push dword [z] push dword fmt call printf add esp,16 pop ebx mov esp,ebp pop ebp mov eax,0 ret ; end main sum: push ebp ; function int sum(int x, int y) mov ebp,esp push ebx mov eax,[ebp+8] ; get argument x mov ebx,[ebp+12] ; get argument y add eax,ebx ; x+y with result in eax pop ebx mov esp,ebp pop ebp ret ; return value in eax ; end of function int sum(int x, int y)