Data in the Object Module

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.

Listing 1.7: The module containing the ALT variable used in another module, PROG1.ASM
image from book
 .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 
image from book
 
Listing 1.8: The module using the ALT variable defined in another module, PROG2.ASM
image from book
 .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 
image from book
 

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."



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net