; Program that demonstrates C-style procedure call and definition.
; Procedure parameters are declared as pointers to data.
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
.DATA ; reserve storage for data
number1 DWORD ?
number2 DWORD ?
.CODE ; start of main program code
_start:
mov number1, 10 ; Load data
mov number2, 20
push offset number2 ; Push second argument
push offset number1 ; Push first argument
call add2nums ; push address of next instruction
; onto the stack, and pass control
; to the address of add2nums
add sp, 8 ; Destroy the pushed arguments
; (equivalent to two pops)
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
add2nums PROC NEAR32 C arg1:NEAR32 PTR DWORD, arg2:NEAR32 PTR DWORD
mov ebx, arg1 ; get address of the 1st parameter
mov eax, [ebx] ; get the value
mov ebx, arg2 ; get address of the 2nd parameter
add eax, [ebx] ; compute sum
ret ; return result in EAX
add2nums ENDP
END ; end of source code