Example of C Calling a MASM Procedure

Last reviewed: July 17, 1997
Article ID: Q39309
5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a | 1.00 1.50
MS-DOS                      | OS/2            | WINDOWS
kbprg

The information in this article applies to:

  • Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
  • Microsoft C for OS/2, versions 5.1, 6.0, and 6.0a
  • Microsoft C/C++ for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SUMMARY

The sample code below demonstrates a C program calling a MASM procedure. The C code declares an integer and passes the integer to the MASM procedure called mixed(). The mixed() function has an integer return value.

MORE INFORMATION

Sample Code 1

/* Code for the calling C function.
 *
 * Compile options needed: /c /AL
 */

#include <stdio.h>

int retval, value, myvar;
extern int mixed( int );

main() {

    value = 35;
    myvar = 25;
    retval = 0;

    retval = mixed( myvar );
    printf( "%d\n%d\n", retval, value );
}

Sample Code 2

; Code for the called assembly procedure ; ; Assemble options needed: /c /Cx (MASM 6.0 and later)

;                          /Mx  (MASM 5.10 and eariler)

DOSSEG

.MODEL LARGE, C

.STACK 100h

.DATA

    Dw 0

.FARDATA
    EXTRN value:WORD

.CODE
    PUBLIC mixed
    mixed PROC

      push  bp
      mov   bp,sp

      ; access and change value

      mov   ax, SEG _DATA
      push  ds
      mov   ds, ax
      mov   ax, SEG value
      mov   es, ax
      mov   es:value, 10h

      ; return the passed variable

      mov   ax, [bp+6]
      pop   ds
      pop   bp
      ret

    mixed ENDP
END


Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
KBCategory: kbprg
KBSubcategory: CLngIss MASMLngIss
Keywords : CLngIss kb16bitonly MASMLngIss kbprg
Version : 5.10 6.00 6.00a 6.00ax 7.00 | 5.
Platform : MS-DOS OS/2 WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.