For situations in which this behaviour is unacceptable, NASM provides the −o command−line option,
which allows you to specify your desired output file name. You invoke −o by following it with the name
you wish for the output file, either with or without an intervening space. For example:
nasm −f bin program.asm −o program.com
nasm −f bin driver.asm −odriver.sys
Note that this is a small o, and is different from a capital O , which is used to specify the number of
optimisation passes required. See section 2.1.22.
2.1.2 The −f Option: Specifying the Output File Format
If you do not supply the −f option to NASM, it will choose an output file format for you itself. In the
distribution versions of NASM, the default is always bin; if you’ve compiled your own copy of NASM,
you can redefine OF_DEFAULT at compile time and choose what you want the default to be.
Like −o, the intervening space between −f and the output file format is optional; so −f elf and
−felf are both valid.
A complete list of the available output file formats can be given by issuing the command nasm −hf.
2.1.3 The −l Option: Generating a Listing File
If you supply the −l option to NASM, followed (with the usual optional space) by a file name, NASM will
generate a source−listing file for you, in which addresses and generated code are listed on the left, and
the actual source code, with expansions of multi−line macros (except those which specifically request
no expansion in source listings: see section 4.3.11) on the right. For example:
nasm −f elf myfile.asm −l myfile.lst
If a list file is selected, you may turn off listing for a section of your source with [list −], and turn it
back on with [list +], (the default, obviously). There is no "user form" (without the brackets). This
can be used to list only sections of interest, avoiding excessively long listings.
2.1.4 The −M Option: Generate Makefile Dependencies
This option can be used to generate makefile dependencies on stdout. This can be redirected to a file
for further processing. For example:
nasm −M myfile.asm > myfile.dep
2.1.5 The −MG Option: Generate Makefile Dependencies
This option can be used to generate makefile dependencies on stdout. This differs from the −M option
in that if a nonexisting file is encountered, it is assumed to be a generated file and is added to the
dependency list without a prefix.
2.1.6 The −MF Option: Set Makefile Dependency File
This option can be used with the −M or −MG options to send the output to a file, rather than to stdout.
For example:
nasm −M −MF myfile.dep myfile.asm
2.1.7 The −MD Option: Assemble and Generate Dependencies
The −MD option acts as the combination of the −M and −MF options (i.e. a filename has to be specified.)
However, unlike the −M or −MG options, −MD does not inhibit the normal operation of the assembler.
Use this to automatically generate updated dependencies with every assembly session. For example:
nasm −f elf −o myfile.o −MD myfile.dep myfile.asm
20