Look at this assembler code. It is designed for 32 bits x86 and will be compiled by nasm
...
my_function:
pop %eax
...
ret
See below for explanation:-
[BITS 32]
%include "nagoa+.inc"
%include "cfunctions.txt"
[SEGMENT .DATA USE32]
ret_value db "I am the Return Value",0
localvar db "My Local Variable Value",0
[SEGMENT .BSS USE32]
arg_param resb 160
[SEGMENT .TEXT USE32]
my_function:
;save arguments/parameters as this esp+ space will be destroyed by system function calls
mov eax,[esp+4]
;enjoy local variables for processing
;enter 4,0
mov dword [esp-4],localvar
call printf,`Argument/Parmeter=%s and Local Variable=%s`,eax,[esp-4]
add esp,12
;leave
;fill-up return values
mov eax,ret_value
ret
;ret 4
..start:
call puts,`Enter Argument/Parmeter`
add esp,4
call gets,arg_param
add esp,4
push arg_param
CALL my_function
call printf,`Return Value From Called Function=%s`,eax
add esp,4
call exit, 0