The EXTERN directive specifies a declaration for the external symbol Name so that it may be referred to within this module. The actual definition for the symbol occurs in some other module, and the linker resolves all such external declarations to a single definition for Name.
Syntax
EXTERN [Language-Name] Name [(Default-Resolution)] :Type [, ...]
Where Type is one of:
The obsolete spelling for the EXTERN directive is EXTRN.
The external source module that defines the symbol must give it public visibility in the corresponding object module, which is accomplished in assembler language by declaring it with the COMM directive, defining the symbol in association with an EXTERNDEF or PUBLIC directive, or by specifying the PUBLIC or EXPORT attributes in a PROC directive.
If the EXTERN directive is given within a segment, the assembler assumes that the symbol is located within that segment. If the segment is not known, place the EXTERN directive outside all segments and either use an explicit segment prefix or an ASSUME directive.
A Type value of ABS indicates that Name is an externally-defined constant value. Local references to Name are treated as immediate values having an Operand Size equal to the Address Size of the segment containing the reference.
Note: If the Type of EXTERN is ABS, it may not be used anywhere in this module where conversion to an immediate value of type BYTE is required. Additionally, the defining module must define the value as a constant symbol.
For example:
FOO EQU 5 PUBLIC FOO
Use of the (default_resolution) syntax declares the external symbol Name to be a "weak" symbol, in which case the linker will pair all such declarations with the symbol default_resolution unless a standard "strong" public definition for Name is encountered during the link. Example
┌───────────────────────────────────┬───────────────────────────────────┐ │IN THE SAME SEGMENT │IN ANOTHER SEGMENT │ ├───────────────────────────────────┼───────────────────────────────────┤ │IN MODULE 1: │IN MODULE 1: │ │ │ │ │cseg segment │csega segment │ │public tagn │public tagf │ │. │. │ │. │. │ │. │. │ │tagn: │tagf: │ │. │. │ │. │. │ │. │. │ │cseg ends │csega ends │ │ │ │ │IN MODULE 2: │IN MODULE 2: │ │ │ │ │cseg segment │extern tagf:far │ │extern tagn:near │csegb segment │ │. │. │ │. │. │ │. │. │ │jmp tagn │jmp tagf │ │cseg ends │csegb ends │ └───────────────────────────────────┴───────────────────────────────────┘