| ||
Now, it is time to consider an important aspect of using data ( variables ) defined in another object module. Here, everything will be clear if you have carefully read the preceding material. The PROG2.ASM and PROG1.ASM modules demonstrating the technique of using external variables [i] are provided in Listings 1.7 and 1.8.
.586P ; The PROG2.ASM module ; Flat memory model .MODEL FLAT, STDCALL PUBLIC PROC1 PUBLIC ALT ; Data segment _DATA SEGMENT ALT DWORD 0 _DATA ENDS _TEXT SEGMENT PROC1 PROC MOV EAX, ALT ADD EAX, 10 RET PROC1 ENDP _TEXT ENDS END
.586P ; The PROG1.ASM ; Flat memory model .MODEL FLAT, STDCALL ;------------------------------------------ ; Prototype of the external procedure EXTERN PROC1@0:NEAR ; External variable EXTERN ALT:DWORD ; Data segment _DATA SEGMENT _DATA ENDS ; Code segment _TEXT SEGMENT START: MOV ALT, 10 CALL PROC1@0 MOV EAX, ALT RET ; Exit _TEXT ENDS END START
Note that in contrast to external procedures, external variables don't require the suffix @N because the variable size is known.
[i] The term "external variable" is used by analogy with the term "external procedure."
| ||