### Passing Conforming Parameters to a Prototyped Routine

The following example shows the code sequences and a picture of the stack for a call to the function `foo`:

       long foo(char p1, short p2, long p3, long p4);

       short x;
       long y;

       y = foo('A', x, y+x, y);

Caller's code surrounding call:

       PUSH     y           ; Push p4 onto the run-time stack
       SUB      ESP, 12     ; Allocate stack space for
                            ;  register parameters
       MOV      AL, 'A'     ; Put p1 into AL
       MOV      DX,  x      ; Put p2 into DX
       MOVSX    ECX, DX     ; Sign-extend x to long
       ADD      ECX, y      ; Calculate p3 and put it into ECX
       CALL     FOO         ; Make call

Callee's prolog code:

       PUSH     EBP                      ; Save caller's EBP
       MOV      EBP, ESP                 ; Set up callee's EBP
       SUB      ESP, callee's local size ; Allocate callee's Local
       PUSH     EBX                      ; Save preserved registers -
       PUSH     EDI                      ;  will optimize to save
       PUSH     ESI                      ;  only registers callee uses

Note: The term undefined in registers EBX, EDI, and ESI refers to the fact that they can be safely overwritten by the code in `foo`.

Callee's epilog code:

       MOV       EAX, RetVal ; Put return value in EAX
       POP       ESI         ; Restore preserved registers
       POP       EDI
       POP       EBX
       MOV       ESP, EBP    ; Deallocate callee's local
       POP       EBP         ; Restore caller's EBP
       RET                   ; Return to caller

Caller's code just after call:

       ADD      ESP, 16      ; Remove parameters from stack
       MOV      y,   EAX     ; Use return value.

Calling Conventions

Examples of Passing Parameters Using _Optlink