0% found this document useful (1 vote)
6K views

Ms-Dos Linker: Dhriti Das (Roll No-07) Simsima Gogoi (Roll No-17) Tanmi Bharadwaj (Roll No-18)

The document discusses the MS-DOS linker, which combines object modules created by compilers and assemblers into executable programs. It describes the object module format, which includes records for binary image, external references, public definitions, and more. It also explains the two-pass linking process, where the linker first collects symbol and segment information, then performs relocation and linking to produce the executable file.

Uploaded by

Mukut Jyoti Das
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
6K views

Ms-Dos Linker: Dhriti Das (Roll No-07) Simsima Gogoi (Roll No-17) Tanmi Bharadwaj (Roll No-18)

The document discusses the MS-DOS linker, which combines object modules created by compilers and assemblers into executable programs. It describes the object module format, which includes records for binary image, external references, public definitions, and more. It also explains the two-pass linking process, where the linker first collects symbol and segment information, then performs relocation and linking to produce the executable file.

Uploaded by

Mukut Jyoti Das
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

MS-DOS LINKER

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 below-
RECORD TYPE Id (Hex) DESCRIPTION
THEADR 8O Translator header record
LNAMES 96 List of names record
SEGDEF 98 Segment defination record
EXTDEF 8C External names defination record
PUBDEF 9O Public names defination record
LEDATA AO Translated data (binary image)
FIXUPP 9C Relocation & linking information
MODEND 8A 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 Check-sum


name
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 Check-sum


list
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 … Check
(2-4) (2) 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 Data Data Check sum


index (1-2) offset (2)

Specifies the location


Identifies the of the code within
segment to which the segment
the code belongs
FIXUPP records
 FIXUPP records are used to resolve external references,
and to perform address modification that are
associated with relocation.

9CH length locat Fix Frame Target Target offset Check sum
(1) dat datum datum (1) …
(1) (1) (1)
 Locat field: it contains a numeric code called loc code
to indicate the type of a fixup.

Loc code Meaning


0 Low order bytes is to be fixed
1 Offset is to be fixed
2 Segment is to be fixed
3 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.
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.
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 Segment index and displacement
2 External index and target displacement
4 Segment index (offset field is not used)
6 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 indicates whether it is the main


Type field
program.
 This record also optionally indicates the execution
start address.
Sample MS DOS assembly language program
Sr. no. Statement offset
0001 NAME FIRST
0002 COMPUTE SEGMENT
0003 EXTERN BETA:BYTE, GAMMA:WORD
0004 PUBLIC ALPHA 0015
0007 ALPHA .. ..
: :
: :
0012 MOV AX, SEG BETA 0028
: :
: :
0029 JMP GAMMA 0056
: :
: :
0036 COMPUTE ENDS
0037 END
OBJECT Module “FIRST”
TypeLength Other fields Check sum
8OH … 05 FIRST … THEADR
96H … 07 COMPUTE … LNAMES
98H … 20H 122 01 … SEGDEF
9oH … 01 05 ALPHA 0015 … PUBDEF
8CH … 04 BETA 05 GAMMA … EXTDEF
AOH … 01 0028 A1 00 00 … LEDATA
9CH … 8801 06 01 01 … FIXUPP
AOH … 01 0056 EA 00 00 … LEDATA
9CH … 8C01 06 01 02 … FIXUPP
8AH … 8OH … 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 format-

SYMBOL 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