Fortran/MASM Calling Conventions

You specify the calling convention for a MASM procedure in the PROTO and PROC directives. The STDCALL option in the PROTO and PROC directives tells the procedure to use the STDCALL calling convention. The C option in the PROTO and PROC directives tells the procedure to use the C calling convention. The USES option in the PROC directive specifies which registers to save and restore in the called MASM routine. The VARARG option to the PROTO and PROC directives specifies that the procedure allows a variable number of arguments.

For example, the following Fortran and MASM statements set up a MASM function that can be called from Visual Fortran, using the STDCALL calling convention:

 ! Fortran STDCALL interface prototype.
      INTERFACE
         INTEGER FUNCTION forfunc(I1, I2)
         !DEC$ ATTRIBUTES STDCALL :: forfunc
         INTEGER I1
         INTEGER(2) I2
      END INTERFACE
      WRITE (*,*) forfunc(I1,I2)
 ! End Fortran STDCALL interface 

 ;MASM STDCALL Prototype
          .MODEL FLAT, STDCALL
 forfunc PROTO STDCALL, forint: SDWORD, shorti: ptr SWORD
          .CODE
 forfunc PROC STDCALL, forint: SDWORD, shorti: ptr SWORD
          ...
 forfunc ENDP END

The following Fortran and MASM statements set up a Fortran-callable MASM function using the C calling convention:

 ! Fortran C interface prototype
      INTERFACE
         INTEGER FUNCTION Forfunc (I1, I2)
         !DEC$ ATTRIBUTES C, ALIAS:'Forfunc' :: Forfunc
         INTEGER I1
         INTEGER(2) I2
      END INTERFACE
      WRITE(*,*) Forfunc (I1, I2)
      END
 ! End Fortran C interface 
 
 ;MASM C PROTOTYPE
         .MODEL FLAT, C
  Forfunc PROTO C, forint:SDWORD, shorti: ptr SWORD
         .CODE
  Forfunc PROC C, forint:SDWORD, shorti: ptr SWORD
         ...
  Forfunc ENDP END