The Microsoft Macro Assembler (MASM) is distributed as the file MASM.EXE. When beginning a program translation, MASM needs the following information:
The name of the file containing the source program
The filename for the object program to be created
The destination of the program listing
The filename for the information that is later processed by the cross-reference utility (CREF.EXE)
You can invoke MASM in two ways. If you enter the name of the assembler alone, it prompts you for the names of each of the various input and output files. The assembler supplies reasonable defaults for all the responses except the source filename, as shown in the following example:
C>MASM <Enter>
Microsoft Ň Macro Assembler Version 5.10
Copyright Ó Microsoft Corp 1981, 1988. All rights reserved.
Source filename [.ASM]: HELLO <Enter>
Object filename [HELLO.OBJ]: <Enter>
Source listing [NUL.LST]: <Enter>
Cross-reference [NUL.CRF]: <Enter>
49006 Bytes symbol space free
0 Warning Errors
0 Severe Errors
C>
You can use a logical device name (such as PRN or COM1) at any of the MASM prompts to send that output of the assembler to a character device rather than a file. Note that the default for the listing and cross-reference files is the NUL device——that is, no file is created. If you end any response with a semicolon, MASM assumes that the remaining responses are all to be the default.
A more efficient way to use MASM is to supply all parameters in the command line, as follows:
MASM [options] source,[object],[listing],[crossref]
For example, the following command lines are equivalent to the preceding interactive session:
C>MASM HELLO,,NUL,NUL <Enter>
or
C>MASM HELLO; <Enter>
These commands use the file HELLO.ASM as the source, generate the object-code file HELLO.OBJ, and send the listing and cross-reference files to the bit bucket.
MASM accepts several optional switches in the command line, to control code generation and output files. Figure 4-1 lists the switches accepted by MASM version 5.1. As shown in the following example, you can put frequently used options in a MASM environment variable, where they will be found automatically by the assembler:
C>SET MASM=/T /Zi <Enter>
The switches in the environment variable will be overridden by any that you enter in the command line.
In other versions of the Microsoft Macro Assembler, additional or fewer switches may be available. For exact instructions, see the manual for the version of MASM that you are using.
Switch Meaning
/A Arrange segments in alphabetic order.
/Bn Set size of source-file buffer (in KB).
/C Force creation of a cross-reference (.CRF) file.
/D Produce listing on both passes (to find phase errors).
/Dsymbol Define symbol as a null text string (symbol can be referenced
by conditional assembly directives in file).
/E Assemble for 80x87 numeric coprocessor emulator using IEEE
real-number format.
/Ipath Set search path for include files.
/L Force creation of a program-listing file.
/LA Force listing of all generated code.
/ML Preserve case sensitivity in all names (uppercase names
distinct from their lowercase equivalents).
/MX Preserve lowercase in external names only (names defined with
PUBLIC or EXTRN directives).
/MU Convert all lowercase names to uppercase.
/N Suppress generation of tables of macros, structures, records,
segments, groups, and symbols at the end of the listing.
/P Check for impure code in 80286/80386 protected mode.
/S Arrange segments in order of occurrence (default).
/T "Terse" mode; suppress all messages unless errors are
encountered during the assembly.
/V "Verbose" mode; report number of lines and symbols at end of
assembly.
/Wn Set error display (warning) level; n=0—2.
/X Force listing of false conditionals.
/Z Display source lines containing errors on the screen.
/Zd Include line-number information in .OBJ file.
/Zi Include line-number and symbol information in .OBJ file.
Figure 4-1. Microsoft Macro Assembler version 5.1 switches.
MASM allows you to override the default extensions on any file——a feature that can be rather dangerous. For example, if in the preceding example you had responded to the Object filename prompt with HELLO.ASM, the assembler would have accepted the entry without comment and destroyed your source file. This is not too likely to happen in the interactive command mode, but you must be very careful with file extensions when MASM is used in a batch file.