Microsoft KB Archive/39309

From BetaArchive Wiki

Example of C Calling a MASM Procedure

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 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
Issue type :
Technology : kbVCsearch kbAudDeveloper kbPTProdChange kbvc150 kbvc100 kbCCompSearch kbZNotKeyword3 kbCComp510DOS kbCComp600DOS kbCComp600aDOS kbCComp600axDOS kbCComp510OS2 kbCComp600OS2 kbCComp600aOS2 kbCVC700DOS


Last Reviewed: May 6, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.