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.

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. The next step is to link this file. The linker takes one or more object files as input, and produces an executable file. 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. 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. 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. 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\.