Microsoft KB Archive/76504

= Static Variables Declared in MASM Routines Called from C =

Article ID: 76504

Article Last Modified on 10/16/2003

-

APPLIES TO


 * Microsoft Macro Assembler 5.0
 * Microsoft Macro Assembler 6.0 Standard Edition
 * Microsoft Macro Assembler 6.0a
 * Microsoft Macro Assembler 6.0b

-



This article was previously published under Q76504



SUMMARY
The programs below demonstrate how a variable declared in a Microsoft Macro Assembler (MASM) subprogram will keep its value between calls from a C main program.



MORE INFORMATION
Link the two programs below with the following command:   link cmain masmsub,,, /nod llibce;

Sample Code #1
// Filename: CMAIN.C // Compile options needed: /c /AL


 * 1) include 

extern int far MasmSub ;

main {  int i ; for (i = 1; i < 11; ++i)         // Call the MASM subprogram 10 {                                // times, and its return value printf (&quot;%d\n&quot;, MasmSub) ;  // will be incremented by 1 each }                                // time. }

Sample Code #2
; Filename: MASMSUB.ASM
 * Assemble options needed: /mx /ml

.MODEL LARGE, C .DATA var DW 0       ; This variable will keeps its value between calls. .CODE PUBLIC MasmSub MasmSub PROC FAR INC var MOV AX, var    ; Since the function returns an int, C will get the RET            ; return value from AX. MasmSub ENDP END

Additional query words: kbinf 5.00 5.10 6.00

Keywords: KB76504

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.