Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Presented by: Dhriti Das (roll no-07) Simsima Gogoi (roll no-17) Tanmi Bharadwaj (roll no-18)

What is MS-DOS linker?


 Basically in MS-DOS compilers and assemblers object

modules are created instead of executable machine language programs.

 MS- DOS linker is a linkage editor that combines one

or more object modules to produce a complete executable program.

 This executable module has the file name extension

.exe .

Object module format:


There are total of 8 object records types corresponding to the following categories of informations:
 Binary image  External references  Public definations

 Each object record contains variable length

information and may refer to the contents of previous object records . It must appear in a specific order as shown belowRECORD TYPE THEADR LNAMES SEGDEF EXTDEF PUBDEF LEDATA FIXUPP MODEND Id (Hex) 8O 96 98 8C 9O AO 9C 8A DESCRIPTION Translator header record List of names record Segment defination record External names defination record Public names defination record Translated data (binary image) Relocation & linking information End of object module record

THEADR records
 The THEADR record specifies the name of the object

module.  It is derived by the translator from the source file.  This name is used by the linker to report errors.
8O H length T-module name Check-sum

LNAMES records
 The LNAMES record lists the names for use by

SEGDEF record.

96 H

length

Name list

Check-sum

SEGDFEF records
 SEGDEF records describe the segments in the

object module , including their name, length and alignment.  It designates a segment name using an index into NAMELIST of LNAMES record.  The attributes field indicates whether the segment is relocatable or absolute, alignment specification and other details. It also contains the origin specification for an absolute segment.
98 H

length

Attributes Segment Name Check(1-4) length index ( 1) sum (2)

EXTDEF records
 The EXTDEF record contains a list of the external

references used by the programs of this module.

8CH

length

External reference list

Check-sum

PUBDEF records
 The PUBDEF record contains a list of the external

symbols (called public names) that are declared in a segment of the object module.
9O H Length

Base name Offset (2-4) (2)

Check sum

Identifies the segment


Each (name, offset) pair defines one public name. Specifies the name of the symbol. Specifies its offset within the segment identified by the base specification.

LEDATA records
 LEDATA records contains translated instructions and

data from the source program.


AO H length Segment index (1-2) Data offset (2) Data Check sum

Identifies the segment to which the code belongs

Specifies the location of the code within the segment

FIXUPP records
 FIXUPP records are used to resolve external references,

and to perform address modification that are associated with relocation.


9CH length locat Fix (1) dat (1) Frame datum (1) Target datum (1) Target offset (1) Check sum

 Locat field: it contains a numeric code called loc code

to indicate the type of a fixup.


Loc code 0 1 2 3 Meaning Low order bytes is to be fixed Offset is to be fixed Segment is to be fixed Pointer (segment : offset) is to be fixed

 Frame datum field: it refers to a SEGDEF record and

identifies the segment to which the fixup location belongs.

y Target datum & target offset field: specifies the

relocation or linking information. The target datum contains a segment/external index. The target offset contains an offset from the name indicated in target datum. y Fix dat field: indicates the manner in which the target datum & target offset fields are to be interpreted. C0des in fixdat field:
CODE Contents of target datum and offset fields O 2 4 6 Segment index and displacement External index and target displacement Segment index (offset field is not used) External index (offset field is not used)

MODEND records
 The MODEND specifies the end the object module.
8A H length Type (1) Start addr (5) Check sum

 The

Type field

indicates whether it is the main

program.  This record also optionally indicates the execution start address.

Sample MS DOS assembly language program


Sr. no.
0001 0002 0003 0004 0007 : : 0012 : : 0029 : : 0036 0037

Statement

offset

NAME FIRST COMPUTE SEGMENT EXTERN BETA:BYTE, GAMMA:WORD PUBLIC ALPHA 0015 ALPHA .. .. : : MOV AX, SEG BETA 0028 : : JMP GAMMA 0056 : : COMPUTE ENDS END

OBJECT Module FIRST


Type Length
8OH

96H 98H 9oH 8CH AOH 9CH AOH 9CH 8AH

Other fields Check sum 05 FIRST 07 COMPUTE 20H 122 01 01 05 ALPHA 0015 04 BETA 05 GAMMA 01 0028 A1 00 00 8801 06 01 01 01 0056 EA 00 00 8C01 06 01 02 8OH

THEADR LNAMES SEGDEF PUBDEF EXTDEF LEDATA FIXUPP LEDATA FIXUPP MODEND

Other types of records


 The data type for both EXTDEF and PUBDEF are

defined in TYPDEF record.


 GRPDEF record specify how these segments are

combined into groups.


 LIDATA record specify translated instructions and

data that occur in a repeating pattern.

MS-DOS LINK performs linking, like compiling or assembling, in fundamentally a two pass process. Pass 1
In the first pass, object modules are processed to collect information concerning segments and public definations.

Pass 2
It performs relocation and linking.

PASS 1 of LINK
 Data structure used in pass 1 is Name Table (NTAB). It

has the following formatSYMBOL LOAD ADDRESS

 In pass 1 the object modules are processed. A symbol

table is created and the addresses and name of each segment using SEGDEF, LNAMES respectively are recorded.
 The external references are obtained using EXTDEF

and PUBDEF.

load the origin address (if not specified-> default address) when LNAMES record encountered enter the names in NAMELIST when SEGDEF encountered enter segment name & segment address in NTAB for each PUBDEF record

enter symbol and symbol address (i.e segment address from NTAB + offset) in NTAB

PASS 2 of LINK
 The data structures used in pass 2 are SEGTAB and EXTTAB.  LINKER builds table called SEGTAB (segment table) to contain all segment names defined in the object module.  A SEGTAB has the following format
SEGMENT NAME LOAD ADDRESS

 While processing an LEDATA record the segment index can be used to index SEGTAB to obtain the segment s load address.

 Relocation and linking are performed using FIXUPP records.  Since a linking specification in a FIXUPP record may contain a reference to an external symbol, LINKER builds an external symbol table( EXTTAB) with the following format:
EXTERNAL SYMBOL LOAD ADDRESS

 EXTTAB is built by processing the EXTDEF record and copying the load addresses from NTAB.  At the end, the executable file is prepared which is then loaded into the memory for execution.

prepares memory, if needed disk space is also used data from LEDATA records moved to the appropriate parts of work-area segment index of LEDATA used to obtain load origin of the segment from NTAB segment name can be obtained from LNAMES record this name can be searched in NTAB to obtain its load address

FIXUPP records are then processed to effect relocation & linking (using target datum)

to eliminate indirect references to NTAB , SEGTAB is built to contain all segment names in the object modules FIXUPP record may contain a reference to an external symbol, so EXTTAB is built

Working of a linker
 The LINK program of MS DOS produces an executable program with extension .exe .  The linker is invoked by a command.  LINKER links object module names, executable files, load origins and names of library files.  When LINKER encounters external symbols, it searches the references in the library files, as soon as they are obtained, the set of such object modules are linked and relocated. This process is called auto linking.

The LINKER invocation command has the following format:

LINKER <object module names> <executable file> <load origin> <list of library files>

EXAMPLE
LINKER FIRST+SECOND, sum,10000,math.lib  FIRST and SECOND are object modules which are to be linked.  sum is the executable file name.  10000 is the load origin.  The library file named math.lib is used in which the object modules FIRST and SECOND are searched.

You might also like