Assembly
Language Programming
Using Microsoft's Macro Assembler and Linker
The assembler for this course is MASM (Microsoft's Macro Assembler) version
5.1. It is available on the Banyan Network on drive R: in the masm directory.
The assembler will translate your source file to a common binary format.
This file must be linked before it can be loaded into memory and executed.
The linker program can accomplish this second task.
Source files are simple ASCII text files. You may use any editor that
is capable of saving files in this format. Notepad or Wordpad are two good
choices under Windows95. You may also choose to use DOS's editor, Edit
if you want to stay in the DOS environment.
The assembler, linker, and programs you write, will run under Windows95
in a DOS window. You can open a DOS window by finding the appropriate shortcut,
or running command.com from the run dialog. There are four batch files
available on drive E to streamline the typing necessary to assemble, link,
and run the programs you write. If you copy them to your floppy disk, you
will save a lot of typing.
Assume you have written an assembly language program named PGM4_1.ASM
and stored it in the root directory of your floppy disk in drive A:. The
following screen shot from a DOS window shows how to assemble the program.
The dir command displays the names of the three files created by the assembler.
A:\>r:\masm\masm pgm4_1,,,,
Microsoft (R) Macro Assembler Version 5.10
Copyright (C) Microsoft Corp 1981, 1988. All rights reserved.
47106 + 431914 Bytes symbol space free
0 Warning Errors
0 Severe Errors
A:\>dir
Volume in drive A has no label
Directory of A:\
PGM4_1 ASM
1,024 04-24-92 12:12a PGM4_1.ASM
PGM4_1 OBJ
148 01-22-98 12:56p PGM4_1.OBJ
PGM4_1 LST
2,696 01-22-98 12:56p PGM4_1.LST
PGM4_1 CRF
329 01-22-98 12:56p PGM4_1.CRF
4 file(s)
4,197 bytes
0 dir(s)
1,452,544 bytes free
A:\>
The assembled code is in PGM4_1.OBJ. The .LST file contains the listing
(report) generated by the assembler. The .CRF file is a binary file containing
cross reference information that we will never use. The batch file, MASM.BAT,
contains the above command to invoke the assembler. To assemble this program
using the batch file (assuming that you have copied it to the same location
as the source file) is shown below. Only the first line was typed. The
actual invocation of the assembler is done by the batch file. The entry,
NUL, indicates that no cross reference file is to be generated.
A:\>masm pgm4_1
A:\>r:\masm\masm /Zi pgm4_1,pgm4_1,pgm4_1,NUL
Microsoft (R) Macro Assembler Version 5.10
Copyright (C) Microsoft Corp 1981, 1988. All rights reserved.
47080 + 431844 Bytes symbol space free
0 Warning Errors
0 Severe Errors
A:\>
The next step is to link this file. The linker takes one or more object
files as input, and produces an executable file.
A:\>r:\masm\link pgm4_1,,,,
Microsoft (R) Overlay Linker Version 3.64
Copyright (C) Microsoft Corp 1983-1988. All rights reserved.
A:\>dir
...
PGM4_1 MAP
281 01-22-98 1:26p PGM4_1.MAP
PGM4_1 EXE
542 01-22-98 1:26p PGM4_1.EXE
...
Thelinker produces the executable file and a map file that contains information
about the memory layout contained in the executable. The map file for this
program is shown here.
A:\>type pgm4_1.map
Start Stop Length Name
Class
00000H 0001DH 0001EH _TEXT
CODE
0001EH 0001EH 00000H _DATA
DATA
00020H 0011FH 00100H STACK
STACK
Origin Group
0001:0 DGROUP
Program entry point at 0000:0000
The batch file, LINK.BAT, can again be used to avoid typing the path and
option information. The /CO option will cause the linker to include debugging
information for use with Codeview.
A:\>link pgm4_1
A:\>r:\masm\link /co pgm4_1,,,,
Microsoft (R) Overlay Linker Version 3.64
Copyright (C) Microsoft Corp 1983-1988. All rights reserved.
Now we can execute the program. DOS's command.com program allows us to
request program loading and execution by typing the name of the executable.
In this case, we simply type PGM4_1.EXE (the .EXE is optional). Three sample
runs of this program are shown below. The program expects the user to type
one character.
A:\>pgm4_1.exe
?3
3
A:\>
A:\>pgm4_1
?a
a
A:\>pgm4_1
?y
y
A:\>
The GO.BAT batch file will combine assembly, linking, and requesting execution
in one step. The other batch file, CV.BAT, will invoke Codeview for an
executable file.
You should try assembling, linking, and executing this program using
the above instructions. All of the sample programs in chapter 4 are available
here or at drive E:\Assembly\.