Home | | Microprocessors and Microcontrollers | 8086 Microprocessor Linking and Relocation

Chapter: Microprocessor and Microcontroller - 8086 Microprocessor

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

8086 Microprocessor Linking and Relocation

The DOS linking program links the different object modules of a source program and function library routines to generate an integrated executable code of the source program.

 

Linking And Relocation

 

The DOS linking program links the different object modules of a source program and function library routines to generate an integrated executable code of the source program. The main input to the linker is the .OBJ file that contains the object modules of the source programs. Other supporting information may be obtained from the files generated by the MASM. The linker program is invoked using the following options.

 

C> LINK or

 

C>LINK MS.OBJ

 

The .OBJ extension is a must for a file to be accepted by the LINK as a valid object file. The first object may generate a display asking for the object file, list file and libraries as inputs and an expected name of the .EXE file to be generated. The output of the link program is an executable file with the entered filename and .EXE extension. This executable filename can further be entered at the DOS prompt to execute the file.

 

In the advanced version of the MASM, the complete procedure of assembling and linking is combined under a single menu invokable compile function. The recent versions of MASM have much more sophisticated and user-friendly facilities and options. A linker links the machine codes with the other required assembled codes. Linking is necessary because of the number of codes to be linked for the final binary file.

 

The linked file in binary for run on a computer is commonly known as executable file or simply ‘.exe.’ file. After linking, there has to be re-allocation of the sequences of

placing the codes before actually placement of the codes in the memory.

 

The loader program performs the task of reallocating the codes after finding the physical RAM addresses available at a given instant. The DOS linking program links the different object modules of a source program and function library routines to generate an integrated executable code of the source program. The main input to the linker is the .OBJ file that contains the object modules of the source programs. Other supporting information

 

may be obtained from the files generated by the MASM. The linked file in binary for run on a computer is commonly known as executable file or simply ‘.exe.’ file. After linking, there

 

has to be re-allocation of the sequences of placing the codes before actually placement of the codes in the memory.

 

The loader program performs the task of reallocating the codes after finding the

 

physical RAM addresses available at a given instant. The loader is a part of the operating system and places codes into the memory after reading the ‘.exe’ file. This step is necessary

 

because the available memory addresses may not start from 0x0000, and binary codes have to be loaded at the different addresses during the run. The loader finds the appropriate start address. In a computer, the loader is used and it loads into a section of RAM the program that is ready to run. A program called locator reallocates the linked file and creates a file for permanent location of codes in a standard format.

 

Segment combination

 

In addition to the linker commands, the assembler provides a means of regulating the way segments in

 

different object modules are organized by the linker.

 

Segments with same name are joined together by using the modifiers attached to the SEGMENT directives. SEGMENT directive may have the form

 

Segment name SEGMENT Combination-type

 

where the combine-type indicates how the segment is to be located within the load module. Segments that have different names cannot be combined and segments with the same name but no combine-type will cause a linker error. The possible combine-types are:

 

ü PUBLIC – If the segments in different modules have the same name and combine-type PUBLIC, then they are concatenated into a single element in the load module. The ordering in the concatenation is specified by the linker command.

 

ü COMMON – If the segments in different object modules have the same name and the combine-type is COMMON, then they are overlaid so that they have the same starting address. The length of the common segment is that of the longest segment being overlaid.

ü STACK – If segments in different object modules have the same name and the combine type

 

STACK, then they become one segment whose length is the sum of the lengths of the individually specified segments. In effect, they are combined to form one large stack

ü AT The AT combine-type is followed by an expression that evaluates to a constant which is to be the segment address. It allows the user to specify the exact location of the segment in memory.

 

MEMORY This combine-type causes the segment to be placed at the last of the load module. If more than one segment with the MEMORY combine-type is being linked, only the first one will be treated as having the MEMORY combine type; the others will be overlaid as if they had COMMON combine-type.



Fig. 1.9 Segment combinations resulting from the PUBLIC and Common Combination types


 

Access to External Identifiers

 

If an identifier is defined in an object module, then it is said to be a local (or internal) identifier relative to the module. If it is not defined in the module but is defined in one of the other modules being linked, then it is referred to as an external (or global) identifier relative to the module. In order to permit other object modules to reference some of the identifiers in a given module, the given module must include a list of the identifiers to which it will allow access. Therefore, each module in multi-module programs may contain two lists, one containing the external identifiers that can be referred to by other modules. Two lists are implemented by the EXTRN and PUBLIC directives, which have the forms:


where the identifiers are the variables and labels being declared or as being available to other modules.

 

The assembler must know the type of all external identifiers before it can generate the proper machine code, a type specifier must be associated with each identifier in an EXTRN statement. For a variable the type may be BYTE, WORD, or DWORD and for a label it may be NEAR or FAR.

 

ü One of the primary tasks of the linker is to verify that every identifier appearing in an EXTRN statement is matched by one in a PUBLIC statement. If this is not the case, then there will be an undefined reference and a linker error will occur. The offsets for the local identifier will be inserted by the assembler, but the offsets for the external identifiers and all segment addresses must be inserted by the linking process. The offsets associated with all external references can be assigned once all of the object modules have been found and their external symbol tables have been examined. The assignment of the segment addresses is called relocation and is done after the linking process has determined exactly where each segment is to be put in memory.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.