### Passing Floating-Point Parameters to a Prototyped Routine

The following example shows code sequences, run-time stack layouts, and floating-point register stack states for a call to the routine `fred`. For simplicity, the general-purpose registers are not shown.

       double fred(float p1, double p2, long double p3, float p4, double p5);

       double a, b, c;
       float  d, e;

       a = b + fred(a, d, (long double)(a + c), e, c);

Caller's code up until call:

       PUSH    2ND DWORD OF c       ; Push upper 4 bytes of c onto stack
       PUSH    1ST DWORD OF c       ; Push lower 4 bytes of c onto stack
       FLD     DWORD_PTR e          ; Load e into 80387, promotion
                                    ;  requires no conversion code
       FLD     QWORD_PTR a          ; Load a to calculate p3
       FADD    ST(0), QWORD_PTR c   ; Calculate p3, result is long double
                                    ;  from nature of 80387 hardware
       FLD     DWORD_PTR d          ; Load d, no conversion necessary
       FLD     QWORD_PTR a          ; Load a, demotion requires conversion
       FSTP    DWORD_PTR [EBP - T1] ; Store to a temp (T1) to convert to float
       FLD     DWORD_PTR [EBP - T1] ; Load converted value from temp (T1)
       SUB     ESP, 32              ; Allocate the stack space for
                                    ;  parameter list
       CALL    FRED                 ; 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

Callee's epilog code:

       FLD       RETVAL      ; Load return value onto floating-point stack
       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, 40      ; Remove parameters from stack
       FADD     QWORD_PTR b  ; Use return value
       FSTP     QWORD_PTR a  ; Store expression to variable a

Calling Conventions

Examples of Passing Parameters Using _Optlink