Next Chapter | Previous Chapter | Contents | Index
To assemble a file, you issue a command of the form
nasm -f <format> <filename> [-o <output>]
For example,
nasm -f elf myfile.asm
will assemble 
nasm -f bin myfile.asm -o myfile.com
will assemble 
To produce a listing file, with the hex codes output from NASM displayed
on the left of the original sources, use the 
nasm -f coff myfile.asm -l myfile.lst
To get further usage instructions from NASM, try typing
nasm -h
This will also list the available output file formats, and what they are.
If you use Linux but aren't sure whether your system is
file nasm
(in the directory in which you put the NASM binary when you installed it). If it says something like
nasm: ELF 32-bit LSB executable i386 (386 and up) Version 1
then your system is ELF, and you should use the option
nasm: Linux/i386 demand-paged executable (QMAGIC)
or something similar, your system is 
Like Unix compilers and assemblers, NASM is silent unless it goes wrong: you won't see any output at all, unless it gives error messages.
-o NASM will normally choose the name of your output file for you;
precisely how it does this is dependent on the object file format. For
Microsoft object file formats (
If the output file already exists, NASM will overwrite it, unless it has
the same name as the input file, in which case it will give a warning and
use 
For situations in which this behaviour is unacceptable, NASM provides
the 
nasm -f bin program.asm -o program.com nasm -f bin driver.asm -odriver.sys
-f If you do not supply the 
Like 
A complete list of the available output file formats can be given by
issuing the command 
-l If you supply the 
nasm -f elf myfile.asm -l myfile.lst
-E Under MS-DOS it can be difficult (though there are ways) to redirect the
standard-error output of a program to a file. Since NASM usually produces
its warning and error messages on 
NASM therefore provides the 
nasm -E myfile.err -f obj myfile.asm
-s stdout The 
nasm -s -f obj myfile.asm | more
See also the 
-i When NASM sees the 
nasm -ic:\macrolib\ -f obj myfile.asm
(As usual, a space between 
NASM, in the interests of complete source-code portability, does not
understand the file naming conventions of the OS it is running on; the
string you provide as an argument to the 
(You can use this to your advantage, if you're really perverse, by
noting that the option 
If you want to define a standard include search path, similar
to 
For Makefile compatibility with many C compilers, this option can also
be specified as 
-p NASM allows you to specify files to be pre-included into your
source file, by the use of the 
nasm myfile.asm -p myinc.inc
is equivalent to running 
For consistency with the 
-d Just as the 
nasm myfile.asm -dFOO=100
as an alternative to placing the directive
%define FOO 100
at the start of the file. You can miss off the macro value, as well: the
option 
For Makefile compatibility with many C compilers, this option can also
be specified as 
-u The 
For example, the following command line:
nasm myfile.asm -dFOO=100 -uFOO
would result in 
For Makefile compatibility with many C compilers, this option can also
be specified as 
-e NASM allows the preprocessor to be run on its own, up to a point. Using
the 
This option cannot be applied to programs which require the preprocessor to evaluate expressions which depend on the values of symbols: so code such as
%assign tablesize ($-tablestart)
will cause an error in preprocess-only mode.
-a If NASM is being used as the back end to a compiler, it might be
desirable to suppress preprocessing completely and assume the compiler has
already done it, to save time and increase compilation speeds. The
-w NASM can observe many conditions during the course of assembly which are worth mentioning to the user, but not a sufficiently severe error to justify NASM refusing to generate an output file. These conditions are reported like errors, but come up with the word `warning' before the message. Warnings do not prevent NASM from generating an output file and returning a success status to the operating system.
Some conditions are even less severe than that: they are only sometimes
worth mentioning to the user. Therefore NASM supports the
The suppressible warning classes are:
macro-params orphan-labels number-overflow 0x7ffffffff NASM If you define an environment variable called
The value of the variable is split up at white space, so that the value
To get round this, NASM provides a feature whereby, if you begin the
If you're used to writing programs with MASM, or with TASM in
MASM-compatible (non-Ideal) mode, or with 
One simple difference is that NASM is case-sensitive. It makes a
difference whether you call your label 
NASM was designed with simplicity of syntax in mind. One of the design goals of NASM is that it should be possible, as far as is practical, for the user to look at a single line of NASM code and tell what opcode is generated by it. You can't do this in MASM: if you declare, for example,
foo equ 1 bar dw 2
then the two lines of code
          mov ax,foo 
          mov ax,bar
generate completely different opcodes, despite having identical-looking syntaxes.
NASM avoids this undesirable situation by having a much simpler syntax
for memory references. The rule is simply that any access to the
contents of a memory location requires square brackets around the
address, and any access to the address of a variable doesn't. So
an instruction of the form 
This also means that NASM has no need for MASM's
This issue is even more confusing in 
NASM, in the interests of simplicity, also does not support the hybrid
syntaxes supported by MASM and its clones, such as
NASM, by design, chooses not to remember the types of variables you
declare. Whereas MASM will remember, on seeing
For this reason, NASM doesn't support the
ASSUME As part of NASM's drive for simplicity, it also does not support the
NASM also does not have any directives to support different 16-bit
memory models. The programmer has to keep track of which functions are
supposed to be called with a far call and which with a near call, and is
responsible for putting the correct form of 
NASM uses different names to refer to floating-point registers from
MASM: where MASM would call them 
As of version 0.96, NASM now treats the instructions with `nowait' forms in the same way as MASM-compatible assemblers. The idiosyncratic treatment employed by 0.95 and earlier was based on a misunderstanding by the authors.
For historical reasons, NASM uses the keyword
NASM does not declare uninitialised storage in the same way as MASM:
where a MASM programmer might use
In addition to all of this, macros and directives work completely differently to MASM. See chapter 4 and chapter 5 for further details.