; Program that demonstrates C-style procedure manipulating
; C-like local variables on the stack.

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

.CODE                           ; start of main program code
_start:
        mov     eax, 10         ; Load data into EAX
        push    eax             ; Push first argument
        call    subtract3       ; push address of next instruction
                                ; onto the stack, and pass control
                                ; to the address of subtract3
        add     sp, 4           ; Destroy the pushed arguments
                                ; (equivalent to one pop)
        INVOKE  ExitProcess, 0  ; exit with return code 0

PUBLIC _start                   ; make entry point public

subtract3 PROC NEAR32
        push    ebp             ; Save base pointer
        mov     ebp, esp        ; Load stack into base pointer
        sub     esp, 4          ; Save 2 bytes for a local variable
        
        mov     DWORD PTR [ ebp - 4 ], 6 ; Initialize local variable with 6
        mov     eax, [ ebp - 4 ]         ; put value in EAX
        sub     [ ebp + 8 ], eax         ; Subtract value from the 1st argument
        mov     eax, [ ebp + 8 ]         ; put result in EAX
        
        mov     esp, ebp        ; Clear local variables
        pop     ebp             ; Restore EBP
        ret                     ; Return result in EAX
subtract3 ENDP

END                             ; end of source code