{\rtf1\ansi{\fonttbl \f0\froman Times New Roman;\f1\fmodern Courier New; \f2\fswiss Arial;\f3\ftech Wingdings}\deff0 #{\footnote Top} ${\footnote Contents} +{\footnote browse:00000} !{\footnote DisableButton("btn_up")} \keepn\f2\b\fs30\sb0 NASM: The Netwide Assembler \par\pard\plain\sb120 This file documents NASM, the Netwide Assembler: an assembler targetting the Intel x86 series of processors, with portable source. \par\sb120 \li360\fi-360 {\uldb Chapter 1: Introduction}{\v chapter_1}\par\sb0 {\uldb Chapter 2: Running NASM}{\v chapter_2}\par\sb0 {\uldb Chapter 3: The NASM Language}{\v chapter_3}\par\sb0 {\uldb Chapter 4: The NASM Preprocessor}{\v chapter_4}\par\sb0 {\uldb Chapter 5: Assembler Directives}{\v chapter_5}\par\sb0 {\uldb Chapter 6: Output Formats}{\v chapter_6}\par\sb0 {\uldb Chapter 7: Writing 16-bit Code (DOS, Windows 3/3.1)}{\v chapter_7}\par\sb0 {\uldb Chapter 8: Writing 32-bit Code (Unix, Win32, DJGPP)}{\v chapter_8}\par\sb0 {\uldb Chapter 9: Mixing 16 and 32 Bit Code}{\v chapter_9}\par\sb0 {\uldb Chapter 10: Troubleshooting}{\v chapter_10}\par\sb0 {\uldb Appendix A: Ndisasm}{\v appendix_a}\par\sb0 {\uldb Appendix B: x86 Instruction Reference}{\v appendix_b}\par\sb0 \pard\sb120 \page #{\footnote chapter_1} ${\footnote Chapter 1: Introduction} +{\footnote browse:00001} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`top')"); EnableButton("btn_up")} \keepn\f2\b\fs30\sb60\sa60 Chapter 1: Introduction \par\pard\plain\sb120 \li360\fi-360 {\uldb Section 1.1: What Is NASM?}{\v section_1_1}\par\sb0 {\uldb Section 1.2: Contact Information}{\v section_1_2}\par\sb0 {\uldb Section 1.3: Installation}{\v section_1_3}\par\sb0 \pard\sb120 \page #{\footnote section_1_1} ${\footnote 1.1. What Is NASM?} +{\footnote browse:00002} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`chapter_1')"); EnableButton("btn_up")} \keepn\f2\b\fs30\sb60\sa60 1.1. What Is NASM? \par\pard\plain\sb120 The Netwide Assembler, NASM, is an 80x86 assembler designed for portability and modularity. It supports a range of object file formats, including Linux and {\f1 NetBSD/FreeBSD} {\f1 a.out}, {\f1 ELF}, {\f1 COFF}, Microsoft 16-bit {\f1 OBJ} and {\f1 Win32}. 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 {\f1 Pentium}, {\f1 P6}, {\f1 MMX}, {\f1 3DNow!}, {\f1 SSE} and {\f1 SSE2} opcodes, and has macro capability. \par\sb120 \li360\fi-360 {\uldb Section 1.1.1: Why Yet Another Assembler?}{\v section_1_1_1}\par\sb0 {\uldb Section 1.1.2: Licence Conditions}{\v section_1_1_2}\par\sb0 \pard\sb120 \page #{\footnote section_1_1_1} ${\footnote 1.1.1. Why Yet Another Assembler?} +{\footnote browse:00003} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_1_1')"); EnableButton("btn_up")} K{\footnote a86; alt.lang.asm; as86; comp.lang.asm.x86; gas; gcc; MASM; TASM} \keepn\f2\b\fs30\sb60\sa60 1.1.1. Why Yet Another Assembler? \par\pard\plain\sb120 The Netwide Assembler grew out of an idea on {\f1 comp.lang.asm.x86} (or possibly {\f1 alt.lang.asm} \'96 I forget which), which was essentially that there didn't seem to be a good {\i free} x86-series assembler around, and that maybe someone ought to write one. \par\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 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. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 gas} is free, and ports over DOS and Unix, but it's not very good, since it's designed to be a back end to {\f1 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 {\i write} anything in it. Plus you can't write 16-bit code in it (properly). \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 as86} is Minix- and Linux-specific, and (my version at least) doesn't seem to have much (or any) documentation. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 MASM} isn't very good, and it's (was) expensive, and it runs only under DOS. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 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. \par\pard\sb120 So here, for your coding pleasure, is NASM. At present it's still in prototype stage \'96 we don't promise that it can outperform any of these assemblers. But please, {\i 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. \par\sb120 \page #{\footnote section_1_1_2} ${\footnote 1.1.2. Licence Conditions} +{\footnote browse:00004} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_1_1')"); EnableButton("btn_up")} K{\footnote licence} \keepn\f2\b\fs30\sb60\sa60 1.1.2. Licence Conditions \par\pard\plain\sb120 Please see the file {\f1 COPYING}, supplied as part of any NASM distribution archive, for the licence conditions under which you may use NASM. NASM is now under the so-called GNU Lesser General Public License, LGPL. \par\sb120 \page #{\footnote section_1_2} ${\footnote 1.2. Contact Information} +{\footnote browse:00005} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`chapter_1')"); EnableButton("btn_up")} K{\footnote alt.lang.asm; comp.lang.asm.x86; comp.os.linux.announce; e\'ADmail; ftp.kernel.org; ibiblio.org; nasm\'ADdevel; new releases; WWW page} \keepn\f2\b\fs30\sb60\sa60 1.2. Contact Information \par\pard\plain\sb120 The current version of NASM (since about 0.98.08) are maintained by a team of developers, accessible through the {\f1 nasm\'ADdevel} mailing list (see below for the link). If you want to report a bug, please read {\uldb section 10.2}{\v section_10_2} first. \par\sb120 NASM has a WWW page at {\f1 http://nasm.sourceforge.net}. If it's not there, google for us! \par\sb120 The original authors are e\'ADmailable as {\f1 jules@dsf.org.uk} and {\f1 anakin@pobox.com}. The latter is no longer involved in the development team. \par\sb120 New releases of NASM are uploaded to the official sites {\f1 http://nasm.sourceforge.net} and to {\f1 ftp.kernel.org} and {\f1 ibiblio.org}. \par\sb120 Announcements are posted to {\f1 comp.lang.asm.x86}, {\f1 alt.lang.asm} and {\f1 comp.os.linux.announce} \par\sb120 If you want information about NASM beta releases, and the current development status, please subscribe to the {\f1 nasm\'ADdevel} email list by registering at {\f1 http://sourceforge.net/projects/nasm}. \par\sb120 \page #{\footnote section_1_3} ${\footnote 1.3. Installation} +{\footnote browse:00006} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`chapter_1')"); EnableButton("btn_up")} \keepn\f2\b\fs30\sb60\sa60 1.3. Installation \par\pard\plain\sb120 \li360\fi-360 {\uldb Section 1.3.1: Installing NASM under MS-DOS or Windows}{\v section_1_3_1}\par\sb0 {\uldb Section 1.3.2: Installing NASM under Unix}{\v section_1_3_2}\par\sb0 \pard\sb120 \page #{\footnote section_1_3_1} ${\footnote 1.3.1. Installing NASM under MS-DOS or Windows} +{\footnote browse:00007} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_1_3')"); EnableButton("btn_up")} K{\footnote autoexec.bat; DOS; DOS archive; DOS source archive; installing; makefiles; nasm.exe; nasmw.exe; nasmXXXs.zip; nasmXXX.zip; ndisasm.exe; ndisasmw.exe; PATH; Perl; source code; Win32; Windows 95; Windows NT; www.cpan.org} \keepn\f2\b\fs30\sb60\sa60 1.3.1. Installing NASM under MS-DOS or Windows \par\pard\plain\sb120 Once you've obtained the DOS archive for NASM, {\f1 nasmXXX.zip} (where {\f1 XXX} denotes the version number of NASM contained in the archive), unpack it into its own directory (for example {\f1 c:\\nasm}). \par\sb120 The archive will contain four executable files: the NASM executable files {\f1 nasm.exe} and {\f1 nasmw.exe}, and the NDISASM executable files {\f1 ndisasm.exe} and {\f1 ndisasmw.exe}. In each case, the file whose name ends in {\f1 w} is a {\f1 Win32} executable, designed to run under {\f1 Windows\'A095} or {\f1 Windows\'A0NT} Intel, and the other one is a 16-bit {\f1 DOS} executable. \par\sb120 The only file NASM needs to run is its own executable, so copy (at least) one of {\f1 nasm.exe} and {\f1 nasmw.exe} to a directory on your PATH, or alternatively edit {\f1 autoexec.bat} to add the {\f1 nasm} directory to your {\f1 PATH}. (If you're only installing the {\f1 Win32} version, you may wish to rename it to {\f1 nasm.exe}.) \par\sb120 That's it \'96 NASM is installed. You don't need the nasm directory to be present to run NASM (unless you've added it to your {\f1 PATH}), so you can delete it if you need to save space; however, you may want to keep the documentation or test programs. \par\sb120 If you've downloaded the DOS source archive, {\f1 nasmXXXs.zip}, the {\f1 nasm} directory will also contain the full NASM source code, and a selection of Makefiles you can (hopefully) use to rebuild your copy of NASM from scratch. \par\sb120 Note that the source files {\f1 insnsa.c}, {\f1 insnsd.c}, {\f1 insnsi.h} and {\f1 insnsn.c} are automatically generated from the master instruction table {\f1 insns.dat} by a Perl script; the file {\f1 macros.c} is generated from {\f1 standard.mac} by another Perl script. 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 Perl for a variety of platforms, including DOS and Windows, are available from www.cpan.org. \par\sb120 \page #{\footnote section_1_3_2} ${\footnote 1.3.2. Installing NASM under Unix} +{\footnote browse:00008} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_1_3')"); EnableButton("btn_up")} K{\footnote Autoconf; configure; INSTALL; make; makefiles; Makefile.unx; man pages; nasm.1; nasm\'ADX.XX.tar.gz; ndisasm.1; rdoff subdirectory; Unix; Unix, source archive} \keepn\f2\b\fs30\sb60\sa60 1.3.2. Installing NASM under Unix \par\pard\plain\sb120 Once you've obtained the Unix source archive for NASM, {\f1 nasm\'ADX.XX.tar.gz} (where {\f1 X.XX} denotes the version number of NASM contained in the archive), unpack it into a directory such as {\f1 /usr/local/src}. The archive, when unpacked, will create its own subdirectory {\f1 nasm\'ADX.XX}. \par\sb120 NASM is an auto-configuring package: once you've unpacked it, {\f1 cd} to the directory it's been unpacked into and type {\f1 ./configure}. This shell script will find the best C compiler to use for building NASM and set up Makefiles accordingly. \par\sb120 Once NASM has auto-configured, you can type {\f1 make} to build the {\f1 nasm} and {\f1 ndisasm} binaries, and then {\f1 make\'A0install} to install them in {\f1 /usr/local/bin} and install the man pages {\f1 nasm.1} and {\f1 ndisasm.1} in {\f1 /usr/local/man/man1}. Alternatively, you can give options such as {\f1 \'AD\'ADprefix} to the configure script (see the file {\f1 INSTALL} for more details), or install the programs yourself. \par\sb120 NASM also comes with a set of utilities for handling the {\f1 RDOFF} custom object-file format, which are in the {\f1 rdoff} subdirectory of the NASM archive. You can build these with {\f1 make\'A0rdf} and install them with {\f1 make\'A0rdf_install}, if you want them. \par\sb120 If NASM fails to auto-configure, you may still be able to make it compile by using the fall-back Unix makefile {\f1 Makefile.unx}. Copy or rename that file to {\f1 Makefile} and try typing {\f1 make}. There is also a Makefile.unx file in the {\f1 rdoff} subdirectory. \par\sb120 \page #{\footnote chapter_2} ${\footnote Chapter 2: Running NASM} +{\footnote browse:00009} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`top')"); EnableButton("btn_up")} \keepn\f2\b\fs30\sb60\sa60 Chapter 2: Running NASM \par\pard\plain\sb120 \li360\fi-360 {\uldb Section 2.1: NASM Command\'ADLine Syntax}{\v section_2_1}\par\sb0 {\uldb Section 2.2: Quick Start for MASM Users}{\v section_2_2}\par\sb0 \pard\sb120 \page #{\footnote section_2_1} ${\footnote 2.1. NASM Command\'ADLine Syntax} +{\footnote browse:00010} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`chapter_2')"); EnableButton("btn_up")} K{\footnote command\'ADline} \keepn\f2\b\fs30\sb60\sa60 2.1. NASM Command\'ADLine Syntax \par\pard\plain\sb120 To assemble a file, you issue a command of the form \par\sb120 \keep\f1\sb120 nasm -f [-o ]\par\sb0 \pard\f0\sb120 For example, \par\sb120 \keep\f1\sb120 nasm -f elf myfile.asm\par\sb0 \pard\f0\sb120 will assemble {\f1 myfile.asm} into an {\f1 ELF} object file {\f1 myfile.o}. And \par\sb120 \keep\f1\sb120 nasm -f bin myfile.asm -o myfile.com\par\sb0 \pard\f0\sb120 will assemble {\f1 myfile.asm} into a raw binary file {\f1 myfile.com}. \par\sb120 To produce a listing file, with the hex codes output from NASM displayed on the left of the original sources, use the {\f1 \'ADl} option to give a listing file name, for example: \par\sb120 \keep\f1\sb120 nasm -f coff myfile.asm -l myfile.lst\par\sb0 \pard\f0\sb120 To get further usage instructions from NASM, try typing \par\sb120 \keep\f1\sb120 nasm -h\par\sb0 \pard\f0\sb120 As {\f1 \'ADhf}, this will also list the available output file formats, and what they are. \par\sb120 If you use Linux but aren't sure whether your system is {\f1 a.out} or {\f1 ELF}, type \par\sb120 \keep\f1\sb120 file nasm\par\sb0 \pard\f0\sb120 (in the directory in which you put the NASM binary when you installed it). If it says something like \par\sb120 \keep\f1\sb120 nasm: ELF 32-bit LSB executable i386 (386 and up) Version 1\par\sb0 \pard\f0\sb120 then your system is {\f1 ELF}, and you should use the option {\f1 \'ADf\'A0elf} when you want NASM to produce Linux object files. If it says \par\sb120 \keep\f1\sb120 nasm: Linux/i386 demand-paged executable (QMAGIC)\par\sb0 \pard\f0\sb120 or something similar, your system is {\f1 a.out}, and you should use {\f1 \'ADf\'A0aout} instead (Linux {\f1 a.out} systems have long been obsolete, and are rare these days.) \par\sb120 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. \par\sb120 \li360\fi-360 {\uldb Section 2.1.1: The \'ADo Option: Specifying the Output File Name}{\v section_2_1_1}\par\sb0 {\uldb Section 2.1.2: The \'ADf Option: Specifying the Output File Format}{\v section_2_1_2}\par\sb0 {\uldb Section 2.1.3: The \'ADl Option: Generating a Listing File}{\v section_2_1_3}\par\sb0 {\uldb Section 2.1.4: The \'ADM Option: Generate Makefile Dependencies.}{\v section_2_1_4}\par\sb0 {\uldb Section 2.1.5: The \'ADF Option: Selecting a Debug Information Format}{\v section_2_1_5}\par\sb0 {\uldb Section 2.1.6: The \'ADg Option: Enabling Debug Information.}{\v section_2_1_6}\par\sb0 {\uldb Section 2.1.7: The \'ADX Option: Selecting an Error Reporting Format}{\v section_2_1_7}\par\sb0 {\uldb Section 2.1.8: The \'ADE Option: Send Errors to a File}{\v section_2_1_8}\par\sb0 {\uldb Section 2.1.9: The \'ADs Option: Send Errors to stdout}{\v section_2_1_9}\par\sb0 {\uldb Section 2.1.10: The \'ADi Option: Include File Search Directories}{\v section_2_1_10}\par\sb0 {\uldb Section 2.1.11: The \'ADp Option: Pre-Include a File}{\v section_2_1_11}\par\sb0 {\uldb Section 2.1.12: The \'ADd Option: Pre-Define a Macro}{\v section_2_1_12}\par\sb0 {\uldb Section 2.1.13: The \'ADu Option: Undefine a Macro}{\v section_2_1_13}\par\sb0 {\uldb Section 2.1.14: The \'ADe Option: Preprocess Only}{\v section_2_1_14}\par\sb0 {\uldb Section 2.1.15: The \'ADa Option: Don't Preprocess At All}{\v section_2_1_15}\par\sb0 {\uldb Section 2.1.16: The \'ADOn Option: Specifying Multipass Optimization.}{\v section_2_1_16}\par\sb0 {\uldb Section 2.1.17: The \'ADt option: Enable TASM Compatibility Mode}{\v section_2_1_17}\par\sb0 {\uldb Section 2.1.18: The \'ADw Option: Enable or Disable Assembly Warnings}{\v section_2_1_18}\par\sb0 {\uldb Section 2.1.19: The \'ADv Option: Display Version Info}{\v section_2_1_19}\par\sb0 {\uldb Section 2.1.20: The \'ADy Option: Display Available Debug Info Formats}{\v section_2_1_20}\par\sb0 {\uldb Section 2.1.21: The \'AD\'ADprefix and \'AD\'ADpostfix Options.}{\v section_2_1_21}\par\sb0 {\uldb Section 2.1.22: The NASMENV Environment Variable}{\v section_2_1_22}\par\sb0 \pard\sb120 \page #{\footnote section_2_1_1} ${\footnote 2.1.1. The \'ADo Option: Specifying the Output File Name} +{\footnote browse:00011} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote aout; as86; bin; coff; ELF; extension; nasm.out; \'ADo option; obj; rdf; Win32} \keepn\f2\b\fs30\sb60\sa60 2.1.1. The {\f1 \'ADo} Option: Specifying the Output File Name \par\pard\plain\sb120 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 ({\f1 obj} and {\f1 win32}), it will remove the {\f1 .asm} extension (or whatever extension you like to use \'96 NASM doesn't care) from your source file name and substitute {\f1 .obj}. For Unix object file formats ({\f1 aout}, {\f1 coff}, {\f1 elf} and {\f1 as86}) it will substitute {\f1 .o}. For {\f1 rdf}, it will use {\f1 .rdf}, and for the {\f1 bin} format it will simply remove the extension, so that {\f1 myfile.asm} produces the output file {\f1 myfile}. \par\sb120 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 {\f1 nasm.out} as the output file name instead. \par\sb120 For situations in which this behaviour is unacceptable, NASM provides the {\f1 \'ADo} command-line option, which allows you to specify your desired output file name. You invoke {\f1 \'ADo} by following it with the name you wish for the output file, either with or without an intervening space. For example: \par\sb120 \keep\f1\sb120 nasm -f bin program.asm -o program.com \par\sb0 nasm -f bin driver.asm -odriver.sys\par\sb0 \pard\f0\sb120 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 {\uldb section 2.1.16}{\v section_2_1_16}. \par\sb120 \page #{\footnote section_2_1_2} ${\footnote 2.1.2. The \'ADf Option: Specifying the Output File Format} +{\footnote browse:00012} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote bin; \'ADf option; nasm\'A0\'ADhf; OF_DEFAULT; output file format} \keepn\f2\b\fs30\sb60\sa60 2.1.2. The {\f1 \'ADf} Option: Specifying the Output File Format \par\pard\plain\sb120 If you do not supply the {\f1 \'ADf} option to NASM, it will choose an output file format for you itself. In the distribution versions of NASM, the default is always {\f1 bin}; if you've compiled your own copy of NASM, you can redefine {\f1 OF_DEFAULT} at compile time and choose what you want the default to be. \par\sb120 Like {\f1 \'ADo}, the intervening space between {\f1 \'ADf} and the output file format is optional; so {\f1 \'ADf\'A0elf} and {\f1 \'ADfelf} are both valid. \par\sb120 A complete list of the available output file formats can be given by issuing the command {\f1 nasm\'A0\'ADhf}. \par\sb120 \page #{\footnote section_2_1_3} ${\footnote 2.1.3. The \'ADl Option: Generating a Listing File} +{\footnote browse:00013} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADl option; listing file; source\'ADlisting file} \keepn\f2\b\fs30\sb60\sa60 2.1.3. The {\f1 \'ADl} Option: Generating a Listing File \par\pard\plain\sb120 If you supply the {\f1 \'ADl} option to NASM, followed (with the usual optional space) by a file name, NASM will generate a source\'ADlisting 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 {\uldb section 4.3.9}{\v section_4_3_9}) on the right. For example: \par\sb120 \keep\f1\sb120 nasm -f elf myfile.asm -l myfile.lst\par\sb0 \pard\f0\sb120 If a list file is selected, you may turn off listing for a section of your source with {\f1 [list\'A0\'AD]}, and turn it back on with {\f1 [list\'A0+]}, (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. \par\sb120 \page #{\footnote section_2_1_4} ${\footnote 2.1.4. The \'ADM Option: Generate Makefile Dependencies.} +{\footnote browse:00014} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADM option; makefile dependencies} \keepn\f2\b\fs30\sb60\sa60 2.1.4. The {\f1 \'ADM} Option: Generate Makefile Dependencies. \par\pard\plain\sb120 This option can be used to generate makefile dependencies on stdout. This can be redirected to a file for further processing. For example: \par\sb120 \keep\f1\sb120 NASM -M myfile.asm > myfile.dep\par\sb0 \pard\f0\sb120 \page #{\footnote section_2_1_5} ${\footnote 2.1.5. The \'ADF Option: Selecting a Debug Information Format} +{\footnote browse:00015} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote debug information format; \'ADF option; nasm\'A0\'ADf\'A0\'A0\'ADy} \keepn\f2\b\fs30\sb60\sa60 2.1.5. The {\f1 \'ADF} Option: Selecting a Debug Information Format \par\pard\plain\sb120 This option is used to select the format of the debug information emitted into the output file, to be used by a debugger (or {\i will} be). Use of this switch does {\i not} enable output of the selected debug info format. Use {\f1 \'ADg}, see {\uldb section 2.1.6}{\v section_2_1_6}, to enable output. \par\sb120 A complete list of the available debug file formats for an output format can be seen by issuing the command {\f1 nasm\'A0\'ADf\'A0\'A0\'ADy}. (only "borland" in "-f obj", as of 0.98.35, but "watch this space") See: {\uldb section 2.1.20}{\v section_2_1_20}. \par\sb120 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 {\uldb section 6.10}{\v section_6_10} \par\sb120 \page #{\footnote section_2_1_6} ${\footnote 2.1.6. The \'ADg Option: Enabling Debug Information.} +{\footnote browse:00016} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote debug information; \'ADg option} \keepn\f2\b\fs30\sb60\sa60 2.1.6. The {\f1 \'ADg} Option: Enabling Debug Information. \par\pard\plain\sb120 This option can be used to generate debugging information in the specified format. See: {\uldb section 2.1.5}{\v section_2_1_5}. Using {\f1 \'ADg} without {\f1 \'ADF} 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, {\f1 \'ADg} is {\i silently ignored}. \par\sb120 \page #{\footnote section_2_1_7} ${\footnote 2.1.7. The \'ADX Option: Selecting an Error Reporting Format} +{\footnote browse:00017} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote error reporting format; \'ADX option} \keepn\f2\b\fs30\sb60\sa60 2.1.7. The {\f1 \'ADX} Option: Selecting an Error Reporting Format \par\pard\plain\sb120 This option can be used to select an error reporting format for any error messages that might be produced by NASM. \par\sb120 Currently, two error reporting formats may be selected. They are the {\f1 \'ADXvc} option and the {\f1 \'ADXgnu} option. The GNU format is the default and looks like this: \par\sb120 \keep\f1\sb120 filename.asm:65: error: specific error message \par\sb0 \pard\f0\sb120 where {\f1 filename.asm} is the name of the source file in which the error was detected, {\f1 65} is the source file line number on which the error was detected, {\f1 error} is the severity of the error (this could be {\f1 warning}), and {\f1 specific\'A0error\'A0message} is a more detailed text message which should help pinpoint the exact problem. \par\sb120 The other format, specified by {\f1 \'ADXvc} is the style used by Microsoft Visual C++ and some other programs. It looks like this: \par\sb120 \keep\f1\sb120 filename.asm(65) : error: specific error message\par\sb0 \pard\f0\sb120 where the only difference is that the line number is in parentheses instead of being delimited by colons. \par\sb120 See also the {\f1 Visual\'A0C++} output format, {\uldb section 6.3}{\v section_6_3}. \par\sb120 \page #{\footnote section_2_1_8} ${\footnote 2.1.8. The \'ADE Option: Send Errors to a File} +{\footnote browse:00018} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote DOS; \'ADE option; error messages; redirecting errors; stderr} \keepn\f2\b\fs30\sb60\sa60 2.1.8. The {\f1 \'ADE} Option: Send Errors to a File \par\pard\plain\sb120 Under {\f1 MS\'ADDOS} 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 {\f1 stderr}, this can make it hard to capture the errors if (for example) you want to load them into an editor. \par\sb120 NASM therefore provides the {\f1 \'ADE} option, taking a filename argument which causes errors to be sent to the specified files rather than standard error. Therefore you can redirect the errors into a file by typing \par\sb120 \keep\f1\sb120 nasm -E myfile.err -f obj myfile.asm\par\sb0 \pard\f0\sb120 \page #{\footnote section_2_1_9} ${\footnote 2.1.9. The \'ADs Option: Send Errors to stdout} +{\footnote browse:00019} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote DOS; error messages; \'ADs option; stdout} \keepn\f2\b\fs30\sb60\sa60 2.1.9. The {\f1 \'ADs} Option: Send Errors to {\f1 stdout} \par\pard\plain\sb120 The {\f1 \'ADs} option redirects error messages to {\f1 stdout} rather than {\f1 stderr}, so it can be redirected under {\f1 MS\'ADDOS}. To assemble the file {\f1 myfile.asm} and pipe its output to the {\f1 more} program, you can type: \par\sb120 \keep\f1\sb120 nasm -s -f obj myfile.asm | more\par\sb0 \pard\f0\sb120 See also the {\f1 \'ADE} option, {\uldb section 2.1.8}{\v section_2_1_8}. \par\sb120 \page #{\footnote section_2_1_10} ${\footnote 2.1.10. The \'ADi Option: Include File Search Directories} +{\footnote browse:00020} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADI option; \'ADi option; incbin; %include; include search path; macro library; perverse} \keepn\f2\b\fs30\sb60\sa60 2.1.10. The {\f1 \'ADi} Option: Include File Search Directories \par\pard\plain\sb120 When NASM sees the {\f1 %include} or {\f1 incbin} directive in a source file (see {\uldb section 4.6}{\v section_4_6} or {\uldb section 3.2.3}{\v section_3_2_3}), 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 {\f1 \'ADi} option. Therefore you can include files from a macro library, for example, by typing \par\sb120 \keep\f1\sb120 nasm -ic:\\macrolib\\ -f obj myfile.asm\par\sb0 \pard\f0\sb120 (As usual, a space between {\f1 \'ADi} and the path name is allowed, and optional). \par\sb120 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 {\f1 \'ADi} 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. \par\sb120 (You can use this to your advantage, if you're really perverse, by noting that the option {\f1 \'ADifoo} will cause {\f1 %include\'A0"bar.i"} to search for the file {\f1 foobar.i}...) \par\sb120 If you want to define a {\i standard} include search path, similar to {\f1 /usr/include} on Unix systems, you should place one or more {\f1 \'ADi} directives in the {\f1 NASMENV} environment variable (see {\uldb section 2.1.22}{\v section_2_1_22}). \par\sb120 For Makefile compatibility with many C compilers, this option can also be specified as {\f1 \'ADI}. \par\sb120 \page #{\footnote section_2_1_11} ${\footnote 2.1.11. The \'ADp Option: Pre-Include a File} +{\footnote browse:00021} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote %include; \'ADP option; \'ADp option; pre\'ADincluding files} \keepn\f2\b\fs30\sb60\sa60 2.1.11. The {\f1 \'ADp} Option: Pre-Include a File \par\pard\plain\sb120 NASM allows you to specify files to be {\i pre\'ADincluded} into your source file, by the use of the {\f1 \'ADp} option. So running \par\sb120 \keep\f1\sb120 nasm myfile.asm -p myinc.inc\par\sb0 \pard\f0\sb120 is equivalent to running {\f1 nasm\'A0myfile.asm} and placing the directive {\f1 %include\'A0"myinc.inc"} at the start of the file. \par\sb120 For consistency with the {\f1 \'ADI}, {\f1 \'ADD} and {\f1 \'ADU} options, this option can also be specified as {\f1 \'ADP}. \par\sb120 \page #{\footnote section_2_1_12} ${\footnote 2.1.12. The \'ADd Option: Pre-Define a Macro} +{\footnote browse:00022} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote assembly\'ADtime options; \'ADD option; \'ADd option; %define; pre\'ADdefining macros} \keepn\f2\b\fs30\sb60\sa60 2.1.12. The {\f1 \'ADd} Option: Pre-Define a Macro \par\pard\plain\sb120 Just as the {\f1 \'ADp} option gives an alternative to placing {\f1 %include} directives at the start of a source file, the {\f1 \'ADd} option gives an alternative to placing a {\f1 %define} directive. You could code \par\sb120 \keep\f1\sb120 nasm myfile.asm -dFOO=100\par\sb0 \pard\f0\sb120 as an alternative to placing the directive \par\sb120 \keep\f1\sb120 %define FOO 100\par\sb0 \pard\f0\sb120 at the start of the file. You can miss off the macro value, as well: the option {\f1 \'ADdFOO} is equivalent to coding {\f1 %define\'A0FOO}. This form of the directive may be useful for selecting assembly\'ADtime options which are then tested using {\f1 %ifdef}, for example {\f1 \'ADdDEBUG}. \par\sb120 For Makefile compatibility with many C compilers, this option can also be specified as {\f1 \'ADD}. \par\sb120 \page #{\footnote section_2_1_13} ${\footnote 2.1.13. The \'ADu Option: Undefine a Macro} +{\footnote browse:00023} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADU option; \'ADu option; %undef; undefining macros} \keepn\f2\b\fs30\sb60\sa60 2.1.13. The {\f1 \'ADu} Option: Undefine a Macro \par\pard\plain\sb120 The {\f1 \'ADu} option undefines a macro that would otherwise have been pre-defined, either automatically or by a {\f1 \'ADp} or {\f1 \'ADd} option specified earlier on the command lines. \par\sb120 For example, the following command line: \par\sb120 \keep\f1\sb120 nasm myfile.asm -dFOO=100 -uFOO\par\sb0 \pard\f0\sb120 would result in {\f1 FOO} {\i not} being a predefined macro in the program. This is useful to override options specified at a different point in a Makefile. \par\sb120 For Makefile compatibility with many C compilers, this option can also be specified as {\f1 \'ADU}. \par\sb120 \page #{\footnote section_2_1_14} ${\footnote 2.1.14. The \'ADe Option: Preprocess Only} +{\footnote browse:00024} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADe option; expressions; preprocess\'ADonly mode; preprocessor; preprocessor expressions} \keepn\f2\b\fs30\sb60\sa60 2.1.14. The {\f1 \'ADe} Option: Preprocess Only \par\pard\plain\sb120 NASM allows the preprocessor to be run on its own, up to a point. Using the {\f1 \'ADe} 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 {\f1 \'ADo} option is also used). \par\sb120 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 \par\sb120 \keep\f1\sb120 %assign tablesize ($-tablestart)\par\sb0 \pard\f0\sb120 will cause an error in preprocess\'ADonly mode. \par\sb120 \page #{\footnote section_2_1_15} ${\footnote 2.1.15. The \'ADa Option: Don't Preprocess At All} +{\footnote browse:00025} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADa option; preprocessor; stub preprocessor; suppressing preprocessing} \keepn\f2\b\fs30\sb60\sa60 2.1.15. The {\f1 \'ADa} Option: Don't Preprocess At All \par\pard\plain\sb120 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 {\f1 \'ADa} option, requiring no argument, instructs NASM to replace its powerful preprocessor with a stub preprocessor which does nothing. \par\sb120 \page #{\footnote section_2_1_16} ${\footnote 2.1.16. The \'ADOn Option: Specifying Multipass Optimization.} +{\footnote browse:00026} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote multipass optimization; \'ADOn option} \keepn\f2\b\fs30\sb60\sa60 2.1.16. The {\f1 \'ADOn} Option: Specifying Multipass Optimization. \par\pard\plain\sb120 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. \par\sb120 Using the {\f1 \'ADO} option, you can tell NASM to carry out multiple passes. The syntax is: \par\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 \'ADO0} 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. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 \'ADO1} strict two-pass assembly, but forward branches are assembled with code guaranteed to reach; may produce larger code than \'96O0, 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 optimised, unless the long form is specified. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 \'ADOn} multi-pass optimization, minimize branch offsets; also will minimize signed immediate bytes, overriding size specification unless the {\f1 strict} keyword has been used (see {\uldb section 3.7}{\v section_3_7}). The number specifies the maximum number of passes. The more passes, the better the code, but the slower is the assembly. \par\pard\sb120 Note that this is a capital O, and is different from a small o, which is used to specify the output format. See {\uldb section 2.1.1}{\v section_2_1_1}. \par\sb120 \page #{\footnote section_2_1_17} ${\footnote 2.1.17. The \'ADt option: Enable TASM Compatibility Mode} +{\footnote browse:00027} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADt; TASM} \keepn\f2\b\fs30\sb60\sa60 2.1.17. The {\f1 \'ADt} option: Enable TASM Compatibility Mode \par\pard\plain\sb120 NASM includes a limited form of compatibility with Borland's {\f1 TASM}. When NASM's {\f1 \'ADt} option is used, the following changes are made: \par\sb120 \tx360\li360\fi-360{\f3\'9F}\tab local labels may be prefixed with {\f1 @@} instead of {\f1 .} \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab TASM-style response files beginning with {\f1 @} may be specified on the command line. This is different from the {\f1 \'AD@resp} style that NASM natively supports. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab 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. {\f1 mov\'A0eax,[DWORD\'A0val]} is valid syntax in TASM compatibility mode. Note that you lose the ability to override the default address type for the instruction. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 %arg} preprocessor directive is supported which is similar to TASM's {\f1 ARG} directive. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 %local} preprocessor directive \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 %stacksize} preprocessor directive \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab unprefixed forms of some directives supported ({\f1 arg}, {\f1 elif}, {\f1 else}, {\f1 endif}, {\f1 if}, {\f1 ifdef}, {\f1 ifdifi}, {\f1 ifndef}, {\f1 include}, {\f1 local}) \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab more... \par\pard\sb120 For more information on the directives, see the section on TASM Compatiblity preprocessor directives in {\uldb section 4.9}{\v section_4_9}. \par\sb120 \page #{\footnote section_2_1_18} ${\footnote 2.1.18. The \'ADw Option: Enable or Disable Assembly Warnings} +{\footnote browse:00028} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote gnu\'ADelf\'ADextensions; macro\'ADparams; macro\'ADselfref; multi\'ADline macros; number\'ADoverflow; orphan\'ADlabels; suppressible warning; \'ADw option; warnings; [warning\'A0+warning\'ADname]; [warning\'A0\'ADwarning\'ADname]} \keepn\f2\b\fs30\sb60\sa60 2.1.18. The {\f1 \'ADw} Option: Enable or Disable Assembly Warnings \par\pard\plain\sb120 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. \par\sb120 Some conditions are even less severe than that: they are only sometimes worth mentioning to the user. Therefore NASM supports the {\f1 \'ADw} command-line option, which enables or disables certain classes of assembly warning. Such warning classes are described by a name, for example {\f1 orphan\'ADlabels}; you can enable warnings of this class by the command-line option {\f1 \'ADw+orphan\'ADlabels} and disable it by {\f1 \'ADw\'ADorphan\'ADlabels}. \par\sb120 The suppressible warning classes are: \par\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 macro\'ADparams} covers warnings about multi\'ADline macros being invoked with the wrong number of parameters. This warning class is enabled by default; see {\uldb section 4.3.1}{\v section_4_3_1} for an example of why you might want to disable it. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 macro\'ADselfref} warns if a macro references itself. This warning class is enabled by default. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 orphan\'ADlabels} 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 {\uldb section 3.1}{\v section_3_1} for an example of why you might want it to. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 number\'ADoverflow} 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 {\f1 0x7ffffffff} by mistake). This warning class is enabled by default. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab {\f1 gnu\'ADelf\'ADextensions} warns if 8-bit or 16-bit relocations are used in {\f1 \'ADf\'A0elf} format. The GNU extensions allow this. This warning class is enabled by default. \par\pard\sb120 \tx360\li360\fi-360{\f3\'9F}\tab In addition, warning classes may be enabled or disabled across sections of source code with {\f1 [warning\'A0+warning\'ADname]} or {\f1 [warning\'A0\'ADwarning\'ADname]}. No "user form" (without the brackets) exists. \par\pard\sb120 \page #{\footnote section_2_1_19} ${\footnote 2.1.19. The \'ADv Option: Display Version Info} +{\footnote browse:00029} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADv option; version} \keepn\f2\b\fs30\sb60\sa60 2.1.19. The {\f1 \'ADv} Option: Display Version Info \par\pard\plain\sb120 Typing {\f1 NASM\'A0\'ADv} will display the version of NASM which you are using, and the date on which it was compiled. This replaces the deprecated {\f1 \'ADr}. \par\sb120 You will need the version number if you report a bug. \par\sb120 \page #{\footnote section_2_1_20} ${\footnote 2.1.20. The \'ADy Option: Display Available Debug Info Formats} +{\footnote browse:00030} !{\footnote ChangeButtonBinding("btn_up","JumpId(`nasmdoc.hlp',`section_2_1')"); EnableButton("btn_up")} K{\footnote \'ADy option} \keepn\f2\b\fs30\sb60\sa60 2.1.20. The {\f1 \'ADy} Option: Display Available Debug Info Formats \par\pard\plain\sb120 Typing {\f1 nasm\'A0\'ADf\'A0