The following example tries to demonstrate how a function can be created with masm and then be called from a C program.
This example needs to be compiled on a x86 (not a x64) environment.
add_3.asm
func.asm defines a function, named _add_3 that adds the first three parameters (arguments) and returns it via the eaxregister.
.model flat
; PUBLIC _add_3
_TEXT SEGMENT
_add_3 PROC
push ebp
mov ebp, esp
mov eax, DWORD PTR 8[ebp] ; The 1st argument is ebp + 8
add eax, DWORD PTR 12[ebp] ; The 2nd argument is ebp + 12
add eax, DWORD PTR 16[ebp] ; The 3rd argument is ebp + 16
pop ebp
ret 0
_add_3 ENDP
_TEXT ENDS
END ; END directive required at end of file