Symbols can be defined in one module and referred to in another, which results in symbolic linkages between independently assembled program sections. These linkages can be made only if the assembler can provide information about the linkage symbols to the linker, which resolves the linkage references at link-edit time.
You must establish symbolic linkage between source modules so that you can refer to or branch to symbolic locations defined in the control sections of external source modules. You do this by using external symbol definitions, and external symbol references. To establish symbolic linkage with an external source module, you must do the following:
The assembler places information about entry and external symbols in the external symbol dictionary. The linker uses this information to resolve the linkage addresses identified by the entry and external symbols.
Use the EXTRN instruction to identify the external symbol that represents data in an external source module, if you want to refer to this data symbolically.
For example, you can identify the address of a data area as an external symbol and load the A-type address constant specifying this symbol into a base register. Then, you use this base register when establishing the addressability of a dummy section that describes this external data. You can now refer symbolically to the data that the external area contains.
You must also identify, in the source module that contains the data area, the address of the data as an entry symbol.
Use the V-type address constant to identify the external symbol that represents the address in an external source module that you want to branch to.
For example, you can load into a register the V-type address constant that identifies the external symbol. Using this register, you can then branch to the external address represented by the symbol.
If the symbol is the name entry of a START, CSECT, or RSECT instruction in the other source module, and thus names an executable control section, it is automatically identified as an entry symbol. If the symbol represents an address in the middle of a control section, you must identify it as an entry symbol for the external source module.
You can also use a combination of an EXTRN instruction to identify, and an A-type address constant to contain, the external branch address. However, the V-type address constant is more convenient because:
The following example shows how you use an A-type address constant to contain the address of an external symbol that you identify in an EXTRN instruction. You cannot use the external symbol name EXMOD1 in the name entry of any other statement in the source program.
.
.
L 15,EX_SYM Load address of external symbol
BASR 14,15 Branch to it
.
.
EX_SYM DC A(EXMOD1) Address of external symbol
EXTRN EXMOD1 Identify EXMOD1 as external symbol
.
.
The following example shows how you use the symbol EXMOD1 as both the name of an external symbol and a name entry on another statement.
.
.
L 15,EX_SYM Load address of external symbol
BASR 14,15 Branch to it
.
.
EXMOD1 DS 0H Using EXMOD1 as a name entry
.
.
EX_SYM DC V(EXMOD1) Address of external symbol
.
.
If the external symbol that represents the address to which you want to branch is to be part of an overlay-structured module, you should identify it with a V-type address constant, not with an EXTRN instruction and an A-type address constant. You can use the supervisor CALL macro instruction to branch to the address represented by the external symbol. The CALL macro instruction generates the necessary V-type address constant.
You may branch to external symbols in the same class using relative branch instructions.
MYPROG CSECT , Define section MYPROG
CLASS_A CATTR RMODE(31) Define class CLASS_A
- - -
BRAS 14,ENTRYB Branch to external symbol
- - -
HISPROG CSECT , Define section HISPROG
CLASS_A CATTR RMODE(31) Define class CLASS_A
- - -
ENTRYB STM 14,12,12(13) Entry point referenced externally
- - -
END
You may also use a relative branch instruction to branch to an externally defined symbol:
MYPROG CSECT , Define section MYPROG
MYCLASS CATTR RMODE(31) Define class MYCLASS
EXTRN TARGET Declare external symbol TARGET
- - -
BRAS 14,TARGET Branch to external symbol
- - -
END
A separate source module must define the entry point TARGET in class MYCLASS.
You can instruct the assembler to use an alias for an external symbol in place of the external symbol itself, when it generates the object module. To do this you must code an ALIAS instruction which specifies the external symbol and the alias you want the assembler to use. The external symbol must be defined in a START, CSECT, RSECT, ENTRY, COM, DXD, external DSECT, EXTRN, or WXTRN instruction, or in a V-type address constant.
The following example shows how you use the ALIAS instruction to specify an alias for the external symbol EXMOD1.
.
.
L 15,EX_SYM Load address of external symbol
BASR 14,15 Branch to it
.
.
EXMOD1 DS 0H Using EXMOD1 as a name entry
.
.
EX_SYM DC V(EXMOD1) Address of external symbol
EXMOD1 ALIAS C'XMD1PGM' XMD1PGM is the real external name
.
.
See ALIAS instruction for information about the ALIAS instruction.
[ Top of Page | Previous Page | Next Page | Contents | Index ]