Chapter 5

Assembling, Linking, and Executing a Program


Source Program :assembly language program

Object Program :output of the assembler

Executable Program : output of the linker


The steps of preparing a program for execution:


1. The assembly steps involves translating the source code into object code and generating an intermediate .OBJ file or module. The assembler calculates the offset for every data item in the data segment and every instruction in the code segment. It also creates a header immediately ahead of the generated .OBJ module. Part of the header contains information about incomplete addresses.

2. The link step involves converting the .OBJ module to an .EXE machine code module. One of the linker’s tasks is to combine separately assembled programs into one executable module.

3. The last step is to load the program for execution. Since the loader is about to load, it is able to complete any addresses indicated in the header that were left incomplete. The loader drops the header and creates a PSP immediately before the program loaded in memory.


Assembling a Source Program


TASM or MASM

Command line


MASM/TASM [options] source[,object][,listing][,crossref]


Options are explained in Appendix E. One option is for debugging, /zi.


Source is the source program. If you leave the .ASM off it default to that type of file. Otherwise if the extension is not .ASM then you need to specify it.


Object is a user specified object file name.


Listing is a .LST file which contains both the source and object code.


Crossref generates a cross-reference file containing the symbols used in the program which you can use for a cross-reference listing. MASM has extension .CRF and TASM has extension .XRF.



Both TASM and MASM are two-pass assemblers. Two pass assemblers are used to resolve forward references of addresses not yet encountered in the program. During pass 1, the assembler reads the entire source program and constructs a symbol table of names and labels used in the program, that is, names of data fields and program labels and their relative locations(offsets) within the segment. Pass 1 also determines the amount of code to be generated for each instruction.


Note: MASM starts generating code in pass 1, whereas TASM does it in pass 2.

During pass 2 the assembler uses the symbol table that is constructed in pass 1. From pass 1, the assembler knows the length and relative of position of each data field and instruction, it can complete the object code for each instruction.


With MASM, there is a potential problem with forward references. Since it begins generating object code in pass one (Page 80 of TEXT.)


Linking an Object Program


Once your program is free of error messages, your next step is to link the object module.


The linker performs the following functions:

1. Combines, if requested, more than one separately assembled module into one executable program.

2. Generates an .EXE module and initializes it with special instruction to facilitate its subsequent loading for execution.




LINK and TLINK


Syntax:


LINK/TLINK objfile,exefile[,mapfile][,libraryfile]


Objfile identifies the object file generated by the assembler.

Exefile provides for generating an .EXE file.

Mapfile provides for generating a file with an extension .MAP that indicates the relative location and size of each segment and any errors that LINK has found. If you enter CON as the mapfile preference it will disply the map file on the screen.

Libraryfile provides for the libaries option.