\# -------------------------------------------------------------------------- \# \# Copyright 1996-2013 The NASM Authors - All Rights Reserved \# See the file AUTHORS included with the NASM distribution for \# the specific copyright holders. \# \# Redistribution and use in source and binary forms, with or without \# modification, are permitted provided that the following \# conditions are met: \# \# * Redistributions of source code must retain the above copyright \# notice, this list of conditions and the following disclaimer. \# * Redistributions in binary form must reproduce the above \# copyright notice, this list of conditions and the following \# disclaimer in the documentation and/or other materials provided \# with the distribution. \# \# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, \# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; \# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) \# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR \# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, \# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \# \# -------------------------------------------------------------------------- \# \# Source code to NASM documentation \# \M{category}{Programming} \M{title}{NASM - The Netwide Assembler} \M{year}{1996-2012} \M{author}{The NASM Development Team} \M{copyright_tail}{-- All Rights Reserved} \M{license}{This document is redistributable under the license given in the file "LICENSE" distributed in the NASM archive.} \M{summary}{This file documents NASM, the Netwide Assembler: an assembler targetting the Intel x86 series of processors, with portable source.} \M{infoname}{NASM} \M{infofile}{nasm} \M{infotitle}{The Netwide Assembler for x86} \M{epslogo}{nasmlogo.eps} \M{logoyadj}{-72} \IR{-D} \c{-D} option \IR{-E} \c{-E} option \IR{-F} \c{-F} option \IR{-I} \c{-I} option \IR{-M} \c{-M} option \IR{-MD} \c{-MD} option \IR{-MF} \c{-MF} option \IR{-MG} \c{-MG} option \IR{-MP} \c{-MP} option \IR{-MQ} \c{-MQ} option \IR{-MT} \c{-MT} option \IR{-O} \c{-O} option \IR{-P} \c{-P} option \IR{-U} \c{-U} option \IR{-X} \c{-X} option \IR{-a} \c{-a} option \IR{-d} \c{-d} option \IR{-e} \c{-e} option \IR{-f} \c{-f} option \IR{-g} \c{-g} option \IR{-i} \c{-i} option \IR{-l} \c{-l} option \IR{-o} \c{-o} option \IR{-p} \c{-p} option \IR{-s} \c{-s} option \IR{-u} \c{-u} option \IR{-v} \c{-v} option \IR{-W} \c{-W} option \IR{-w} \c{-w} option \IR{-y} \c{-y} option \IR{-Z} \c{-Z} option \IR{!=} \c{!=} operator \IR{$, here} \c{$}, Here token \IR{$, prefix} \c{$}, prefix \IR{$$} \c{$$} token \IR{%} \c{%} operator \IR{%%} \c{%%} operator \IR{%+1} \c{%+1} and \c{%-1} syntax \IA{%-1}{%+1} \IR{%0} \c{%0} parameter count \IR{&} \c{&} operator \IR{&&} \c{&&} operator \IR{*} \c{*} operator \IR{..@} \c{..@} symbol prefix \IR{/} \c{/} operator \IR{//} \c{//} operator \IR{<} \c{<} operator \IR{<<} \c{<<} operator \IR{<=} \c{<=} operator \IR{<>} \c{<>} operator \IR{=} \c{=} operator \IR{==} \c{==} operator \IR{>} \c{>} operator \IR{>=} \c{>=} operator \IR{>>} \c{>>} operator \IR{?} \c{?} MASM syntax \IR{^} \c{^} operator \IR{^^} \c{^^} operator \IR{|} \c{|} operator \IR{||} \c{||} operator \IR{~} \c{~} operator \IR{%$} \c{%$} and \c{%$$} prefixes \IA{%$$}{%$} \IR{+ opaddition} \c{+} operator, binary \IR{+ opunary} \c{+} operator, unary \IR{+ modifier} \c{+} modifier \IR{- opsubtraction} \c{-} operator, binary \IR{- opunary} \c{-} operator, unary \IR{! opunary} \c{!} operator, unary \IR{alignment, in bin sections} alignment, in \c{bin} sections \IR{alignment, in elf sections} alignment, in \c{elf} sections \IR{alignment, in win32 sections} alignment, in \c{win32} sections \IR{alignment, of elf common variables} alignment, of \c{elf} common variables \IR{alignment, in obj sections} alignment, in \c{obj} sections \IR{a.out, bsd version} \c{a.out}, BSD version \IR{a.out, linux version} \c{a.out}, Linux version \IR{autoconf} Autoconf \IR{bin} bin \IR{bitwise and} bitwise AND \IR{bitwise or} bitwise OR \IR{bitwise xor} bitwise XOR \IR{block ifs} block IFs \IR{borland pascal} Borland, Pascal \IR{borland's win32 compilers} Borland, Win32 compilers \IR{braces, after % sign} braces, after \c{%} sign \IR{bsd} BSD \IR{c calling convention} C calling convention \IR{c symbol names} C symbol names \IA{critical expressions}{critical expression} \IA{command line}{command-line} \IA{case sensitivity}{case sensitive} \IA{case-sensitive}{case sensitive} \IA{case-insensitive}{case sensitive} \IA{character constants}{character constant} \IR{common object file format} Common Object File Format \IR{common variables, alignment in elf} common variables, alignment in \c{elf} \IR{common, elf extensions to} \c{COMMON}, \c{elf} extensions to \IR{common, obj extensions to} \c{COMMON}, \c{obj} extensions to \IR{declaring structure} declaring structures \IR{default-wrt mechanism} default-\c{WRT} mechanism \IR{devpac} DevPac \IR{djgpp} DJGPP \IR{dll symbols, exporting} DLL symbols, exporting \IR{dll symbols, importing} DLL symbols, importing \IR{dos} DOS \IR{dos archive} DOS archive \IR{dos source archive} DOS source archive \IA{effective address}{effective addresses} \IA{effective-address}{effective addresses} \IR{elf} ELF \IR{elf, 16-bit code and} ELF, 16-bit code and \IR{elf shared libraries} ELF, shared libraries \IR{elf32} \c{elf32} \IR{elf64} \c{elf64} \IR{elfx32} \c{elfx32} \IR{executable and linkable format} Executable and Linkable Format \IR{extern, obj extensions to} \c{EXTERN}, \c{obj} extensions to \IR{extern, rdf extensions to} \c{EXTERN}, \c{rdf} extensions to \IR{floating-point, constants} floating-point, constants \IR{floating-point, packed bcd constants} floating-point, packed BCD constants \IR{freebsd} FreeBSD \IR{freelink} FreeLink \IR{functions, c calling convention} functions, C calling convention \IR{functions, pascal calling convention} functions, Pascal calling convention \IR{global, aoutb extensions to} \c{GLOBAL}, \c{aoutb} extensions to \IR{global, elf extensions to} \c{GLOBAL}, \c{elf} extensions to \IR{global, rdf extensions to} \c{GLOBAL}, \c{rdf} extensions to \IR{got} GOT \IR{got relocations} \c{GOT} relocations \IR{gotoff relocation} \c{GOTOFF} relocations \IR{gotpc relocation} \c{GOTPC} relocations \IR{intel number formats} Intel number formats \IR{linux, elf} Linux, ELF \IR{linux, a.out} Linux, \c{a.out} \IR{linux, as86} Linux, \c{as86} \IR{logical and} logical AND \IR{logical or} logical OR \IR{logical xor} logical XOR \IR{mach object file format} Mach, object file format \IR{mach-o} Mach-O \IR{macho32} \c{macho32} \IR{macho64} \c{macho64} \IR{macos x} MacOS X \IR{masm} MASM \IA{memory reference}{memory references} \IR{minix} Minix \IA{misc directory}{misc subdirectory} \IR{misc subdirectory} \c{misc} subdirectory \IR{microsoft omf} Microsoft OMF \IR{mmx registers} MMX registers \IA{modr/m}{modr/m byte} \IR{modr/m byte} ModR/M byte \IR{ms-dos} MS-DOS \IR{ms-dos device drivers} MS-DOS device drivers \IR{multipush} \c{multipush} macro \IR{nan} NaN \IR{nasm version} NASM version \IR{netbsd} NetBSD \IR{omf} OMF \IR{openbsd} OpenBSD \IR{operating system} operating system \IR{os/2} OS/2 \IR{pascal calling convention}Pascal calling convention \IR{passes} passes, assembly \IR{perl} Perl \IR{pic} PIC \IR{pharlap} PharLap \IR{plt} PLT \IR{plt} \c{PLT} relocations \IA{pre-defining macros}{pre-define} \IA{preprocessor expressions}{preprocessor, expressions} \IA{preprocessor loops}{preprocessor, loops} \IA{preprocessor variables}{preprocessor, variables} \IA{rdoff subdirectory}{rdoff} \IR{rdoff} \c{rdoff} subdirectory \IR{relocatable dynamic object file format} Relocatable Dynamic Object File Format \IR{relocations, pic-specific} relocations, PIC-specific \IA{repeating}{repeating code} \IR{section alignment, in elf} section alignment, in \c{elf} \IR{section alignment, in bin} section alignment, in \c{bin} \IR{section alignment, in obj} section alignment, in \c{obj} \IR{section alignment, in win32} section alignment, in \c{win32} \IR{section, elf extensions to} \c{SECTION}, \c{elf} extensions to \IR{section, win32 extensions to} \c{SECTION}, \c{win32} extensions to \IR{segment alignment, in bin} segment alignment, in \c{bin} \IR{segment alignment, in obj} segment alignment, in \c{obj} \IR{segment, obj extensions to} \c{SEGMENT}, \c{elf} extensions to \IR{segment names, borland pascal} segment names, Borland Pascal \IR{shift command} \c{shift} command \IA{sib}{sib byte} \IR{sib byte} SIB byte \IR{align, smart} \c{ALIGN}, smart \IA{sectalign}{sectalign} \IR{solaris x86} Solaris x86 \IA{standard section names}{standardized section names} \IR{symbols, exporting from dlls} symbols, exporting from DLLs \IR{symbols, importing from dlls} symbols, importing from DLLs \IR{test subdirectory} \c{test} subdirectory \IR{tlink} \c{TLINK} \IR{underscore, in c symbols} underscore, in C symbols \IR{unicode} Unicode \IR{unix} Unix \IR{utf-8} UTF-8 \IR{utf-16} UTF-16 \IR{utf-32} UTF-32 \IA{sco unix}{unix, sco} \IR{unix, sco} Unix, SCO \IA{unix source archive}{unix, source archive} \IR{unix, source archive} Unix, source archive \IA{unix system v}{unix, system v} \IR{unix, system v} Unix, System V \IR{unixware} UnixWare \IR{val} VAL \IR{version number of nasm} version number of NASM \IR{visual c++} Visual C++ \IR{www page} WWW page \IR{win32} Win32 \IR{win32} Win64 \IR{windows} Windows \IR{windows 95} Windows 95 \IR{windows nt} Windows NT \# \IC{program entry point}{entry point, program} \# \IC{program entry point}{start point, program} \# \IC{MS-DOS device drivers}{device drivers, MS-DOS} \# \IC{16-bit mode, versus 32-bit mode}{32-bit mode, versus 16-bit mode} \# \IC{c symbol names}{symbol names, in C} \C{intro} Introduction \H{whatsnasm} What Is NASM? The Netwide Assembler, NASM, is an 80x86 and x86-64 assembler designed for portability and modularity. It supports a range of object file formats, including Linux and \c{*BSD} \c{a.out}, \c{ELF}, \c{COFF}, \c{Mach-O}, Microsoft 16-bit \c{OBJ}, \c{Win32} and \c{Win64}. It will also output plain binary files. Its syntax is designed to be simple and easy to understand, similar to Intel's but less complex. It supports all currently known x86 architectural extensions, and has strong support for macros. \S{yaasm} Why Yet Another Assembler? The Netwide Assembler grew out of an idea on \i\c{comp.lang.asm.x86} (or possibly \i\c{alt.lang.asm} - I forget which), which was essentially that there didn't seem to be a good \e{free} x86-series assembler around, and that maybe someone ought to write one. \b \i\c{a86} is good, but not free, and in particular you don't get any 32-bit capability until you pay. It's DOS only, too. \b \i\c{gas} is free, and ports over to DOS and Unix, but it's not very good, since it's designed to be a back end to \i\c{gcc}, which always feeds it correct code. So its error checking is minimal. Also, its syntax is horrible, from the point of view of anyone trying to actually \e{write} anything in it. Plus you can't write 16-bit code in it (properly.) \b \i\c{as86} is specific to Minix and Linux, and (my version at least) doesn't seem to have much (or any) documentation. \b \i\c{MASM} isn't very good, and it's (was) expensive, and it runs only under DOS. \b \i\c{TASM} is better, but still strives for MASM compatibility, which means millions of directives and tons of red tape. And its syntax is essentially MASM's, with the contradictions and quirks that entails (although it sorts out some of those by means of Ideal mode.) It's expensive too. And it's DOS-only. So here, for your coding pleasure, is NASM. At present it's still in prototype stage - we don't promise that it can outperform any of these assemblers. But please, \e{please} send us bug reports, fixes, helpful information, and anything else you can get your hands on (and thanks to the many people who've done this already! You all know who you are), and we'll improve it out of all recognition. Again. \S{legal} \i{License} Conditions Please see the file \c{LICENSE}, supplied as part of any NASM distribution archive, for the license conditions under which you may use NASM. NASM is now under the so-called 2-clause BSD license, also known as the simplified BSD license. Copyright 1996-2011 the NASM Authors - All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: \b Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. \b Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \H{contact} Contact Information The current version of NASM (since about 0.98.08) is maintained by a team of developers, accessible through the \c{nasm-devel} mailing list (see below for the link). If you want to report a bug, please read \k{bugs} first. NASM has a \i{website} at \W{http://www.nasm.us/}\c{http://www.nasm.us/}. If it's not there, google for us! \i{New releases}, \i{release candidates}, and \I{snapshots, daily development}\i{daily development snapshots} of NASM are available from the official web site. Announcements are posted to \W{news:comp.lang.asm.x86}\i\c{comp.lang.asm.x86}, and to the web site \W{http://www.freshmeat.net/}\c{http://www.freshmeat.net/}. If you want information about the current development status, please subscribe to the \i\c{nasm-devel} email list; see link from the website. \H{install} Installation \S{instdos} \i{Installing} NASM under MS-\i{DOS} or Windows Once you've obtained the appropriate archive for NASM, \i\c{nasm-XXX-dos.zip} or \i\c{nasm-XXX-win32.zip} (where \c{XXX} denotes the version number of NASM contained in the archive), unpack it into its own directory (for example \c{c:\\nasm}). The archive will contain a set of executable files: the NASM executable file \i\c{nasm.exe}, the NDISASM executable file \i\c{ndisasm.exe}, and possibly additional utilities to handle the RDOFF file format. The only file NASM needs to run is its own executable, so copy \c{nasm.exe} to a directory on your PATH, or alternatively edit \i\c{autoexec.bat} to add the \c{nasm} directory to your \i\c{PATH} (to do that under Windows XP, go to Start > Control Panel > System > Advanced > Environment Variables; these instructions may work under other versions of Windows as well.) That's it - NASM is installed. You don't need the nasm directory to be present to run NASM (unless you've added it to your \c{PATH}), so you can delete it if you need to save space; however, you may want to keep the documentation or test programs. If you've downloaded the \i{DOS source archive}, \i\c{nasm-XXX.zip}, the \c{nasm} directory will also contain the full NASM \i{source code}, and a selection of \i{Makefiles} you can (hopefully) use to rebuild your copy of NASM from scratch. See the file \c{INSTALL} in the source archive. Note that a number of files are generated from other files by Perl scripts. Although the NASM source distribution includes these generated files, you will need to rebuild them (and hence, will need a Perl interpreter) if you change insns.dat, standard.mac or the documentation. It is possible future source distributions may not include these files at all. Ports of \i{Perl} for a variety of platforms, including DOS and Windows, are available from \W{http://www.cpan.org/ports/}\i{www.cpan.org}. \S{instdos} Installing NASM under \i{Unix} Once you've obtained the \i{Unix source archive} for NASM, \i\c{nasm-XXX.tar.gz} (where \c{XXX} denotes the version number of NASM contained in the archive), unpack it into a directory such as \c{/usr/local/src}. The archive, when unpacked, will create its own subdirectory \c{nasm-XXX}. NASM is an \I{Autoconf}\I\c{configure}auto-configuring package: once you've unpacked it, \c{cd} to the directory it's been unpacked into and type \c{./configure}. This shell script will find the best C compiler to use for building NASM and set up \i{Makefiles} accordingly. Once NASM has auto-configured, you can type \i\c{make} to build the \c{nasm} and \c{ndisasm} binaries, and then \c{make install} to install them in \c{/usr/local/bin} and install the \i{man pages} \i\c{nasm.1} and \i\c{ndisasm.1} in \c{/usr/local/man/man1}. Alternatively, you can give options such as \c{--prefix} to the configure script (see the file \i\c{INSTALL} for more details), or install the programs yourself. NASM also comes with a set of utilities for handling the \c{RDOFF} custom object-file format, which are in the \i\c{rdoff} subdirectory of the NASM archive. You can build these with \c{make rdf} and install them with \c{make rdf_install}, if you want them. \C{running} Running NASM \H{syntax} NASM \i{Command-Line} Syntax To assemble a file, you issue a command of the form \c nasm -f [-o ] For example, \c nasm -f elf myfile.asm will assemble \c{myfile.asm} into an \c{ELF} object file \c{myfile.o}. And \c nasm -f bin myfile.asm -o myfile.com will assemble \c{myfile.asm} into a raw binary file \c{myfile.com}. To produce a listing file, with the hex codes output from NASM displayed on the left of the original sources, use the \c{-l} option to give a listing file name, for example: \c nasm -f coff myfile.asm -l myfile.lst To get further usage instructions from NASM, try typing \c nasm -h As \c{-hf}, 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 \c{a.out} or \c{ELF}, type \c file nasm (in the directory in which you put the NASM binary when you installed it). If it says something like \c nasm: ELF 32-bit LSB executable i386 (386 and up) Version 1 then your system is \c{ELF}, and you should use the option \c{-f elf} when you want NASM to produce Linux object files. If it says \c nasm: Linux/i386 demand-paged executable (QMAGIC) or something similar, your system is \c{a.out}, and you should use \c{-f aout} instead (Linux \c{a.out} systems have long been obsolete, and are rare these days.) 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. \S{opt-o} The \i\c{-o} Option: Specifying the Output File Name 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 (\c{obj}, \c{win32} and \c{win64}), it will remove the \c{.asm} \i{extension} (or whatever extension you like to use - NASM doesn't care) from your source file name and substitute \c{.obj}. For Unix object file formats (\c{aout}, \c{as86}, \c{coff}, \c{elf32}, \c{elf64}, \c{elfx32}, \c{ieee}, \c{macho32} and \c{macho64}) it will substitute \c{.o}. For \c{dbg}, \c{rdf}, \c{ith} and \c{srec}, it will use \c{.dbg}, \c{.rdf}, \c{.ith} and \c{.srec}, respectively, and for the \c{bin} format it will simply remove the extension, so that \c{myfile.asm} produces the output file \c{myfile}. 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 \i\c{nasm.out} as the output file name instead. For situations in which this behaviour is unacceptable, NASM provides the \c{-o} command-line option, which allows you to specify your desired output file name. You invoke \c{-o} by following it with the name you wish for the output file, either with or without an intervening space. For example: \c nasm -f bin program.asm -o program.com \c 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 \k{opt-O}. \S{opt-f} The \i\c{-f} Option: Specifying the \i{Output File Format} If you do not supply the \c{-f} option to NASM, it will choose an output file format for you itself. In the distribution versions of NASM, the default is always \i\c{bin}; if you've compiled your own copy of NASM, you can redefine \i\c{OF_DEFAULT} at compile time and choose what you want the default to be. Like \c{-o}, the intervening space between \c{-f} and the output file format is optional; so \c{-f elf} and \c{-felf} are both valid. A complete list of the available output file formats can be given by issuing the command \i\c{nasm -hf}. \S{opt-l} The \i\c{-l} Option: Generating a \i{Listing File} If you supply the \c{-l} option to NASM, followed (with the usual optional space) by a file name, NASM will generate a \i{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 \k{nolist}) on the right. For example: \c 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 \c{[list -]}, and turn it back on with \c{[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. \S{opt-M} The \i\c{-M} Option: Generate \i{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: \c nasm -M myfile.asm > myfile.dep \S{opt-MG} The \i\c{-MG} Option: Generate \i{Makefile Dependencies} This option can be used to generate makefile dependencies on stdout. This differs from the \c{-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. \S{opt-MF} The \i\c\{-MF} Option: Set Makefile Dependency File This option can be used with the \c{-M} or \c{-MG} options to send the output to a file, rather than to stdout. For example: \c nasm -M -MF myfile.dep myfile.asm \S{opt-MD} The \i\c{-MD} Option: Assemble and Generate Dependencies The \c{-MD} option acts as the combination of the \c{-M} and \c{-MF} options (i.e. a filename has to be specified.) However, unlike the \c{-M} or \c{-MG} options, \c{-MD} does \e{not} inhibit the normal operation of the assembler. Use this to automatically generate updated dependencies with every assembly session. For example: \c nasm -f elf -o myfile.o -MD myfile.dep myfile.asm \S{opt-MT} The \i\c{-MT} Option: Dependency Target Name The \c{-MT} option can be used to override the default name of the dependency target. This is normally the same as the output filename, specified by the \c{-o} option. \S{opt-MQ} The \i\c{-MQ} Option: Dependency Target Name (Quoted) The \c{-MQ} option acts as the \c{-MT} option, except it tries to quote characters that have special meaning in Makefile syntax. This is not foolproof, as not all characters with special meaning are quotable in Make. The default output (if no \c{-MT} or \c{-MQ} option is specified) is automatically quoted. \S{opt-MP} The \i\c{-MP} Option: Emit phony targets When used with any of the dependency generation options, the \c{-MP} option causes NASM to emit a phony target without dependencies for each header file. This prevents Make from complaining if a header file has been removed. \S{opt-F} The \i\c{-F} Option: Selecting a \i{Debug Information Format} This option is used to select the format of the debug information emitted into the output file, to be used by a debugger (or \e{will} be). Prior to version 2.03.01, the use of this switch did \e{not} enable output of the selected debug info format. Use \c{-g}, see \k{opt-g}, to enable output. Versions 2.03.01 and later automatically enable \c{-g} if \c{-F} is specified. A complete list of the available debug file formats for an output format can be seen by issuing the command \c{nasm -f -y}. Not all output formats currently support debugging output. See \k{opt-y}. This should not be confused with the \c{-f dbg} output format option which is not built into NASM by default. For information on how to enable it when building from the sources, see \k{dbgfmt}. \S{opt-g} The \i\c{-g} Option: Enabling \i{Debug Information}. This option can be used to generate debugging information in the specified format. See \k{opt-F}. Using \c{-g} without \c{-F} results in emitting debug info in the default format, if any, for the selected output format. If no debug information is currently implemented in the selected output format, \c{-g} is \e{silently ignored}. \S{opt-X} The \i\c{-X} Option: Selecting an \i{Error Reporting Format} 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 \c{-Xvc} option and the \c{-Xgnu} option. The GNU format is the default and looks like this: \c filename.asm:65: error: specific error message where \c{filename.asm} is the name of the source file in which the error was detected, \c{65} is the source file line number on which the error was detected, \c{error} is the severity of the error (this could be \c{warning}), and \c{specific error message} is a more detailed text message which should help pinpoint the exact problem. The other format, specified by \c{-Xvc} is the style used by Microsoft Visual C++ and some other programs. It looks like this: \c 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 \c{Visual C++} output format, \k{win32fmt}. \S{opt-Z} The \i\c{-Z} Option: Send Errors to a File Under \I{DOS}\c{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 \i{error messages} on \i\c{stderr}, this can make it hard to capture the errors if (for example) you want to load them into an editor. NASM therefore provides the \c{-Z} option, taking a filename argument which causes errors to be sent to the specified files rather than standard error. Therefore you can \I{redirecting errors}redirect the errors into a file by typing \c nasm -Z myfile.err -f obj myfile.asm In earlier versions of NASM, this option was called \c{-E}, but it was changed since \c{-E} is an option conventionally used for preprocessing only, with disastrous results. See \k{opt-E}. \S{opt-s} The \i\c{-s} Option: Send Errors to \i\c{stdout} The \c{-s} option redirects \i{error messages} to \c{stdout} rather than \c{stderr}, so it can be redirected under \I{DOS}\c{MS-DOS}. To assemble the file \c{myfile.asm} and pipe its output to the \c{more} program, you can type: \c nasm -s -f obj myfile.asm | more See also the \c{-Z} option, \k{opt-Z}. \S{opt-i} The \i\c{-i}\I\c{-I} Option: Include File Search Directories When NASM sees the \i\c{%include} or \i\c{%pathsearch} directive in a source file (see \k{include}, \k{pathsearch} or \k{incbin}), it will search for the given file not only in the current directory, but also in any directories specified on the command line by the use of the \c{-i} option. Therefore you can include files from a \i{macro library}, for example, by typing \c nasm -ic:\macrolib\ -f obj myfile.asm (As usual, a space between \c{-i} and the path name is allowed, and optional). 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 \c{-i} option will be prepended exactly as written to the name of the include file. Therefore the trailing backslash in the above example is necessary. Under Unix, a trailing forward slash is similarly necessary. (You can use this to your advantage, if you're really \i{perverse}, by noting that the option \c{-ifoo} will cause \c{%include "bar.i"} to search for the file \c{foobar.i}...) If you want to define a \e{standard} \i{include search path}, similar to \c{/usr/include} on Unix systems, you should place one or more \c{-i} directives in the \c{NASMENV} environment variable (see \k{nasmenv}). For Makefile compatibility with many C compilers, this option can also be specified as \c{-I}. \S{opt-p} The \i\c{-p}\I\c{-P} Option: \I{pre-including files}Pre-Include a File \I\c{%include}NASM allows you to specify files to be \e{pre-included} into your source file, by the use of the \c{-p} option. So running \c nasm myfile.asm -p myinc.inc is equivalent to running \c{nasm myfile.asm} and placing the directive \c{%include "myinc.inc"} at the start of the file. For consistency with the \c{-I}, \c{-D} and \c{-U} options, this option can also be specified as \c{-P}. \S{opt-d} The \i\c{-d}\I\c{-D} Option: \I{pre-defining macros}Pre-Define a Macro \I\c{%define}Just as the \c{-p} option gives an alternative to placing \c{%include} directives at the start of a source file, the \c{-d} option gives an alternative to placing a \c{%define} directive. You could code \c nasm myfile.asm -dFOO=100 as an alternative to placing the directive \c %define FOO 100 at the start of the file. You can miss off the macro value, as well: the option \c{-dFOO} is equivalent to coding \c{%define FOO}. This form of the directive may be useful for selecting \i{assembly-time options} which are then tested using \c{%ifdef}, for example \c{-dDEBUG}. For Makefile compatibility with many C compilers, this option can also be specified as \c{-D}. \S{opt-u} The \i\c{-u}\I\c{-U} Option: \I{Undefining macros}Undefine a Macro \I\c{%undef}The \c{-u} option undefines a macro that would otherwise have been pre-defined, either automatically or by a \c{-p} or \c{-d} option specified earlier on the command lines. For example, the following command line: \c nasm myfile.asm -dFOO=100 -uFOO would result in \c{FOO} \e{not} being a predefined macro in the program. This is useful to override options specified at a different point in a Makefile. For Makefile compatibility with many C compilers, this option can also be specified as \c{-U}. \S{opt-E} The \i\c{-E}\I{-e} Option: Preprocess Only NASM allows the \i{preprocessor} to be run on its own, up to a point. Using the \c{-E} option (which requires no arguments) will cause NASM to preprocess its input file, expand all the macro references, remove all the comments and preprocessor directives, and print the resulting file on standard output (or save it to a file, if the \c{-o} option is also used). This option cannot be applied to programs which require the preprocessor to evaluate \I{preprocessor expressions}\i{expressions} which depend on the values of symbols: so code such as \c %assign tablesize ($-tablestart) will cause an error in \i{preprocess-only mode}. For compatiblity with older version of NASM, this option can also be written \c{-e}. \c{-E} in older versions of NASM was the equivalent of the current \c{-Z} option, \k{opt-Z}. \S{opt-a} The \i\c{-a} Option: Don't Preprocess At All If NASM is being used as the back end to a compiler, it might be desirable to \I{suppressing preprocessing}suppress preprocessing completely and assume the compiler has already done it, to save time and increase compilation speeds. The \c{-a} option, requiring no argument, instructs NASM to replace its powerful \i{preprocessor} with a \i{stub preprocessor} which does nothing. \S{opt-O} The \i\c{-O} Option: Specifying \i{Multipass Optimization} Using the \c{-O} option, you can tell NASM to carry out different levels of optimization. The syntax is: \b \c{-O0}: No optimization. All operands take their long forms, if a short form is not specified, except conditional jumps. This is intended to match NASM 0.98 behavior. \b \c{-O1}: Minimal optimization. As above, but immediate operands which will fit in a signed byte are optimized, unless the long form is specified. Conditional jumps default to the long form unless otherwise specified. \b \c{-Ox} (where \c{x} is the actual letter \c{x}): Multipass optimization. Minimize branch offsets and signed immediate bytes, overriding size specification unless the \c{strict} keyword has been used (see \k{strict}). For compatibility with earlier releases, the letter \c{x} may also be any number greater than one. This number has no effect on the actual number of passes. The \c{-Ox} mode is recommended for most uses, and is the default since NASM 2.09. Note that this is a capital \c{O}, and is different from a small \c{o}, which is used to specify the output file name. See \k{opt-o}. \S{opt-t} The \i\c{-t} Option: Enable TASM Compatibility Mode NASM includes a limited form of compatibility with Borland's \i\c{TASM}. When NASM's \c{-t} option is used, the following changes are made: \b local labels may be prefixed with \c{@@} instead of \c{.} \b size override is supported within brackets. In TASM compatible mode, a size override inside square brackets changes the size of the operand, and not the address type of the operand as it does in NASM syntax. E.g. \c{mov eax,[DWORD val]} is valid syntax in TASM compatibility mode. Note that you lose the ability to override the default address type for the instruction. \b unprefixed forms of some directives supported (\c{arg}, \c{elif}, \c{else}, \c{endif}, \c{if}, \c{ifdef}, \c{ifdifi}, \c{ifndef}, \c{include}, \c{local}) \S{opt-w} The \i\c{-w} and \i\c{-W} Options: Enable or Disable Assembly \i{Warnings} 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 \c{-w} command-line option, which enables or disables certain classes of assembly warning. Such warning classes are described by a name, for example \c{orphan-labels}; you can enable warnings of this class by the command-line option \c{-w+orphan-labels} and disable it by \c{-w-orphan-labels}. The \i{suppressible warning} classes are: \b \i\c{macro-params} covers warnings about \i{multi-line macros} being invoked with the wrong number of parameters. This warning class is enabled by default; see \k{mlmacover} for an example of why you might want to disable it. \b \i\c{macro-selfref} warns if a macro references itself. This warning class is disabled by default. \b\i\c{macro-defaults} warns when a macro has more default parameters than optional parameters. This warning class is enabled by default; see \k{mlmacdef} for why you might want to disable it. \b \i\c{orphan-labels} covers warnings about source lines which contain no instruction but define a label without a trailing colon. NASM warns about this somewhat obscure condition by default; see \k{syntax} for more information. \b \i\c{number-overflow} covers warnings about numeric constants which don't fit in 64 bits. This warning class is enabled by default. \b \i\c{gnu-elf-extensions} warns if 8-bit or 16-bit relocations are used in \c{-f elf} format. The GNU extensions allow this. This warning class is disabled by default. \b \i\c{float-overflow} warns about floating point overflow. Enabled by default. \b \i\c{float-denorm} warns about floating point denormals. Disabled by default. \b \i\c{float-underflow} warns about floating point underflow. Disabled by default. \b \i\c{float-toolong} warns about too many digits in floating-point numbers. Enabled by default. \b \i\c{user} controls \c{%warning} directives (see \k{pperror}). Enabled by default. \b \i\c{lock} warns about \c{LOCK} prefixes on unlockable instructions. Enabled by default. \b \i\c{hle} warns about invalid use of the HLE \c{XACQUIRE} or \c{XRELEASE} prefixes. Enabled by default. \b \i\c{bnd} warns about ineffective use of the \c{BND} prefix when a relaxed form of jmp instruction becomes jmp short form. Enabled by default. \b \i\c{error} causes warnings to be treated as errors. Disabled by default. \b \i\c{all} is an alias for \e{all} suppressible warning classes (not including \c{error}). Thus, \c{-w+all} enables all available warnings. In addition, you can set warning classes across sections. Warning classes may be enabled with \i\c{[warning +warning-name]}, disabled with \i\c{[warning -warning-name]} or reset to their original value with \i\c{[warning *warning-name]}. No "user form" (without the brackets) exists. Since version 2.00, NASM has also supported the gcc-like syntax \c{-Wwarning} and \c{-Wno-warning} instead of \c{-w+warning} and \c{-w-warning}, respectively. \S{opt-v} The \i\c{-v} Option: Display \i{Version} Info Typing \c{NASM -v} will display the version of NASM which you are using, and the date on which it was compiled. You will need the version number if you report a bug. For command-line compatibility with Yasm, the form \i\c{--v} is also accepted for this option. \S{opt-y} The \i\c{-y} Option: Display Available Debug Info Formats Typing \c{nasm -f