Example of C Calling a MASM Procedure

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:

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          : kb16bitonly kbLangC kbVC MASMLngIss 
Version           : 5.10 6.00 6.00a 6.00ax 7.00 | 5.
Platform          : MS-DOS OS/2 WINDOWS

Last Reviewed: July 20, 1997