\# \# Source code to NASM documentation \# \M{category}{Programming} \M{title}{NASM - The Netwide Assembler} \M{year}{2007} \M{author}{The NASM Development Team} \M{license}{All rights reserved. This document is redistributable under the license given in the file "COPYING" 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} \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{-MG} \c{-MG} option \IR{-On} \c{-On} 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{-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{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{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{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{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{unix} Unix \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{whatsnew} Documentation Changes for Version 2.00 \S{p64Bit} 64-Bit Support \b Writing 64-bit Code \k{64bit} \b elf32 and elf64 output formats \k{elffmt} \b win64 output format \k{win64fmt} \b Numeric constants in DQ directive \k{db} \b oword, do and reso \k{db} \b Stack Relative Preprocessor Directives \k{stackrel} \S{fpenhance} Floating Point Enhancements \b 8-, 16- and 128-bit floating-point format \k{fltconst} \b Floating-point option control \k{FLOAT} \b Infinity and NaN \k{fltconst} \S{elfenhance} ELF Enhancements \b Symbol Visibility \k{elfglob} \b Setting OSABI value in ELF header \k{abisect} \b Debug Formats \k{elfdbg} \S{cmdenhance} Command Line Options \b Generate Makefile Dependencies \k{opt-MG} \b Send Errors to a File \k{opt-Z} \b Unlimited Optimization Passes \k{opt-On} \S{oenhance} Other Enhancements \b %IFN and %ELIFN \k{condasm} \b Logical Negation Operator \c{!} \k{expmul} \b Current BITS Mode \k{bitsm} \b Use of \c{%+} \k{concat%+} \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 from the upto and including \c{Pentium}, \c{P6}, \c{MMX}, \c{3DNow!}, \c{SSE}, \c{SSE2}, \c{SSE3} and \c{x64} opcodes. NASM has a strong support for macro conventions. \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} License Conditions Please see the file \c{COPYING}, supplied as part of any NASM distribution archive, for the \i{license} conditions under which you may use NASM. NASM is now under the so-called GNU Lesser General Public License, LGPL. \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{WWW page} at \W{http://nasm.sourceforge.net}\c{http://nasm.sourceforge.net}. If it's not there, google for us! The original authors are \i{e\-mail}able as \W{mailto:jules@dsf.org.uk}\c{jules@dsf.org.uk} and \W{mailto:anakin@pobox.com}\c{anakin@pobox.com}. The latter is no longer involved in the development team. \i{New releases} of NASM are uploaded to the official sites \W{http://nasm.sourceforge.net}\c{http://nasm.sourceforge.net} and to \W{ftp://ftp.kernel.org/pub/software/devel/nasm/}\i\c{ftp.kernel.org} and \W{ftp://ibiblio.org/pub/Linux/devel/lang/assemblers/}\i\c{ibiblio.org}. Announcements are posted to \W{news:comp.lang.asm.x86}\i\c{comp.lang.asm.x86}, \W{news:alt.lang.asm}\i\c{alt.lang.asm} and \W{news:comp.os.linux.announce}\i\c{comp.os.linux.announce} If you want information about NASM beta releases, and the current development status, please subscribe to the \i\c{nasm-devel} email list by registering at \W{http://sourceforge.net/projects/nasm}\c{http://sourceforge.net/projects/nasm}. \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 (\i\c{obj} and \i\c{win32}), 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 (\i\c{aout}, \i\c{coff}, \i\c{elf}, \i\c{macho} and \i\c{as86}) it will substitute \c{.o}. For \i\c{rdf}, it will use \c{.rdf}, and for the \i\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-On}. \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-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). Use of this switch does \e{not} enable output of the selected debug info format. Use \c{-g}, see \k{opt-g}, to enable output. A complete list of the available debug file formats for an output format can be seen by issuing the command \i\c{nasm -f -y}. (As of 2.00, only "-f elf32", "-f elf64", "-f ieee", and "-f obj" provide debug information.) See \k{opt-y}. This should not be confused with the "-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{incbin} directive in a source file (see \k{include} 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-On} The \i\c{-On} Option: Specifying \i{Multipass Optimization}. NASM defaults to being a two pass assembler. This means that if you have a complex source file which needs more than 2 passes to assemble optimally, you have to enable extra passes. Using the \c{-O} option, you can tell NASM to carry out multiple passes. The syntax is: \b \c{-O0} strict two-pass assembly, JMP and Jcc are handled more like v0.98, except that backward JMPs are short, if possible. Immediate operands take their long forms if a short form is not specified. \b \c{-O1} strict two-pass assembly, but forward branches are assembled with code guaranteed to reach; may produce larger code than -O0, but will produce successful assembly more often if branch offset sizes are not specified. Additionally, immediate operands which will fit in a signed byte are optimized, unless the long form is specified. \b \c{-On} multi-pass optimization, minimize branch offsets; also will minimize signed immediate bytes, overriding size specification unless the \c{strict} keyword has been used (see \k{strict}). The number specifies the maximum number of passes. The more passes, the better the code, but the slower is the assembly. \b \c{-Ox} where \c{x} is the actual letter \c{x}, indicates to NASM to do unlimited passes. 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} Option: 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 enabled by default. \b \i\c{orphan-labels} covers warnings about source lines which contain no instruction but define a label without a trailing colon. NASM does not warn about this somewhat obscure condition by default; see \k{syntax} for an example of why you might want it to. \b \i\c{number-overflow} covers warnings about numeric constants which don't fit in 32 bits (for example, it's easy to type one too many Fs and produce \c{0x7ffffffff} by mistake). 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 enabled by default. \b In addition, warning classes may be enabled or disabled across sections of source code with \i\c{[warning +warning-name]} or \i\c{[warning -warning-name]}. No "user form" (without the brackets) exists. \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. \S{opt-y} The \i\c{-y} Option: Display Available Debug Info Formats Typing \c{nasm -f