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
As 
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 
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
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.
-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
If a list file is selected, you may turn off listing for a section of
your source with 
-M 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
-MG This option can be used to generate makefile dependencies on stdout.
This differs from the 
-MF This option can be used with the 
nasm -M -MF myfile.dep myfile.asm
-MD The 
nasm -f elf -o myfile.o -MD myfile.dep myfile.asm
-MT The 
-MQ The 
-MP When used with any of the dependency generation options, the
-F This option is used to select the format of the debug information
emitted into the output file, to be used by a debugger (or will
be). Prior to version 2.03.01, the use of this switch did not
enable output of the selected debug info format. Use
A complete list of the available debug file formats for an output format
can be seen by issuing the command
This should not be confused with the 
-g This option can be used to generate debugging information in the
specified format. See section 2.1.11. Using
-X This option can be used to select an error reporting format for any error messages that might be produced by NASM.
Currently, two error reporting formats may be selected. They are the
filename.asm:65: error: specific error message
where 
The other format, specified by 
filename.asm(65) : error: specific error message
where the only difference is that the line number is in parentheses instead of being delimited by colons.
See also the 
-Z Under 
NASM therefore provides the 
nasm -Z myfile.err -f obj myfile.asm
In earlier versions of NASM, this option was called
-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.
For compatiblity with older version of NASM, this option can also be
written 
-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
-O Using the 
-O0 -O1 -Ox x x strict x The 
Note that this is a capital 
-t NASM includes a limited form of compatibility with Borland's
@@ . mov eax,[DWORD val] arg elif else endif if ifdef ifdifi ifndef include local -w -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 macro-selfref macro-defaults orphan-labels number-overflow gnu-elf-extensions -f elf float-overflow float-denorm float-underflow float-toolong user %warning lock LOCK hle XACQUIRE XRELEASE error all error -w+all In addition, you can set warning classes across sections. Warning
classes may be enabled with
Since version 2.00, NASM has also supported the gcc-like syntax
-v Typing 
You will need the version number if you report a bug.
-y Typing 
nasm -f elf -y
valid debug formats for 'elf32' output format are 
  ('*' denotes default): 
  * stabs     ELF32 (i386) stabs debug format for Linux 
    dwarf     elf32 (i386) dwarf debug format for Linux
--prefix --postfix The 
NASMENV 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
This environment variable was previously called
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 uninitialized 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 6 for further details.