home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nasm097d.zip / NASM.INF (.txt) next >
GNU Info File  |  1997-12-06  |  497KB  |  8,901 lines

  1. This is Info file nasm.info, produced by Makeinfo version 1.67 from the
  2. input file nasmdoc.texi.
  3.    This file documents NASM, the Netwide Assembler: an assembler
  4. targetting the Intel x86 series of processors, with portable source.
  5.    Copyright 1997 Simon Tatham
  6.    All rights reserved. This document is redistributable under the
  7. licence given in the file "Licence" distributed in the NASM archive.
  8. File: nasm.info,  Node: Top,  Next: Chapter 1,  Prev: (dir),  Up: (dir)
  9.    This file documents NASM, the Netwide Assembler: an assembler
  10. targetting the Intel x86 series of processors, with portable source.
  11. * Menu:
  12. * Chapter 1:: Introduction
  13. * Chapter 2:: Running NASM
  14. * Chapter 3:: The NASM Language
  15. * Chapter 4:: The NASM Preprocessor
  16. * Chapter 5:: Assembler Directives
  17. * Chapter 6:: Output Formats
  18. * Chapter 7:: Writing 16-bit Code (DOS, Windows 3/3.1)
  19. * Chapter 8:: Writing 32-bit Code (Unix, Win32, DJGPP)
  20. * Chapter 9:: Mixing 16 and 32 Bit Code
  21. * Chapter 10:: Troubleshooting
  22. * Appendix A:: Intel x86 Instruction Reference
  23. * Index::
  24. File: nasm.info,  Node: Chapter 1,  Next: Section 1.1,  Prev: Top,  Up: Top
  25. Chapter 1: Introduction
  26. ***********************
  27. * Menu:
  28. * Section 1.1:: What Is NASM?
  29. * Section 1.2:: Contact Information
  30. * Section 1.3:: Installation
  31. File: nasm.info,  Node: Section 1.1,  Next: Section 1.1.1,  Prev: Chapter 1,  Up: Chapter 1
  32. 1.1. What Is NASM?
  33. ******************
  34.    The Netwide Assembler, NASM, is an 80x86 assembler designed for
  35. portability and modularity. It supports a range of object file formats,
  36. including Linux `a.out' and ELF, NetBSD/FreeBSD, COFF, Microsoft 16-bit
  37. OBJ and Win32.  It will also output plain binary files. Its syntax is
  38. designed to be simple and easy to understand, similar to Intel's but
  39. less complex. It supports Pentium, P6 and MMX opcodes, and has macro
  40. capability.
  41. * Menu:
  42. * Section 1.1.1:: Why Yet Another Assembler?
  43. * Section 1.1.2:: Licence Conditions
  44. File: nasm.info,  Node: Section 1.1.1,  Next: Section 1.1.2,  Prev: Section 1.1,  Up: Section 1.1
  45. 1.1.1. Why Yet Another Assembler?
  46. *********************************
  47.    The Netwide Assembler grew out of an idea on `comp.lang.asm.x86' (or
  48. possibly `alt.lang.asm' - I forget which), which was essentially that
  49. there didn't seem to be a good free x86-series assembler around, and
  50. that maybe someone ought to write one.
  51.    * `a86' is good, but not free, and in particular you don't get any
  52.      32- bit capability until you pay. It's DOS only, too.
  53.    * `gas' is free, and ports over DOS and Unix, but it's not very good,
  54.      since it's designed to be a back end to `gcc', which always feeds
  55.      it correct code. So its error checking is minimal. Also, its
  56.      syntax is horrible, from the point of view of anyone trying to
  57.      actually *write* anything in it. Plus you can't write 16-bit code
  58.      in it (properly).
  59.    * `as86' is Linux-specific, and (my version at least) doesn't seem to
  60.      have much (or any) documentation.
  61.    * MASM isn't very good, and it's expensive, and it runs only under
  62.      DOS.
  63.    * TASM is better, but still strives for MASM compatibility, which
  64.      means millions of directives and tons of red tape. And its syntax
  65.      is essentially MASM's, with the contradictions and quirks that
  66.      entails (although it sorts out some of those by means of Ideal
  67.      mode). It's expensive too. And it's DOS-only.
  68.    So here, for your coding pleasure, is NASM. At present it's still in
  69. prototype stage - we don't promise that it can outperform any of these
  70. assemblers. But please, *please* send us bug reports, fixes, helpful
  71. information, and anything else you can get your hands on (and thanks to
  72. the many people who've done this already! You all know who you are),
  73. and we'll improve it out of all recognition. Again.
  74. File: nasm.info,  Node: Section 1.1.2,  Next: Section 1.2,  Prev: Section 1.1.1,  Up: Section 1.1
  75. 1.1.2. Licence Conditions
  76. *************************
  77.    Please see the file `Licence', supplied as part of any NASM
  78. distribution archive, for the licence conditions under which you may use
  79. NASM.
  80. File: nasm.info,  Node: Section 1.2,  Next: Section 1.3,  Prev: Section 1.1.2,  Up: Chapter 1
  81. 1.2. Contact Information
  82. ************************
  83.    NASM has a WWW page at `http://www.cryogen.com/Nasm'. The authors are
  84. e-mailable as `jules@earthcorp.com' and `anakin@pobox.com'. If you want
  85. to report a bug to us, please read *Note Section 10.2:: first.
  86.    New releases of NASM are uploaded to `sunsite.unc.edu',
  87. `ftp.simtel.net' and `ftp.coast.net'. Announcements are posted to
  88. `comp.lang.asm.x86', `alt.lang.asm', `comp.os.linux.announce' and
  89. `comp.archives.msdos.announce' (the last one is done automagically by
  90. uploading to `ftp.simtel.net').
  91.    If you don't have Usenet access, or would rather be informed by
  92. e-mail when new releases come out, e-mail `anakin@pobox.com' and ask.
  93. File: nasm.info,  Node: Section 1.3,  Next: Section 1.3.1,  Prev: Section 1.2,  Up: Chapter 1
  94. 1.3. Installation
  95. *****************
  96. * Menu:
  97. * Section 1.3.1:: Installing NASM under MS-DOS or Windows
  98. * Section 1.3.2:: Installing NASM under Unix
  99. File: nasm.info,  Node: Section 1.3.1,  Next: Section 1.3.2,  Prev: Section 1.3,  Up: Section 1.3
  100. 1.3.1. Installing NASM under MS-DOS or Windows
  101. **********************************************
  102.    Once you've obtained the DOS archive for NASM, `nasmXXX.zip' (where
  103. `XXX' denotes the version number of NASM contained in the archive),
  104. unpack it into its own directory (for example `c:\nasm').
  105.    The archive will contain four executable files: the NASM executable
  106. files `nasm.exe' and `nasmw.exe', and the NDISASM executable files
  107. `ndisasm.exe' and `ndisasmw.exe'. In each case, the file whose name
  108. ends in `w' is a Win32 executable, designed to run under Windows 95 or
  109. Windows NT Intel, and the other one is a 16-bit DOS executable.
  110.    The only file NASM needs to run is its own executable, so copy (at
  111. least) one of `nasm.exe' and `nasmw.exe' to a directory on your PATH, or
  112. alternatively edit `autoexec.bat' to add the `nasm' directory to your
  113. `PATH'. (If you're only installing the Win32 version, you may wish to
  114. rename it to `nasm.exe'.)
  115.    That's it - NASM is installed. You don't need the `nasm' directory to
  116. be present to run NASM (unless you've added it to your `PATH'), so you
  117. can delete it if you need to save space; however, you may want to keep
  118. the documentation or test programs.
  119.    If you've downloaded the DOS source archive, `nasmXXXs.zip', the
  120. `nasm' directory will also contain the full NASM source code, and a
  121. selection of Makefiles you can (hopefully) use to rebuild your copy of
  122. NASM from scratch. The file `Readme' lists the various Makefiles and
  123. which compilers they work with. Note that the source files `insnsa.c'
  124. and `insnsd.c' are automatically generated from the master instruction
  125. table `insns.dat' by a Perl script; a QBasic version of the program is
  126. provided, but it is recommended that you use the Perl version. A DOS
  127. port of Perl is available from www.perl.org.
  128. File: nasm.info,  Node: Section 1.3.2,  Next: Chapter 2,  Prev: Section 1.3.1,  Up: Section 1.3
  129. 1.3.2. Installing NASM under Unix
  130. *********************************
  131.    Once you've obtained the Unix source archive for NASM,
  132. `nasm-X.XX.tar.gz' (where `X.XX' denotes the version number of NASM
  133. contained in the archive), unpack it into a directory such as
  134. `/usr/local/src'. The archive, when unpacked, will create its own
  135. subdirectory `nasm-X.XX'.
  136.    NASM is an auto-configuring package: once you've unpacked it, `cd' to
  137. the directory it's been unpacked into and type `./configure'. This
  138. shell script will find the best C compiler to use for building NASM and
  139. set up Makefiles accordingly.
  140.    Once NASM has auto-configured, you can type `make' to build the
  141. `nasm' and `ndisasm' binaries, and then `make install' to install them
  142. in `/usr/local/bin' and install the man pages `nasm.1' and `ndisasm.1'
  143. in `/usr/local/man/man1'.  Alternatively, you can give options such as
  144. `--prefix' to the `configure' script (see the file `INSTALL' for more
  145. details), or install the programs yourself.
  146.    NASM also comes with a set of utilities for handling the RDOFF custom
  147. object-file format, which are in the `rdoff' subdirectory of the NASM
  148. archive. You can build these with `make rdf' and install them with
  149. `make rdf_install', if you want them.
  150.    If NASM fails to auto-configure, you may still be able to make it
  151. compile by using the fall-back Unix makefile `Makefile.unx'. Copy or
  152. rename that file to `Makefile' and try typing `make'. There is also a
  153. `Makefile.unx' file in the `rdoff' subdirectory.
  154. File: nasm.info,  Node: Chapter 2,  Next: Section 2.1,  Prev: Section 1.3.2,  Up: Top
  155. Chapter 2: Running NASM
  156. ***********************
  157. * Menu:
  158. * Section 2.1:: NASM Command-Line Syntax
  159. * Section 2.2:: Quick Start for MASM Users
  160. File: nasm.info,  Node: Section 2.1,  Next: Section 2.1.1,  Prev: Chapter 2,  Up: Chapter 2
  161. 2.1. NASM Command-Line Syntax
  162. *****************************
  163.    To assemble a file, you issue a command of the form
  164.      nasm -f <format> <filename> [-o <output>]
  165.    For example,
  166.      nasm -f elf myfile.asm
  167.    will assemble `myfile.asm' into an ELF object file `myfile.o'.  And
  168.      nasm -f bin myfile.asm -o myfile.com
  169.    will assemble `myfile.asm' into a raw binary file `myfile.com'.
  170.    To produce a listing file, with the hex codes output from NASM
  171. displayed on the left of the original sources, use the `-l' option to
  172. give a listing file name, for example:
  173.      nasm -f coff myfile.asm -l myfile.lst
  174.    To get further usage instructions from NASM, try typing
  175.      nasm -h
  176.    This will also list the available output file formats, and what they
  177.    If you use Linux but aren't sure whether your system is `a.out' or
  178. ELF, type
  179.      file nasm
  180.    (in the directory in which you put the NASM binary when you
  181. installed it).  If it says something like
  182.      nasm: ELF 32-bit LSB executable i386 (386 and up) Version 1
  183.    then your system is ELF, and you should use the option `-f elf' when
  184. you want NASM to produce Linux object files. If it says
  185.      nasm: Linux/i386 demand-paged executable (QMAGIC)
  186.    or something similar, your system is `a.out', and you should use `-f
  187. aout' instead.
  188.    Like Unix compilers and assemblers, NASM is silent unless it goes
  189. wrong: you won't see any output at all, unless it gives error messages.
  190. * Menu:
  191. * Section 2.1.1:: The `-o' Option: Specifying the Output File Name
  192. * Section 2.1.2:: The `-f' Option: Specifying the Output File Format
  193. * Section 2.1.3:: The `-l' Option: Generating a Listing File
  194. * Section 2.1.4:: The `-s' Option: Send Errors to `stdout'
  195. * Section 2.1.5:: The `-i' Option: Include File Search Directories
  196. * Section 2.1.6:: The `-p' Option: Pre-Include a File
  197. * Section 2.1.7:: The `-d' Option:  Pre-Define a Macro
  198. * Section 2.1.8:: The `-e' Option: Preprocess Only
  199. * Section 2.1.9:: The `-a' Option: Don't Preprocess At All
  200. * Section 2.1.10:: The `-w' Option: Enable or Disable Assembly Warnings
  201. * Section 2.1.11:: The `NASM' Environment Variable
  202. File: nasm.info,  Node: Section 2.1.1,  Next: Section 2.1.2,  Prev: Section 2.1,  Up: Section 2.1
  203. 2.1.1. The `-o' Option: Specifying the Output File Name
  204. *******************************************************
  205.    NASM will normally choose the name of your output file for you;
  206. precisely how it does this is dependent on the object file format. For
  207. Microsoft object file formats (`obj' and `win32'), it will remove the
  208. `.asm' extension (or whatever extension you like to use - NASM doesn't
  209. care) from your source file name and substitute `.obj'. For Unix object
  210. file formats (`aout', `coff', `elf' and `as86') it will substitute
  211. `.o'. For `rdf', it will use `.rdf', and for the `bin' format it will
  212. simply remove the extension, so that `myfile.asm' produces the output
  213. file `myfile'.
  214.    If the output file already exists, NASM will overwrite it, unless it
  215. has the same name as the input file, in which case it will give a
  216. warning and use `nasm.out' as the output file name instead.
  217.    For situations in which this behaviour is unacceptable, NASM
  218. provides the `-o' command-line option, which allows you to specify your
  219. desired output file name. You invoke `-o' by following it with the name
  220. you wish for the output file, either with or without an intervening
  221. space. For example:
  222.      nasm -f bin program.asm -o program.com
  223.      nasm -f bin driver.asm -odriver.sys
  224. File: nasm.info,  Node: Section 2.1.2,  Next: Section 2.1.3,  Prev: Section 2.1.1,  Up: Section 2.1
  225. 2.1.2. The `-f' Option: Specifying the Output File Format
  226. *********************************************************
  227.    If you do not supply the `-f' option to NASM, it will choose an
  228. output file format for you itself. In the distribution versions of
  229. NASM, the default is always `bin'; if you've compiled your own copy of
  230. NASM, you can redefine `OF_DEFAULT' at compile time and choose what you
  231. want the default to be.
  232.    Like `-o', the intervening space between `-f' and the output file
  233. format is optional; so `-f elf' and `-felf' are both valid.
  234.    A complete list of the available output file formats can be given by
  235. issuing the command `nasm -h'.
  236. File: nasm.info,  Node: Section 2.1.3,  Next: Section 2.1.4,  Prev: Section 2.1.2,  Up: Section 2.1
  237. 2.1.3. The `-l' Option: Generating a Listing File
  238. *************************************************
  239.    If you supply the `-l' option to NASM, followed (with the usual
  240. optional space) by a file name, NASM will generate a source-listing file
  241. for you, in which addresses and generated code are listed on the left,
  242. and the actual source code, with expansions of multi-line macros
  243. (except those which specifically request no expansion in source
  244. listings: see *Note Section 4.2.9::) on the right. For example:
  245.      nasm -f elf myfile.asm -l myfile.lst
  246. File: nasm.info,  Node: Section 2.1.4,  Next: Section 2.1.5,  Prev: Section 2.1.3,  Up: Section 2.1
  247. 2.1.4. The `-s' Option: Send Errors to `stdout'
  248. ***********************************************
  249.    Under MS-DOS it can be difficult (though there are ways) to redirect
  250. the standard-error output of a program to a file. Since NASM usually
  251. produces its warning and error messages on `stderr', this can make it
  252. hard to capture the errors if (for example) you want to load them into
  253. an editor.
  254.    NASM therefore provides the `-s' option, requiring no argument, which
  255. causes errors to be sent to standard output rather than standard error.
  256. Therefore you can redirect the errors into a file by typing
  257.      nasm -s -f obj myfile.asm > myfile.err
  258. File: nasm.info,  Node: Section 2.1.5,  Next: Section 2.1.6,  Prev: Section 2.1.4,  Up: Section 2.1
  259. 2.1.5. The `-i' Option: Include File Search Directories
  260. *******************************************************
  261.    When NASM sees the `%include' directive in a source file (see *Note
  262. Section 4.5::), it will search for the given file not only in the
  263. current directory, but also in any directories specified on the command
  264. line by the use of the `-i' option. Therefore you can include files
  265. from a macro library, for example, by typing
  266.      nasm -ic:\macrolib\ -f obj myfile.asm
  267.    (As usual, a space between `-i' and the path name is allowed, and
  268. optional).
  269.    NASM, in the interests of complete source-code portability, does not
  270. understand the file naming conventions of the OS it is running on; the
  271. string you provide as an argument to the `-i' option will be prepended
  272. exactly as written to the name of the include file. Therefore the
  273. trailing backslash in the above example is necessary. Under Unix, a
  274. trailing forward slash is similarly necessary.
  275.    (You can use this to your advantage, if you're really perverse, by
  276. noting that the option `-ifoo' will cause `%include "bar.i"' to search
  277. for the file `foobar.i'...)
  278.    If you want to define a *standard* include search path, similar to
  279. `/usr/include' on Unix systems, you should place one or more `-i'
  280. directives in the `NASM' environment variable (see *Note Section
  281. 2.1.11::).
  282. File: nasm.info,  Node: Section 2.1.6,  Next: Section 2.1.7,  Prev: Section 2.1.5,  Up: Section 2.1
  283. 2.1.6. The `-p' Option: Pre-Include a File
  284. ******************************************
  285.    NASM allows you to specify files to be *pre-included* into your
  286. source file, by the use of the `-p' option. So running
  287.      nasm myfile.asm -p myinc.inc
  288.    is equivalent to running `nasm myfile.asm' and placing the directive
  289. `%include "myinc.inc"' at the start of the file.
  290. File: nasm.info,  Node: Section 2.1.7,  Next: Section 2.1.8,  Prev: Section 2.1.6,  Up: Section 2.1
  291. 2.1.7. The `-d' Option:  Pre-Define a Macro
  292. *******************************************
  293.    Just as the `-p' option gives an alternative to placing `%include'
  294. directives at the start of a source file, the `-d' option gives an
  295. alternative to placing a `%define' directive. You could code
  296.      nasm myfile.asm -dFOO=100
  297.    as an alternative to placing the directive
  298.      %define FOO 100
  299.    at the start of the file. You can miss off the macro value, as well:
  300. the option `-dFOO' is equivalent to coding `%define FOO'. This form of
  301. the directive may be useful for selecting assembly-time options which
  302. are then tested using `%ifdef', for example `-dDEBUG'.
  303. File: nasm.info,  Node: Section 2.1.8,  Next: Section 2.1.9,  Prev: Section 2.1.7,  Up: Section 2.1
  304. 2.1.8. The `-e' Option: Preprocess Only
  305. ***************************************
  306.    NASM allows the preprocessor to be run on its own, up to a point.
  307. Using the `-e' option (which requires no arguments) will cause NASM to
  308. preprocess its input file, expand all the macro references, remove all
  309. the comments and preprocessor directives, and print the resulting file
  310. on standard output (or save it to a file, if the `-o' option is also
  311. used).
  312.    This option cannot be applied to programs which require the
  313. preprocessor to evaluate expressions which depend on the values of
  314. symbols: so code such as
  315.      %assign tablesize ($-tablestart)
  316.    will cause an error in preprocess-only mode.
  317. File: nasm.info,  Node: Section 2.1.9,  Next: Section 2.1.10,  Prev: Section 2.1.8,  Up: Section 2.1
  318. 2.1.9. The `-a' Option: Don't Preprocess At All
  319. ***********************************************
  320.    If NASM is being used as the back end to a compiler, it might be
  321. desirable to suppress preprocessing completely and assume the compiler
  322. has already done it, to save time and increase compilation speeds. The
  323. `-a' option, requiring no argument, instructs NASM to replace its
  324. powerful preprocessor with a stub preprocessor which does nothing.
  325. File: nasm.info,  Node: Section 2.1.10,  Next: Section 2.1.11,  Prev: Section 2.1.9,  Up: Section 2.1
  326. 2.1.10. The `-w' Option: Enable or Disable Assembly Warnings
  327. ************************************************************
  328.    NASM can observe many conditions during the course of assembly which
  329. are worth mentioning to the user, but not a sufficiently severe error to
  330. justify NASM refusing to generate an output file. These conditions are
  331. reported like errors, but come up with the word `warning' before the
  332. message. Warnings do not prevent NASM from generating an output file and
  333. returning a success status to the operating system.
  334.    Some conditions are even less severe than that: they are only
  335. sometimes worth mentioning to the user. Therefore NASM supports the `-w'
  336. command-line option, which enables or disables certain classes of
  337. assembly warning. Such warning classes are described by a name, for
  338. example `orphan-labels'; you can enable warnings of this class by the
  339. command- line option `-w+orphan-labels' and disable it by
  340. `-w-orphan-labels'.
  341.    The suppressible warning classes are:
  342.    * `macro-params' covers warnings about multi-line macros being
  343.      invoked with the wrong number of parameters. This warning class is
  344.      enabled by default; see *Note Section 4.2.1:: for an example of
  345.      why you might want to disable it.
  346.    * `orphan-labels' covers warnings about source lines which contain no
  347.      instruction but define a label without a trailing colon. NASM does
  348.      not warn about this somewhat obscure condition by default; see
  349.      *Note Section 3.1:: for an example of why you might want it to.
  350.    * `number-overflow' covers warnings about numeric constants which
  351.      don't fit in 32 bits (for example, it's easy to type one too many
  352.      Fs and produce `0x7ffffffff' by mistake). This warning class is
  353.      enabled by default.
  354. File: nasm.info,  Node: Section 2.1.11,  Next: Section 2.2,  Prev: Section 2.1.10,  Up: Section 2.1
  355. 2.1.11. The `NASM' Environment Variable
  356. ***************************************
  357.    If you define an environment variable called `NASM', the program will
  358. interpret it as a list of extra command-line options, which are
  359. processed before the real command line. You can use this to define
  360. standard search directories for include files, by putting `-i' options
  361. in the `NASM' variable.
  362.    The value of the variable is split up at white space, so that the
  363. value `-s -ic:\nasmlib' will be treated as two separate options.
  364. However, that means that the value `-dNAME="my name"' won't do what you
  365. might want, because it will be split at the space and the NASM
  366. command-line processing will get confused by the two nonsensical words
  367. `-dNAME="my' and `name"'.
  368.    To get round this, NASM provides a feature whereby, if you begin the
  369. `NASM' environment variable with some character that isn't a minus
  370. sign, then NASM will treat this character as the separator character for
  371. options. So setting the `NASM' variable to the value `!-s!-ic:\nasmlib'
  372. is equivalent to setting it to `-s -ic:\nasmlib', but `!-dNAME="my
  373. name"' will work.
  374. File: nasm.info,  Node: Section 2.2,  Next: Section 2.2.1,  Prev: Section 2.1.11,  Up: Chapter 2
  375. 2.2. Quick Start for MASM Users
  376. *******************************
  377.    If you're used to writing programs with MASM, or with TASM in MASM-
  378. compatible (non-Ideal) mode, or with `a86', this section attempts to
  379. outline the major differences between MASM's syntax and NASM's. If
  380. you're not already used to MASM, it's probably worth skipping this
  381. section.
  382. * Menu:
  383. * Section 2.2.1:: NASM Is Case-Sensitive
  384. * Section 2.2.2:: NASM Requires Square Brackets For Memory References
  385. * Section 2.2.3:: NASM Doesn't Store Variable Types
  386. * Section 2.2.4:: NASM Doesn't `ASSUME'
  387. * Section 2.2.5:: NASM Doesn't Support Memory Models
  388. * Section 2.2.6:: Floating-Point Differences
  389. * Section 2.2.7:: Other Differences
  390. File: nasm.info,  Node: Section 2.2.1,  Next: Section 2.2.2,  Prev: Section 2.2,  Up: Section 2.2
  391. 2.2.1. NASM Is Case-Sensitive
  392. *****************************
  393.    One simple difference is that NASM is case-sensitive. It makes a
  394. difference whether you call your label `foo', `Foo' or `FOO'. If you're
  395. assembling to DOS or OS/2 `.OBJ' files, you can invoke the `UPPERCASE'
  396. directive (documented in *Note Section 6.2::) to ensure that all
  397. symbols exported to other code modules are forced to be upper case; but
  398. even then, *within* a single module, NASM will distinguish between
  399. labels differing only in case.
  400. File: nasm.info,  Node: Section 2.2.2,  Next: Section 2.2.3,  Prev: Section 2.2.1,  Up: Section 2.2
  401. 2.2.2. NASM Requires Square Brackets For Memory References
  402. **********************************************************
  403.    NASM was designed with simplicity of syntax in mind. One of the
  404. design goals of NASM is that it should be possible, as far as is
  405. practical, for the user to look at a single line of NASM code and tell
  406. what opcode is generated by it. You can't do this in MASM: if you
  407. declare, for example,
  408.      foo       equ 1
  409.      bar       dw 2
  410.    then the two lines of code
  411.                mov ax,foo
  412.                mov ax,bar
  413.    generate completely different opcodes, despite having
  414. identical-looking syntaxes.
  415.    NASM avoids this undesirable situation by having a much simpler
  416. syntax for memory references. The rule is simply that any access to the
  417. *contents* of a memory location requires square brackets around the
  418. address, and any access to the *address* of a variable doesn't. So an
  419. instruction of the form `mov ax,foo' will *always* refer to a
  420. compile-time constant, whether it's an `EQU' or the address of a
  421. variable; and to access the *contents* of the variable `bar', you must
  422. code `mov ax,[bar]'.
  423.    This also means that NASM has no need for MASM's `OFFSET' keyword,
  424. since the MASM code `mov ax,offset bar' means exactly the same thing as
  425. NASM's `mov ax,bar'. If you're trying to get large amounts of MASM code
  426. to assemble sensibly under NASM, you can always code `%idefine offset'
  427. to make the preprocessor treat the `OFFSET' keyword as a no-op.
  428.    This issue is even more confusing in `a86', where declaring a label
  429. with a trailing colon defines it to be a `label' as opposed to a
  430. `variable' and causes `a86' to adopt NASM-style semantics; so in `a86',
  431. `mov ax,var' has different behaviour depending on whether `var' was
  432. declared as `var: dw 0' (a label) or `var dw 0' (a word-size variable).
  433. NASM is very simple by comparison: *everything* is a label.
  434.    NASM, in the interests of simplicity, also does not support the
  435. hybrid syntaxes supported by MASM and its clones, such as `mov
  436. ax,table[bx]', where a memory reference is denoted by one portion
  437. outside square brackets and another portion inside. The correct syntax
  438. for the above is `mov ax,[table+bx]'. Likewise, `mov ax,es:[di]' is
  439. wrong and `mov ax,[es:di]' is right.
  440. File: nasm.info,  Node: Section 2.2.3,  Next: Section 2.2.4,  Prev: Section 2.2.2,  Up: Section 2.2
  441. 2.2.3. NASM Doesn't Store Variable Types
  442. ****************************************
  443.    NASM, by design, chooses not to remember the types of variables you
  444. declare. Whereas MASM will remember, on seeing `var dw 0', that you
  445. declared `var' as a word-size variable, and will then be able to fill
  446. in the ambiguity in the size of the instruction `mov var,2', NASM will
  447. deliberately remember nothing about the symbol `var' except where it
  448. begins, and so you must explicitly code `mov word [var],2'.
  449.    For this reason, NASM doesn't support the `LODS', `MOVS', `STOS',
  450. `SCAS', `CMPS', `INS', or `OUTS' instructions, but only supports the
  451. forms such as `LODSB', `MOVSW', and `SCASD', which explicitly specify
  452. the size of the components of the strings being manipulated.
  453. File: nasm.info,  Node: Section 2.2.4,  Next: Section 2.2.5,  Prev: Section 2.2.3,  Up: Section 2.2
  454. 2.2.4. NASM Doesn't `ASSUME'
  455. ****************************
  456.    As part of NASM's drive for simplicity, it also does not support the
  457. `ASSUME' directive. NASM will not keep track of what values you choose
  458. to put in your segment registers, and will never *automatically*
  459. generate a segment override prefix.
  460. File: nasm.info,  Node: Section 2.2.5,  Next: Section 2.2.6,  Prev: Section 2.2.4,  Up: Section 2.2
  461. 2.2.5. NASM Doesn't Support Memory Models
  462. *****************************************
  463.    NASM also does not have any directives to support different 16-bit
  464. memory models. The programmer has to keep track of which functions are
  465. supposed to be called with a far call and which with a near call, and
  466. is responsible for putting the correct form of `RET' instruction
  467. (`RETN' or `RETF'; NASM accepts `RET' itself as an alternate form for
  468. `RETN'); in addition, the programmer is responsible for coding CALL FAR
  469. instructions where necessary when calling *external* functions, and
  470. must also keep track of which external variable definitions are far and
  471. which are near.
  472. File: nasm.info,  Node: Section 2.2.6,  Next: Section 2.2.7,  Prev: Section 2.2.5,  Up: Section 2.2
  473. 2.2.6. Floating-Point Differences
  474. *********************************
  475.    NASM uses different names to refer to floating-point registers from
  476. MASM: where MASM would call them `ST(0)', `ST(1)' and so on, and `a86'
  477. would call them simply `0', `1' and so on, NASM chooses to call them
  478. `st0', `st1' etc.
  479.    As of version 0.96, NASM now treats the instructions with `nowait'
  480. forms in the same way as MASM-compatible assemblers. The idiosyncratic
  481. treatment employed by 0.95 and earlier was based on a misunderstanding
  482. by the authors.
  483. File: nasm.info,  Node: Section 2.2.7,  Next: Chapter 3,  Prev: Section 2.2.6,  Up: Section 2.2
  484. 2.2.7. Other Differences
  485. ************************
  486.    For historical reasons, NASM uses the keyword `TWORD' where MASM and
  487. compatible assemblers use `TBYTE'.
  488.    NASM does not declare uninitialised storage in the same way as MASM:
  489. where a MASM programmer might use `stack db 64 dup (?)', NASM requires
  490. `stack resb 64', intended to be read as `reserve 64 bytes'. For a
  491. limited amount of compatibility, since NASM treats `?' as a valid
  492. character in symbol names, you can code `? equ 0' and then writing `dw
  493. ?' will at least do something vaguely useful. `DUP' is still not a
  494. supported syntax, however.
  495.    In addition to all of this, macros and directives work completely
  496. differently to MASM. See *Note Chapter 4:: and *Note Chapter 5:: for
  497. further details.
  498. File: nasm.info,  Node: Chapter 3,  Next: Section 3.1,  Prev: Section 2.2.7,  Up: Top
  499. Chapter 3: The NASM Language
  500. ****************************
  501. * Menu:
  502. * Section 3.1:: Layout of a NASM Source Line
  503. * Section 3.2:: Pseudo-Instructions
  504. * Section 3.3:: Effective Addresses
  505. * Section 3.4:: Constants
  506. * Section 3.5:: Expressions
  507. * Section 3.6:: `SEG' and `WRT'
  508. * Section 3.7:: Critical Expressions
  509. * Section 3.8:: Local Labels
  510. File: nasm.info,  Node: Section 3.1,  Next: Section 3.2,  Prev: Chapter 3,  Up: Chapter 3
  511. 3.1. Layout of a NASM Source Line
  512. *********************************
  513.    Like most assemblers, each NASM source line contains (unless it is a
  514. macro, a preprocessor directive or an assembler directive: see *Note
  515. Chapter 4:: and *Note Chapter 5::) some combination of the four fields
  516.      label:    instruction operands        ; comment
  517.    As usual, most of these fields are optional; the presence or absence
  518. of any combination of a label, an instruction and a comment is allowed.
  519. Of course, the operand field is either required or forbidden by the
  520. presence and nature of the instruction field.
  521.    NASM places no restrictions on white space within a line: labels may
  522. have white space before them, or instructions may have no space before
  523. them, or anything. The colon after a label is also optional. (Note that
  524. this means that if you intend to code `lodsb' alone on a line, and type
  525. `lodab' by accident, then that's still a valid source line which does
  526. nothing but define a label. Running NASM with the command-line option
  527. `-w+orphan-labels' will cause it to warn you if you define a label
  528. alone on a line without a trailing colon.)
  529.    Valid characters in labels are letters, numbers, `_', `$', `#', `@',
  530. `~', `.', and `?'. The only characters which may be used as the *first*
  531. character of an identifier are letters, `.' (with special meaning: see
  532. *Note Section 3.8::), `_' and `?'. An identifier may also be prefixed
  533. with a `$' to indicate that it is intended to be read as an identifier
  534. and not a reserved word; thus, if some other module you are linking
  535. with defines a symbol called `eax', you can refer to `$eax' in NASM
  536. code to distinguish the symbol from the register.
  537.    The instruction field may contain any machine instruction: Pentium
  538. and P6 instructions, FPU instructions, MMX instructions and even
  539. undocumented instructions are all supported. The instruction may be
  540. prefixed by `LOCK', `REP', `REPE'/`REPZ' or `REPNE'/`REPNZ', in the
  541. usual way. Explicit address-size and operand-size prefixes `A16',
  542. `A32', `O16' and `O32' are provided - one example of their use is given
  543. in *Note Chapter 9::. You can also use the name of a segment register
  544. as an instruction prefix: coding `es mov [bx],ax' is equivalent to
  545. coding `mov [es:bx],ax'. We recommend the latter syntax, since it is
  546. consistent with other syntactic features of the language, but for
  547. instructions such as `LODSB', which has no operands and yet can require
  548. a segment override, there is no clean syntactic way to proceed apart
  549. from `es lodsb'.
  550.    An instruction is not required to use a prefix: prefixes such as
  551. `CS', `A32', `LOCK' or `REPE' can appear on a line by themselves, and
  552. NASM will just generate the prefix bytes.
  553.    In addition to actual machine instructions, NASM also supports a
  554. number of pseudo-instructions, described in *Note Section 3.2::.
  555.    Instruction operands may take a number of forms: they can be
  556. registers, described simply by the register name (e.g. `ax', `bp',
  557. `ebx', `cr0': NASM does not use the `gas'-style syntax in which
  558. register names must be prefixed by a `%' sign), or they can be
  559. effective addresses (see *Note Section 3.3::), constants (*Note Section
  560. 3.4::) or expressions (*Note Section 3.5::).
  561.    For floating-point instructions, NASM accepts a wide range of
  562. syntaxes: you can use two-operand forms like MASM supports, or you can
  563. use NASM's native single-operand forms in most cases. Details of all
  564. forms of each supported instruction are given in *Note Appendix A::.
  565. For example, you can code:
  566.                fadd st1               ; this sets st0 := st0 + st1
  567.                fadd st0,st1           ; so does this
  568.      
  569.                fadd st1,st0           ; this sets st1 := st1 + st0
  570.                fadd to st1            ; so does this
  571.    Almost any floating-point instruction that references memory must
  572. use one of the prefixes `DWORD', `QWORD' or `TWORD' to indicate what
  573. size of memory operand it refers to.
  574. File: nasm.info,  Node: Section 3.2,  Next: Section 3.2.1,  Prev: Section 3.1,  Up: Chapter 3
  575. 3.2. Pseudo-Instructions
  576. ************************
  577.    Pseudo-instructions are things which, though not real x86 machine
  578. instructions, are used in the instruction field anyway because that's
  579. the most convenient place to put them. The current pseudo-instructions
  580. are `DB', `DW', `DD', `DQ' and `DT', their uninitialised counterparts
  581. `RESB', `RESW', `RESD', `RESQ' and `REST', the `INCBIN' command, the
  582. `EQU' command, and the `TIMES' prefix.
  583. * Menu:
  584. * Section 3.2.1:: `DB' and friends: Declaring Initialised Data
  585. * Section 3.2.2:: `RESB' and friends: Declaring Uninitialised Data
  586. * Section 3.2.3:: `INCBIN': Including External Binary Files
  587. * Section 3.2.4:: `EQU': Defining Constants
  588. * Section 3.2.5:: `TIMES': Repeating Instructions or Data
  589. File: nasm.info,  Node: Section 3.2.1,  Next: Section 3.2.2,  Prev: Section 3.2,  Up: Section 3.2
  590. 3.2.1. `DB' and friends: Declaring Initialised Data
  591. ***************************************************
  592.    `DB', `DW', `DD', `DQ' and `DT' are used, much as in MASM, to
  593. declare initialised data in the output file. They can be invoked in a
  594. wide range of ways:
  595.                db 0x55                ; just the byte 0x55
  596.                db 0x55,0x56,0x57      ; three bytes in succession
  597.                db 'a',0x55            ; character constants are OK
  598.                db 'hello',13,10,'$'   ; so are string constants
  599.                dw 0x1234              ; 0x34 0x12
  600.                dw 'a'                 ; 0x41 0x00 (it's just a number)
  601.                dw 'ab'                ; 0x41 0x42 (character constant)
  602.                dw 'abc'               ; 0x41 0x42 0x43 0x00 (string)
  603.                dd 0x12345678          ; 0x78 0x56 0x34 0x12
  604.                dd 1.234567e20         ; floating-point constant
  605.                dq 1.234567e20         ; double-precision float
  606.                dt 1.234567e20         ; extended-precision float
  607.    `DQ' and `DT' do not accept numeric constants or string constants as
  608. operands.
  609. File: nasm.info,  Node: Section 3.2.2,  Next: Section 3.2.3,  Prev: Section 3.2.1,  Up: Section 3.2
  610. 3.2.2. `RESB' and friends: Declaring Uninitialised Data
  611. *******************************************************
  612.    `RESB', `RESW', `RESD', `RESQ' and `REST' are designed to be used in
  613. the BSS section of a module: they declare *uninitialised* storage
  614. space. Each takes a single operand, which is the number of bytes,
  615. words, doublewords or whatever to reserve. As stated in *Note Section
  616. 2.2.7::, NASM does not support the MASM/TASM syntax of reserving
  617. uninitialised space by writing `DW ?' or similar things: this is what
  618. it does instead. The operand to a `RESB'-type pseudo- instruction is a
  619. *critical expression*: see *Note Section 3.7::.
  620.    For example:
  621.      buffer:   resb 64                ; reserve 64 bytes
  622.      wordvar:  resw 1                 ; reserve a word
  623.      realarray resq 10                ; array of ten reals
  624. File: nasm.info,  Node: Section 3.2.3,  Next: Section 3.2.4,  Prev: Section 3.2.2,  Up: Section 3.2
  625. 3.2.3. `INCBIN': Including External Binary Files
  626. ************************************************
  627.    `INCBIN' is borrowed from the old Amiga assembler DevPac: it includes
  628. a binary file verbatim into the output file. This can be handy for (for
  629. example) including graphics and sound data directly into a game
  630. executable file. It can be called in one of these three ways:
  631.                incbin "file.dat"      ; include the whole file
  632.                incbin "file.dat",1024 ; skip the first 1024 bytes
  633.                incbin "file.dat",1024,512 ; skip the first 1024, and
  634.                                       ; actually include at most 512
  635. File: nasm.info,  Node: Section 3.2.4,  Next: Section 3.2.5,  Prev: Section 3.2.3,  Up: Section 3.2
  636. 3.2.4. `EQU': Defining Constants
  637. ********************************
  638.    `EQU' defines a symbol to a given constant value: when `EQU' is
  639. used, the source line must contain a label. The action of `EQU' is to
  640. define the given label name to the value of its (only) operand. This
  641. definition is absolute, and cannot change later. So, for example,
  642.      message   db 'hello, world'
  643.      msglen    equ $-message
  644.    defines `msglen' to be the constant 12. `msglen' may not then be
  645. redefined later. This is not a preprocessor definition either: the
  646. value of `msglen' is evaluated *once*, using the value of `$' (see
  647. *Note Section 3.5:: for an explanation of `$') at the point of
  648. definition, rather than being evaluated wherever it is referenced and
  649. using the value of `$' at the point of reference. Note that the operand
  650. to an `EQU' is also a critical expression (*Note Section 3.7::).
  651. File: nasm.info,  Node: Section 3.2.5,  Next: Section 3.3,  Prev: Section 3.2.4,  Up: Section 3.2
  652. 3.2.5. `TIMES': Repeating Instructions or Data
  653. **********************************************
  654.    The `TIMES' prefix causes the instruction to be assembled multiple
  655. times. This is partly present as NASM's equivalent of the `DUP' syntax
  656. supported by MASM-compatible assemblers, in that you can code
  657.      zerobuf:  times 64 db 0
  658.    or similar things; but `TIMES' is more versatile than that. The
  659. argument to `TIMES' is not just a numeric constant, but a numeric
  660. *expression*, so you can do things like
  661.      buffer:   db 'hello, world'
  662.                times 64-$+buffer db ' '
  663.    which will store exactly enough spaces to make the total length of
  664. `buffer' up to 64. Finally, `TIMES' can be applied to ordinary
  665. instructions, so you can code trivial unrolled loops in it:
  666.                times 100 movsb
  667.    Note that there is no effective difference between `times 100 resb 1'
  668. and `resb 100', except that the latter will be assembled about 100
  669. times faster due to the internal structure of the assembler.
  670.    The operand to `TIMES', like that of `EQU' and those of `RESB' and
  671. friends, is a critical expression (*Note Section 3.7::).
  672.    Note also that `TIMES' can't be applied to macros: the reason for
  673. this is that `TIMES' is processed after the macro phase, which allows
  674. the argument to `TIMES' to contain expressions such as `64-$+buffer' as
  675. above. To repeat more than one line of code, or a complex macro, use the
  676. preprocessor `%rep' directive.
  677. File: nasm.info,  Node: Section 3.3,  Next: Section 3.4,  Prev: Section 3.2.5,  Up: Chapter 3
  678. 3.3. Effective Addresses
  679. ************************
  680.    An effective address is any operand to an instruction which
  681. references memory. Effective addresses, in NASM, have a very simple
  682. syntax: they consist of an expression evaluating to the desired
  683. address, enclosed in square brackets. For example:
  684.      wordvar   dw 123
  685.                mov ax,[wordvar]
  686.                mov ax,[wordvar+1]
  687.                mov ax,[es:wordvar+bx]
  688.    Anything not conforming to this simple system is not a valid memory
  689. reference in NASM, for example `es:wordvar[bx]'.
  690.    More complicated effective addresses, such as those involving more
  691. than one register, work in exactly the same way:
  692.                mov eax,[ebx*2+ecx+offset]
  693.                mov ax,[bp+di+8]
  694.    NASM is capable of doing algebra on these effective addresses, so
  695. that things which don't necessarily *look* legal are perfectly all
  696. right:
  697.                mov eax,[ebx*5]        ; assembles as [ebx*4+ebx]
  698.                mov eax,[label1*2-label2] ; ie [label1+(label1-label2)]
  699.    Some forms of effective address have more than one assembled form;
  700. in most such cases NASM will generate the smallest form it can. For
  701. example, there are distinct assembled forms for the 32-bit effective
  702. addresses `[eax*2+0]' and `[eax+eax]', and NASM will generally generate
  703. the latter on the grounds that the former requires four bytes to store
  704. a zero offset.
  705.    NASM has a hinting mechanism which will cause `[eax+ebx]' and
  706. `[ebx+eax]' to generate different opcodes; this is occasionally useful
  707. because `[esi+ebp]' and `[ebp+esi]' have different default segment
  708. registers.
  709.    However, you can force NASM to generate an effective address in a
  710. particular form by the use of the keywords `BYTE', `WORD', `DWORD' and
  711. `NOSPLIT'. If you need `[eax+3]' to be assembled using a double-word
  712. offset field instead of the one byte NASM will normally generate, you
  713. can code `[dword eax+3]'. Similarly, you can force NASM to use a byte
  714. offset for a small value which it hasn't seen on the first pass (see
  715. *Note Section 3.7:: for an example of such a code fragment) by using
  716. `[byte eax+offset]'. As special cases, `[byte eax]' will code `[eax+0]'
  717. with a byte offset of zero, and `[dword eax]' will code it with a
  718. double-word offset of zero. The normal form, `[eax]', will be coded
  719. with no offset field.
  720.    Similarly, NASM will split `[eax*2]' into `[eax+eax]' because that
  721. allows the offset field to be absent and space to be saved; in fact, it
  722. will also split `[eax*2+offset]' into `[eax+eax+offset]'. You can
  723. combat this behaviour by the use of the `NOSPLIT' keyword: `[nosplit
  724. eax*2]' will force `[eax*2+0]' to be generated literally.
  725. File: nasm.info,  Node: Section 3.4,  Next: Section 3.4.1,  Prev: Section 3.3,  Up: Chapter 3
  726. 3.4. Constants
  727. **************
  728.    NASM understands four different types of constant: numeric,
  729. character, string and floating-point.
  730. * Menu:
  731. * Section 3.4.1:: Numeric Constants
  732. * Section 3.4.2:: Character Constants
  733. * Section 3.4.3:: String Constants
  734. * Section 3.4.4:: Floating-Point Constants
  735. File: nasm.info,  Node: Section 3.4.1,  Next: Section 3.4.2,  Prev: Section 3.4,  Up: Section 3.4
  736. 3.4.1. Numeric Constants
  737. ************************
  738.    A numeric constant is simply a number. NASM allows you to specify
  739. numbers in a variety of number bases, in a variety of ways: you can
  740. suffix `H', `Q' and `B' for hex, octal and binary, or you can prefix
  741. `0x' for hex in the style of C, or you can prefix `$' for hex in the
  742. style of Borland Pascal. Note, though, that the `$' prefix does double
  743. duty as a prefix on identifiers (see *Note Section 3.1::), so a hex
  744. number prefixed with a `$' sign must have a digit after the `$' rather
  745. than a letter.
  746.    Some examples:
  747.                mov ax,100             ; decimal
  748.                mov ax,0a2h            ; hex
  749.                mov ax,$0a2            ; hex again: the 0 is required
  750.                mov ax,0xa2            ; hex yet again
  751.                mov ax,777q            ; octal
  752.                mov ax,10010011b       ; binary
  753. File: nasm.info,  Node: Section 3.4.2,  Next: Section 3.4.3,  Prev: Section 3.4.1,  Up: Section 3.4
  754. 3.4.2. Character Constants
  755. **************************
  756.    A character constant consists of up to four characters enclosed in
  757. either single or double quotes. The type of quote makes no difference
  758. to NASM, except of course that surrounding the constant with single
  759. quotes allows double quotes to appear within it and vice versa.
  760.    A character constant with more than one character will be arranged
  761. with little-endian order in mind: if you code
  762.                mov eax,'abcd'
  763.    then the constant generated is not `0x61626364', but `0x64636261',
  764. so that if you were then to store the value into memory, it would read
  765. `abcd' rather than `dcba'. This is also the sense of character
  766. constants understood by the Pentium's `CPUID' instruction (see *Note
  767. Section A.22::).
  768. File: nasm.info,  Node: Section 3.4.3,  Next: Section 3.4.4,  Prev: Section 3.4.2,  Up: Section 3.4
  769. 3.4.3. String Constants
  770. ***********************
  771.    String constants are only acceptable to some pseudo-instructions,
  772. namely the `DB' family and `INCBIN'.
  773.    A string constant looks like a character constant, only longer. It is
  774. treated as a concatenation of maximum-size character constants for the
  775. conditions. So the following are equivalent:
  776.                db 'hello'             ; string constant
  777.                db 'h','e','l','l','o' ; equivalent character constants
  778.    And the following are also equivalent:
  779.                dd 'ninechars'         ; doubleword string constant
  780.                dd 'nine','char','s'   ; becomes three doublewords
  781.                db 'ninechars',0,0,0   ; and really looks like this
  782.    Note that when used as an operand to `db', a constant like `'ab'' is
  783. treated as a string constant despite being short enough to be a
  784. character constant, because otherwise `db 'ab'' would have the same
  785. effect as `db 'a'', which would be silly. Similarly, three-character or
  786. four-character constants are treated as strings when they are operands
  787. to `dw'.
  788. File: nasm.info,  Node: Section 3.4.4,  Next: Section 3.5,  Prev: Section 3.4.3,  Up: Section 3.4
  789. 3.4.4. Floating-Point Constants
  790. *******************************
  791.    Floating-point constants are acceptable only as arguments to `DD',
  792. `DQ' and `DT'. They are expressed in the traditional form: digits, then
  793. a period, then optionally more digits, then optionally an `E' followed
  794. by an exponent. The period is mandatory, so that NASM can distinguish
  795. between `dd 1', which declares an integer constant, and `dd 1.0' which
  796. declares a floating-point constant.
  797.    Some examples:
  798.                dd 1.2                 ; an easy one
  799.                dq 1.e10               ; 10,000,000,000
  800.                dq 1.e+10              ; synonymous with 1.e10
  801.                dq 1.e-10              ; 0.000 000 000 1
  802.                dt 3.141592653589793238462 ; pi
  803.    NASM cannot do compile-time arithmetic on floating-point constants.
  804. This is because NASM is designed to be portable - although it always
  805. generates code to run on x86 processors, the assembler itself can run
  806. on any system with an ANSI C compiler. Therefore, the assembler cannot
  807. guarantee the presence of a floating-point unit capable of handling the
  808. Intel number formats, and so for NASM to be able to do floating
  809. arithmetic it would have to include its own complete set of
  810. floating-point routines, which would significantly increase the size of
  811. the assembler for very little benefit.
  812. File: nasm.info,  Node: Section 3.5,  Next: Section 3.5.1,  Prev: Section 3.4.4,  Up: Chapter 3
  813. 3.5. Expressions
  814. ****************
  815.    Expressions in NASM are similar in syntax to those in C.
  816.    NASM does not guarantee the size of the integers used to evaluate
  817. expressions at compile time: since NASM can compile and run on 64-bit
  818. systems quite happily, don't assume that expressions are evaluated in
  819. 32- bit registers and so try to make deliberate use of integer
  820. overflow. It might not always work. The only thing NASM will guarantee
  821. is what's guaranteed by ANSI C: you always have *at least* 32 bits to
  822. work in.
  823.    NASM supports two special tokens in expressions, allowing
  824. calculations to involve the current assembly position: the `$' and `$$'
  825. tokens.  `$' evaluates to the assembly position at the beginning of the
  826. line containing the expression; so you can code an infinite loop using
  827. `JMP $'. `$$' evaluates to the beginning of the current section; so you
  828. can tell how far into the section you are by using `($-$$)'.
  829.    The arithmetic operators provided by NASM are listed here, in
  830. increasing order of precedence.
  831. * Menu:
  832. * Section 3.5.1:: `|': Bitwise OR Operator
  833. * Section 3.5.2:: `^': Bitwise XOR Operator
  834. * Section 3.5.3:: `&': Bitwise AND Operator
  835. * Section 3.5.4:: `<<' and `>>': Bit Shift Operators
  836. * Section 3.5.5:: `+' and `-': Addition and Subtraction Operators
  837. * Section 3.5.6:: `*', `/', `//', `%' and `%%': Multiplication and Division
  838. * Section 3.5.7:: Unary Operators: `+', `-', `~' and `SEG'
  839. File: nasm.info,  Node: Section 3.5.1,  Next: Section 3.5.2,  Prev: Section 3.5,  Up: Section 3.5
  840. 3.5.1. `|': Bitwise OR Operator
  841. *******************************
  842.    The `|' operator gives a bitwise OR, exactly as performed by the
  843. `OR' machine instruction. Bitwise OR is the lowest-priority arithmetic
  844. operator supported by NASM.
  845. File: nasm.info,  Node: Section 3.5.2,  Next: Section 3.5.3,  Prev: Section 3.5.1,  Up: Section 3.5
  846. 3.5.2. `^': Bitwise XOR Operator
  847. ********************************
  848.    `^' provides the bitwise XOR operation.
  849. File: nasm.info,  Node: Section 3.5.3,  Next: Section 3.5.4,  Prev: Section 3.5.2,  Up: Section 3.5
  850. 3.5.3. `&': Bitwise AND Operator
  851. ********************************
  852.    `&' provides the bitwise AND operation.
  853. File: nasm.info,  Node: Section 3.5.4,  Next: Section 3.5.5,  Prev: Section 3.5.3,  Up: Section 3.5
  854. 3.5.4. `<<' and `>>': Bit Shift Operators
  855. *****************************************
  856.    `<<' gives a bit-shift to the left, just as it does in C. So `5<<3'
  857. evaluates to 5 times 8, or 40. `>>' gives a bit-shift to the right; in
  858. NASM, such a shift is *always* unsigned, so that the bits shifted in
  859. from the left-hand end are filled with zero rather than a
  860. sign-extension of the previous highest bit.
  861. File: nasm.info,  Node: Section 3.5.5,  Next: Section 3.5.6,  Prev: Section 3.5.4,  Up: Section 3.5
  862. 3.5.5. `+' and `-': Addition and Subtraction Operators
  863. ******************************************************
  864.    The `+' and `-' operators do perfectly ordinary addition and
  865. subtraction.
  866. File: nasm.info,  Node: Section 3.5.6,  Next: Section 3.5.7,  Prev: Section 3.5.5,  Up: Section 3.5
  867. 3.5.6. `*', `/', `//', `%' and `%%': Multiplication and Division
  868. ****************************************************************
  869.    `*' is the multiplication operator. `/' and `//' are both division
  870. operators: `/' is unsigned division and `//' is signed division.
  871. Similarly, `%' and `%%' provide unsigned and signed modulo operators
  872. respectively.
  873.    NASM, like ANSI C, provides no guarantees about the sensible
  874. operation of the signed modulo operator.
  875.    Since the `%' character is used extensively by the macro
  876. preprocessor, you should ensure that both the signed and unsigned
  877. modulo operators are followed by white space wherever they appear.
  878. File: nasm.info,  Node: Section 3.5.7,  Next: Section 3.6,  Prev: Section 3.5.6,  Up: Section 3.5
  879. 3.5.7. Unary Operators: `+', `-', `~' and `SEG'
  880. ***********************************************
  881.    The highest-priority operators in NASM's expression grammar are
  882. those which only apply to one argument. `-' negates its operand, `+'
  883. does nothing (it's provided for symmetry with `-'), `~' computes the
  884. one's complement of its operand, and `SEG' provides the segment address
  885. of its operand (explained in more detail in *Note Section 3.6::).
  886. File: nasm.info,  Node: Section 3.6,  Next: Section 3.7,  Prev: Section 3.5.7,  Up: Chapter 3
  887. 3.6. `SEG' and `WRT'
  888. ********************
  889.    When writing large 16-bit programs, which must be split into multiple
  890. segments, it is often necessary to be able to refer to the segment part
  891. of the address of a symbol. NASM supports the `SEG' operator to perform
  892. this function.
  893.    The `SEG' operator returns the *preferred* segment base of a symbol,
  894. defined as the segment base relative to which the offset of the symbol
  895. makes sense. So the code
  896.                mov ax,seg symbol
  897.                mov es,ax
  898.                mov bx,symbol
  899.    will load `ES:BX' with a valid pointer to the symbol `symbol'.
  900.    Things can be more complex than this: since 16-bit segments and
  901. groups may overlap, you might occasionally want to refer to some symbol
  902. using a different segment base from the preferred one. NASM lets you do
  903. this, by the use of the `WRT' (With Reference To) keyword. So you can
  904. do things like
  905.                mov ax,weird_seg       ; weird_seg is a segment base
  906.                mov es,ax
  907.                mov bx,symbol wrt weird_seg
  908.    to load `ES:BX' with a different, but functionally equivalent,
  909. pointer to the symbol `symbol'.
  910.    NASM supports far (inter-segment) calls and jumps by means of the
  911. syntax `call segment:offset', where `segment' and `offset' both
  912. represent immediate values. So to call a far procedure, you could code
  913. either of
  914.                call (seg procedure):procedure
  915.                call weird_seg:(procedure wrt weird_seg)
  916.    (The parentheses are included for clarity, to show the intended
  917. parsing of the above instructions. They are not necessary in practice.)
  918.    NASM supports the syntax `call far procedure' as a synonym for the
  919. first of the above usages. `JMP' works identically to `CALL' in these
  920. examples.
  921.    To declare a far pointer to a data item in a data segment, you must
  922.                dw symbol, seg symbol
  923.    NASM supports no convenient synonym for this, though you can always
  924. invent one using the macro processor.
  925. File: nasm.info,  Node: Section 3.7,  Next: Section 3.8,  Prev: Section 3.6,  Up: Chapter 3
  926. 3.7. Critical Expressions
  927. *************************
  928.    A limitation of NASM is that it is a two-pass assembler; unlike TASM
  929. and others, it will always do exactly two assembly passes. Therefore it
  930. is unable to cope with source files that are complex enough to require
  931. three or more passes.
  932.    The first pass is used to determine the size of all the assembled
  933. code and data, so that the second pass, when generating all the code,
  934. knows all the symbol addresses the code refers to. So one thing NASM
  935. can't handle is code whose size depends on the value of a symbol
  936. declared after the code in question. For example,
  937.                times (label-$) db 0
  938.      label:    db 'Where am I?'
  939.    The argument to `TIMES' in this case could equally legally evaluate
  940. to anything at all; NASM will reject this example because it cannot
  941. tell the size of the `TIMES' line when it first sees it. It will just
  942. as firmly reject the slightly paradoxical code
  943.                times (label-$+1) db 0
  944.      label:    db 'NOW where am I?'
  945.    in which *any* value for the `TIMES' argument is by definition wrong!
  946.    NASM rejects these examples by means of a concept called a *critical
  947. expression*, which is defined to be an expression whose value is
  948. required to be computable in the first pass, and which must therefore
  949. depend only on symbols defined before it. The argument to the `TIMES'
  950. prefix is a critical expression; for the same reason, the arguments to
  951. the `RESB' family of pseudo-instructions are also critical expressions.
  952.    Critical expressions can crop up in other contexts as well: consider
  953. the following code.
  954.                mov ax,symbol1
  955.      symbol1   equ symbol2
  956.      symbol2:
  957.    On the first pass, NASM cannot determine the value of `symbol1',
  958. because `symbol1' is defined to be equal to `symbol2' which NASM hasn't
  959. seen yet. On the second pass, therefore, when it encounters the line
  960. `mov ax,symbol1', it is unable to generate the code for it because it
  961. still doesn't know the value of `symbol1'. On the next line, it would
  962. see the `EQU' again and be able to determine the value of `symbol1',
  963. but by then it would be too late.
  964.    NASM avoids this problem by defining the right-hand side of an `EQU'
  965. statement to be a critical expression, so the definition of `symbol1'
  966. would be rejected in the first pass.
  967.    There is a related issue involving forward references: consider this
  968. code fragment.
  969.                mov eax,[ebx+offset]
  970.      offset    equ 10
  971.    NASM, on pass one, must calculate the size of the instruction `mov
  972. eax,[ebx+offset]' without knowing the value of `offset'. It has no way
  973. of knowing that `offset' is small enough to fit into a one- byte offset
  974. field and that it could therefore get away with generating a shorter
  975. form of the effective-address encoding; for all it knows, in pass one,
  976. `offset' could be a symbol in the code segment, and it might need the
  977. full four-byte form. So it is forced to compute the size of the
  978. instruction to accommodate a four-byte address part. In pass two, having
  979. made this decision, it is now forced to honour it and keep the
  980. instruction large, so the code generated in this case is not as small
  981. as it could have been. This problem can be solved by defining `offset'
  982. before using it, or by forcing byte size in the effective address by
  983. coding `[byte ebx+offset]'.
  984. File: nasm.info,  Node: Section 3.8,  Next: Chapter 4,  Prev: Section 3.7,  Up: Chapter 3
  985. 3.8. Local Labels
  986. *****************
  987.    NASM gives special treatment to symbols beginning with a period. A
  988. label beginning with a single period is treated as a *local* label,
  989. which means that it is associated with the previous non-local label.
  990. So, for example:
  991.      label1    ; some code
  992.      .loop     ; some more code
  993.                jne .loop
  994.                ret
  995.      label2    ; some code
  996.      .loop     ; some more code
  997.                jne .loop
  998.                ret
  999.    In the above code fragment, each `JNE' instruction jumps to the line
  1000. immediately before it, because the two definitions of `.loop' are kept
  1001. separate by virtue of each being associated with the previous non-local
  1002. label.
  1003.    This form of local label handling is borrowed from the old Amiga
  1004. assembler DevPac; however, NASM goes one step further, in allowing
  1005. access to local labels from other parts of the code. This is achieved
  1006. by means of *defining* a local label in terms of the previous non-local
  1007. label: the first definition of `.loop' above is really defining a
  1008. symbol called `label1.loop', and the second defines a symbol called
  1009. `label2.loop'. So, if you really needed to, you could write
  1010.      label3    ; some more code
  1011.                ; and some more
  1012.                jmp label1.loop
  1013.    Sometimes it is useful - in a macro, for instance - to be able to
  1014. define a label which can be referenced from anywhere but which doesn't
  1015. interfere with the normal local-label mechanism. Such a label can't be
  1016. non-local because it would interfere with subsequent definitions of,
  1017. and references to, local labels; and it can't be local because the
  1018. macro that defined it wouldn't know the label's full name. NASM
  1019. therefore introduces a third type of label, which is probably only
  1020. useful in macro definitions: if a label begins with the special prefix
  1021. `..@', then it does nothing to the local label mechanism. So you could
  1022.      label1:   ; a non-local label
  1023.      .local:   ; this is really label1.local
  1024.      ..@foo:   ; this is a special symbol
  1025.      label2:   ; another non-local label
  1026.      .local:   ; this is really label2.local
  1027.                jmp ..@foo             ; this will jump three lines up
  1028.    NASM has the capacity to define other special symbols beginning with
  1029. a double period: for example, `..start' is used to specify the entry
  1030. point in the `obj' output format (see *Note Section 6.2.6::).
  1031. File: nasm.info,  Node: Chapter 4,  Next: Section 4.1,  Prev: Section 3.8,  Up: Top
  1032. Chapter 4: The NASM Preprocessor
  1033. ********************************
  1034.    NASM contains a powerful macro processor, which supports conditional
  1035. assembly, multi-level file inclusion, two forms of macro (single-line
  1036. and multi-line), and a `context stack' mechanism for extra macro power.
  1037. Preprocessor directives all begin with a `%' sign.
  1038. * Menu:
  1039. * Section 4.1:: Single-Line Macros
  1040. * Section 4.2:: Multi-Line Macros: `%macro'
  1041. * Section 4.3:: Conditional Assembly
  1042. * Section 4.4:: Preprocessor Loops: `%rep'
  1043. * Section 4.5:: Including Other Files
  1044. * Section 4.6:: The Context Stack
  1045. * Section 4.7:: Standard Macros
  1046. File: nasm.info,  Node: Section 4.1,  Next: Section 4.1.1,  Prev: Chapter 4,  Up: Chapter 4
  1047. 4.1. Single-Line Macros
  1048. ***********************
  1049. * Menu:
  1050. * Section 4.1.1:: The Normal Way: `%define'
  1051. * Section 4.1.2:: Preprocessor Variables: `%assign'
  1052. File: nasm.info,  Node: Section 4.1.1,  Next: Section 4.1.2,  Prev: Section 4.1,  Up: Section 4.1
  1053. 4.1.1. The Normal Way: `%define'
  1054. ********************************
  1055.    Single-line macros are defined using the `%define' preprocessor
  1056. directive. The definitions work in a similar way to C; so you can do
  1057. things like
  1058.      %define ctrl 0x1F &
  1059.      %define param(a,b) ((a)+(a)*(b))
  1060.                mov byte [param(2,ebx)], ctrl 'D'
  1061.    which will expand to
  1062.                mov byte [(2)+(2)*(ebx)], 0x1F & 'D'
  1063.    When the expansion of a single-line macro contains tokens which
  1064. invoke another macro, the expansion is performed at invocation time,
  1065. not at definition time. Thus the code
  1066.      %define a(x) 1+b(x)
  1067.      %define b(x) 2*x
  1068.                mov ax,a(8)
  1069.    will evaluate in the expected way to `mov ax,1+2*8', even though the
  1070. macro `b' wasn't defined at the time of definition of `a'.
  1071.    Macros defined with `%define' are case sensitive: after `%define foo
  1072. bar', only `foo' will expand to `bar': `Foo' or `FOO' will not. By
  1073. using `%idefine' instead of `%define' (the `i' stands for
  1074. `insensitive') you can define all the case variants of a macro at once,
  1075. so that `%idefine foo bar' would cause `foo', `Foo', `FOO', `fOO' and
  1076. so on all to expand to `bar'.
  1077.    There is a mechanism which detects when a macro call has occurred as
  1078. a result of a previous expansion of the same macro, to guard against
  1079. circular references and infinite loops. If this happens, the
  1080. preprocessor will only expand the first occurrence of the macro. Hence,
  1081. if you code
  1082.      %define a(x) 1+a(x)
  1083.                mov ax,a(3)
  1084.    the macro `a(3)' will expand once, becoming `1+a(3)', and will then
  1085. expand no further. This behaviour can be useful: see *Note Section 8.1::
  1086. for an example of its use.
  1087.    You can overload single-line macros: if you write
  1088.      %define foo(x) 1+x
  1089.      %define foo(x,y) 1+x*y
  1090.    the preprocessor will be able to handle both types of macro call, by
  1091. counting the parameters you pass; so `foo(3)' will become `1+3' whereas
  1092. `foo(ebx,2)' will become `1+ebx*2'. However, if you define
  1093.      %define foo bar
  1094.    then no other definition of `foo' will be accepted: a macro with no
  1095. parameters prohibits the definition of the same name as a macro *with*
  1096. parameters, and vice versa.
  1097.    This doesn't prevent single-line macros being *redefined*: you can
  1098. perfectly well define a macro with
  1099.      %define foo bar
  1100.    and then re-define it later in the same source file with
  1101.      %define foo baz
  1102.    Then everywhere the macro `foo' is invoked, it will be expanded
  1103. according to the most recent definition. This is particularly useful
  1104. when defining single-line macros with `%assign' (see *Note Section
  1105. 4.1.2::).
  1106.    You can pre-define single-line macros using the `-d' option on the
  1107. NASM command line: see *Note Section 2.1.7::.
  1108. File: nasm.info,  Node: Section 4.1.2,  Next: Section 4.2,  Prev: Section 4.1.1,  Up: Section 4.1
  1109. 4.1.2. Preprocessor Variables: `%assign'
  1110. ****************************************
  1111.    An alternative way to define single-line macros is by means of the
  1112. `%assign' command (and its case sensitivecase-insensitive counterpart
  1113. `%iassign', which differs from `%assign' in exactly the same way that
  1114. `%idefine' differs from `%define').
  1115.    `%assign' is used to define single-line macros which take no
  1116. parameters and have a numeric value. This value can be specified in the
  1117. form of an expression, and it will be evaluated once, when the
  1118. `%assign' directive is processed.
  1119.    Like `%define', macros defined using `%assign' can be re-defined
  1120. later, so you can do things like
  1121.      %assign i i+1
  1122.    to increment the numeric value of a macro.
  1123.    `%assign' is useful for controlling the termination of `%rep'
  1124. preprocessor loops: see *Note Section 4.4:: for an example of this.
  1125. Another use for `%assign' is given in *Note Section 7.4:: and *Note
  1126. Section 8.1::.
  1127.    The expression passed to `%assign' is a critical expression (see
  1128. *Note Section 3.7::), and must also evaluate to a pure number (rather
  1129. than a relocatable reference such as a code or data address, or
  1130. anything involving a register).
  1131. File: nasm.info,  Node: Section 4.2,  Next: Section 4.2.1,  Prev: Section 4.1.2,  Up: Chapter 4
  1132. 4.2. Multi-Line Macros: `%macro'
  1133. ********************************
  1134.    Multi-line macros are much more like the type of macro seen in MASM
  1135. and TASM: a multi-line macro definition in NASM looks something like
  1136. this.
  1137.      %macro prologue 1
  1138.                push ebp
  1139.                mov ebp,esp
  1140.                sub esp,%1
  1141.      %endmacro
  1142.    This defines a C-like function prologue as a macro: so you would
  1143. invoke the macro with a call such as
  1144.      myfunc:   prologue 12
  1145.    which would expand to the three lines of code
  1146.      myfunc:   push ebp
  1147.                mov ebp,esp
  1148.                sub esp,12
  1149.    The number `1' after the macro name in the `%macro' line defines the
  1150. number of parameters the macro `prologue' expects to receive. The use
  1151. of `%1' inside the macro definition refers to the first parameter to
  1152. the macro call. With a macro taking more than one parameter, subsequent
  1153. parameters would be referred to as `%2', `%3' and so on.
  1154.    Multi-line macros, like single-line macros, are case-sensitive,
  1155. unless you define them using the alternative directive `%imacro'.
  1156.    If you need to pass a comma as *part* of a parameter to a multi-line
  1157. macro, you can do that by enclosing the entire parameter in braces. So
  1158. you could code things like
  1159.      %macro silly 2
  1160.      %2:       db %1
  1161.      %endmacro
  1162.                silly 'a', letter_a    ; letter_a:  db 'a'
  1163.                silly 'ab', string_ab  ; string_ab: db 'ab'
  1164.                silly {13,10}, crlf    ; crlf:      db 13,10
  1165. * Menu:
  1166. * Section 4.2.1:: Overloading Multi-Line Macros
  1167. * Section 4.2.2:: Macro-Local Labels
  1168. * Section 4.2.3:: Greedy Macro Parameters
  1169. * Section 4.2.4:: Default Macro Parameters
  1170. * Section 4.2.5:: `%0': Macro Parameter Counter
  1171. * Section 4.2.6:: `%rotate': Rotating Macro Parameters
  1172. * Section 4.2.7:: Concatenating Macro Parameters
  1173. * Section 4.2.8:: Condition Codes as Macro Parameters
  1174. * Section 4.2.9:: Disabling Listing Expansion
  1175. File: nasm.info,  Node: Section 4.2.1,  Next: Section 4.2.2,  Prev: Section 4.2,  Up: Section 4.2
  1176. 4.2.1. Overloading Multi-Line Macros
  1177. ************************************
  1178.    As with single-line macros, multi-line macros can be overloaded by
  1179. defining the same macro name several times with different numbers of
  1180. parameters.  This time, no exception is made for macros with no
  1181. parameters at all. So you could define
  1182.      %macro prologue 0
  1183.                push ebp
  1184.                mov ebp,esp
  1185.      %endmacro
  1186.    to define an alternative form of the function prologue which
  1187. allocates no local stack space.
  1188.    Sometimes, however, you might want to `overload' a machine
  1189. instruction; for example, you might want to define
  1190.      %macro push 2
  1191.                push %1
  1192.                push %2
  1193.      %endmacro
  1194.    so that you could code
  1195.                push ebx               ; this line is not a macro call
  1196.                push eax,ecx           ; but this one is
  1197.    Ordinarily, NASM will give a warning for the first of the above two
  1198. lines, since `push' is now defined to be a macro, and is being invoked
  1199. with a number of parameters for which no definition has been given. The
  1200. correct code will still be generated, but the assembler will give a
  1201. warning. This warning can be disabled by the use of the
  1202. `-w-macro-params' command- line option (see *Note Section 2.1.10::).
  1203. File: nasm.info,  Node: Section 4.2.2,  Next: Section 4.2.3,  Prev: Section 4.2.1,  Up: Section 4.2
  1204. 4.2.2. Macro-Local Labels
  1205. *************************
  1206.    NASM allows you to define labels within a multi-line macro
  1207. definition in such a way as to make them local to the macro call: so
  1208. calling the same macro multiple times will use a different label each
  1209. time. You do this by prefixing `%%' to the label name. So you can
  1210. invent an instruction which executes a `RET' if the `Z' flag is set by
  1211. doing this:
  1212.      %macro retz 0
  1213.                jnz %%skip
  1214.                ret
  1215.      %%skip:
  1216.      %endmacro
  1217.    You can call this macro as many times as you want, and every time
  1218. you call it NASM will make up a different `real' name to substitute for
  1219. the label `%%skip'. The names NASM invents are of the form
  1220. `..@2345.skip', where the number 2345 changes with every macro call.
  1221. The `..@' prefix prevents macro-local labels from interfering with the
  1222. local label mechanism, as described in *Note Section 3.8::. You should
  1223. avoid defining your own labels in this form (the `..@' prefix, then a
  1224. number, then another period) in case they interfere with macro-local
  1225. labels.
  1226. File: nasm.info,  Node: Section 4.2.3,  Next: Section 4.2.4,  Prev: Section 4.2.2,  Up: Section 4.2
  1227. 4.2.3. Greedy Macro Parameters
  1228. ******************************
  1229.    Occasionally it is useful to define a macro which lumps its entire
  1230. command line into one parameter definition, possibly after extracting
  1231. one or two smaller parameters from the front. An example might be a
  1232. macro to write a text string to a file in MS-DOS, where you might want
  1233. to be able to write
  1234.                writefile [filehandle],"hello, world",13,10
  1235.    NASM allows you to define the last parameter of a macro to be
  1236. *greedy*, meaning that if you invoke the macro with more parameters
  1237. than it expects, all the spare parameters get lumped into the last
  1238. defined one along with the separating commas. So if you code:
  1239.      %macro writefile 2+
  1240.                jmp %%endstr
  1241.      %%str:    db %2
  1242.      %%endstr: mov dx,%%str
  1243.                mov cx,%%endstr-%%str
  1244.                mov bx,%1
  1245.                mov ah,0x40
  1246.                int 0x21
  1247.      %endmacro
  1248.    then the example call to `writefile' above will work as expected: the
  1249. text before the first comma, `[filehandle]', is used as the first macro
  1250. parameter and expanded when `%1' is referred to, and all the subsequent
  1251. text is lumped into `%2' and placed after the `db'.
  1252.    The greedy nature of the macro is indicated to NASM by the use of the
  1253. `+' sign after the parameter count on the `%macro' line.
  1254.    If you define a greedy macro, you are effectively telling NASM how it
  1255. should expand the macro given *any* number of parameters from the
  1256. actual number specified up to infinity; in this case, for example, NASM
  1257. now knows what to do when it sees a call to `writefile' with 2, 3, 4 or
  1258. more parameters. NASM will take this into account when overloading
  1259. macros, and will not allow you to define another form of `writefile'
  1260. taking 4 parameters (for example).
  1261.    Of course, the above macro could have been implemented as a
  1262. non-greedy macro, in which case the call to it would have had to look
  1263.                writefile [filehandle], {"hello, world",13,10}
  1264.    NASM provides both mechanisms for putting commas in macro
  1265. parameters, and you choose which one you prefer for each macro
  1266. definition.
  1267.    See *Note Section 5.2.1:: for a better way to write the above macro.
  1268. File: nasm.info,  Node: Section 4.2.4,  Next: Section 4.2.5,  Prev: Section 4.2.3,  Up: Section 4.2
  1269. 4.2.4. Default Macro Parameters
  1270. *******************************
  1271.    NASM also allows you to define a multi-line macro with a *range* of
  1272. allowable parameter counts. If you do this, you can specify defaults for
  1273. omitted parameters. So, for example:
  1274.      %macro die 0-1 "Painful program death has occurred."
  1275.                writefile 2,%1
  1276.                mov ax,0x4c01
  1277.                int 0x21
  1278.      %endmacro
  1279.    This macro (which makes use of the `writefile' macro defined in
  1280. *Note Section 4.2.3::) can be called with an explicit error message,
  1281. which it will display on the error output stream before exiting, or it
  1282. can be called with no parameters, in which case it will use the default
  1283. error message supplied in the macro definition.
  1284.    In general, you supply a minimum and maximum number of parameters
  1285. for a macro of this type; the minimum number of parameters are then
  1286. required in the macro call, and then you provide defaults for the
  1287. optional ones. So if a macro definition began with the line
  1288.      %macro foobar 1-3 eax,[ebx+2]
  1289.    then it could be called with between one and three parameters, and
  1290. `%1' would always be taken from the macro call. `%2', if not specified
  1291. by the macro call, would default to `eax', and `%3' if not specified
  1292. would default to `[ebx+2]'.
  1293.    You may omit parameter defaults from the macro definition, in which
  1294. case the parameter default is taken to be blank. This can be useful for
  1295. macros which can take a variable number of parameters, since the `%0'
  1296. token (see *Note Section 4.2.5::) allows you to determine how many
  1297. parameters were really passed to the macro call.
  1298.    This defaulting mechanism can be combined with the greedy-parameter
  1299. mechanism; so the `die' macro above could be made more powerful, and
  1300. more useful, by changing the first line of the definition to
  1301.      %macro die 0-1+ "Painful program death has occurred.",13,10
  1302.    The maximum parameter count can be infinite, denoted by `*'. In this
  1303. case, of course, it is impossible to provide a *full* set of default
  1304. parameters. Examples of this usage are shown in *Note Section 4.2.6::.
  1305. File: nasm.info,  Node: Section 4.2.5,  Next: Section 4.2.6,  Prev: Section 4.2.4,  Up: Section 4.2
  1306. 4.2.5. `%0': Macro Parameter Counter
  1307. ************************************
  1308.    For a macro which can take a variable number of parameters, the
  1309. parameter reference `%0' will return a numeric constant giving the
  1310. number of parameters passed to the macro. This can be used as an
  1311. argument to `%rep' (see *Note Section 4.4::) in order to iterate
  1312. through all the parameters of a macro. Examples are given in *Note
  1313. Section 4.2.6::.
  1314. File: nasm.info,  Node: Section 4.2.6,  Next: Section 4.2.7,  Prev: Section 4.2.5,  Up: Section 4.2
  1315. 4.2.6. `%rotate': Rotating Macro Parameters
  1316. *******************************************
  1317.    Unix shell programmers will be familiar with the `shift' shell
  1318. command, which allows the arguments passed to a shell script
  1319. (referenced as `$1', `$2' and so on) to be moved left by one place, so
  1320. that the argument previously referenced as `$2' becomes available as
  1321. `$1', and the argument previously referenced as `$1' is no longer
  1322. available at all.
  1323.    NASM provides a similar mechanism, in the form of `%rotate'. As its
  1324. name suggests, it differs from the Unix `shift' in that no parameters
  1325. are lost: parameters rotated off the left end of the argument list
  1326. reappear on the right, and vice versa.
  1327.    `%rotate' is invoked with a single numeric argument (which may be an
  1328. expression). The macro parameters are rotated to the left by that many
  1329. places. If the argument to `%rotate' is negative, the macro parameters
  1330. are rotated to the right.
  1331.    So a pair of macros to save and restore a set of registers might
  1332. work as follows:
  1333.      %macro multipush 1-*
  1334.      %rep %0
  1335.                push %1
  1336.      %rotate 1
  1337.      %endrep
  1338.      %endmacro
  1339.    This macro invokes the `PUSH' instruction on each of its arguments in
  1340. turn, from left to right. It begins by pushing its first argument,
  1341. `%1', then invokes `%rotate' to move all the arguments one place to the
  1342. left, so that the original second argument is now available as `%1'.
  1343. Repeating this procedure as many times as there were arguments
  1344. (achieved by supplying `%0' as the argument to `%rep') causes each
  1345. argument in turn to be pushed.
  1346.    Note also the use of `*' as the maximum parameter count, indicating
  1347. that there is no upper limit on the number of parameters you may supply
  1348. to the `multipush' macro.
  1349.    It would be convenient, when using this macro, to have a `POP'
  1350. equivalent, which *didn't* require the arguments to be given in reverse
  1351. order. Ideally, you would write the `multipush' macro call, then
  1352. cut-and-paste the line to where the pop needed to be done, and change
  1353. the name of the called macro to `multipop', and the macro would take
  1354. care of popping the registers in the opposite order from the one in
  1355. which they were pushed.
  1356.    This can be done by the following definition:
  1357.      %macro multipop 1-*
  1358.      %rep %0
  1359.      %rotate -1
  1360.                pop %1
  1361.      %endrep
  1362.      %endmacro
  1363.    This macro begins by rotating its arguments one place to the *right*,
  1364. so that the original *last* argument appears as `%1'. This is then
  1365. popped, and the arguments are rotated right again, so the second-to-
  1366. last argument becomes `%1'. Thus the arguments are iterated through in
  1367. reverse order.
  1368. File: nasm.info,  Node: Section 4.2.7,  Next: Section 4.2.8,  Prev: Section 4.2.6,  Up: Section 4.2
  1369. 4.2.7. Concatenating Macro Parameters
  1370. *************************************
  1371.    NASM can concatenate macro parameters on to other text surrounding
  1372. them.  This allows you to declare a family of symbols, for example, in
  1373. a macro definition. If, for example, you wanted to generate a table of
  1374. key codes along with offsets into the table, you could code something
  1375.      %macro keytab_entry 2
  1376.      keypos%1 equ $-keytab
  1377.                db %2
  1378.      %endmacro
  1379.      keytab:
  1380.                keytab_entry F1,128+1
  1381.                keytab_entry F2,128+2
  1382.                keytab_entry Return,13
  1383.    which would expand to
  1384.      keytab:
  1385.      keyposF1 equ $-keytab
  1386.                db 128+1
  1387.      keyposF2 equ $-keytab
  1388.                db 128+2
  1389.      keyposReturn equ $-keytab
  1390.                db 13
  1391.    You can just as easily concatenate text on to the other end of a
  1392. macro parameter, by writing `%1foo'.
  1393.    If you need to append a *digit* to a macro parameter, for example
  1394. defining labels `foo1' and `foo2' when passed the parameter `foo', you
  1395. can't code `%11' because that would be taken as the eleventh macro
  1396. parameter. Instead, you must code `%{1}1', which will separate the
  1397. first `1' (giving the number of the macro parameter) from the second
  1398. (literal text to be concatenated to the parameter).
  1399.    This concatenation can also be applied to other preprocessor in-line
  1400. objects, such as macro-local labels (*Note Section 4.2.2::) and
  1401. context-local labels (*Note Section 4.6.2::). In all cases, ambiguities
  1402. in syntax can be resolved by enclosing everything after the `%' sign
  1403. and before the literal text in braces: so `%{%foo}bar' concatenates the
  1404. text `bar' to the end of the real name of the macro-local label
  1405. `%%foo'. (This is unnecessary, since the form NASM uses for the real
  1406. names of macro-local labels means that the two usages `%{%foo}bar' and
  1407. `%%foobar' would both expand to the same thing anyway; nevertheless,
  1408. the capability is there.)
  1409. File: nasm.info,  Node: Section 4.2.8,  Next: Section 4.2.9,  Prev: Section 4.2.7,  Up: Section 4.2
  1410. 4.2.8. Condition Codes as Macro Parameters
  1411. ******************************************
  1412.    NASM can give special treatment to a macro parameter which contains a
  1413. condition code. For a start, you can refer to the macro parameter `%1'
  1414. by means of the alternative syntax `%+1', which informs NASM that this
  1415. macro parameter is supposed to contain a condition code, and will cause
  1416. the preprocessor to report an error message if the macro is called with
  1417. a parameter which is *not* a valid condition code.
  1418.    Far more usefully, though, you can refer to the macro parameter by
  1419. means of `%-1', which NASM will expand as the *inverse* condition code.
  1420. So the `retz' macro defined in *Note Section 4.2.2:: can be replaced by
  1421. a general conditional-return macro like this:
  1422.      %macro retc 1
  1423.                j%-1 %%skip
  1424.                ret
  1425.      %%skip:
  1426.      %endmacro
  1427.    This macro can now be invoked using calls like `retc ne', which will
  1428. cause the conditional-jump instruction in the macro expansion to come
  1429. out as `JE', or `retc po' which will make the jump a `JPE'.
  1430.    The `%+1' macro-parameter reference is quite happy to interpret the
  1431. arguments `CXZ' and `ECXZ' as valid condition codes; however, `%-1'
  1432. will report an error if passed either of these, because no inverse
  1433. condition code exists.
  1434. File: nasm.info,  Node: Section 4.2.9,  Next: Section 4.3,  Prev: Section 4.2.8,  Up: Section 4.2
  1435. 4.2.9. Disabling Listing Expansion
  1436. **********************************
  1437.    When NASM is generating a listing file from your program, it will
  1438. generally expand multi-line macros by means of writing the macro call
  1439. and then listing each line of the expansion. This allows you to see
  1440. which instructions in the macro expansion are generating what code;
  1441. however, for some macros this clutters the listing up unnecessarily.
  1442.    NASM therefore provides the `.nolist' qualifier, which you can
  1443. include in a macro definition to inhibit the expansion of the macro in
  1444. the listing file. The `.nolist' qualifier comes directly after the
  1445. number of parameters, like this:
  1446.      %macro foo 1.nolist
  1447.    Or like this:
  1448.      %macro bar 1-5+.nolist a,b,c,d,e,f,g,h
  1449. File: nasm.info,  Node: Section 4.3,  Next: Section 4.3.1,  Prev: Section 4.2.9,  Up: Chapter 4
  1450. 4.3. Conditional Assembly
  1451. *************************
  1452.    Similarly to the C preprocessor, NASM allows sections of a source
  1453. file to be assembled only if certain conditions are met. The general
  1454. syntax of this feature looks like this:
  1455.      %if<condition>
  1456.      ; some code which only appears if <condition> is met
  1457.      %elif<condition2>
  1458.      ; only appears if <condition> is not met but <condition2> is
  1459.      %else
  1460.      ; this appears if neither <condition> nor <condition2> was met
  1461.      %endif
  1462.    The `%else' clause is optional, as is the `%elif' clause. You can
  1463. have more than one `%elif' clause as well.
  1464. * Menu:
  1465. * Section 4.3.1:: `%ifdef': Testing Single-Line Macro Existence
  1466. * Section 4.3.2:: `%ifctx': Testing the Context Stack
  1467. * Section 4.3.3:: `%if': Testing Arbitrary Numeric Expressions
  1468. * Section 4.3.4:: `%ifidn' and `%ifidni': Testing Exact Text Identity
  1469. * Section 4.3.5:: `%ifid', `%ifnum', `%ifstr': Testing Token Types
  1470. * Section 4.3.6:: `%error': Reporting User-Defined Errors
  1471. File: nasm.info,  Node: Section 4.3.1,  Next: Section 4.3.2,  Prev: Section 4.3,  Up: Section 4.3
  1472. 4.3.1. `%ifdef': Testing Single-Line Macro Existence
  1473. ****************************************************
  1474.    Beginning a conditional-assembly block with the line `%ifdef MACRO'
  1475. will assemble the subsequent code if, and only if, a single-line macro
  1476. called `MACRO' is defined. If not, then the `%elif' and `%else' blocks
  1477. (if any) will be processed instead.
  1478.    For example, when debugging a program, you might want to write code
  1479. such as
  1480.                ; perform some function
  1481.      %ifdef DEBUG
  1482.                writefile 2,"Function performed successfully",13,10
  1483.      %endif
  1484.                ; go and do something else
  1485.    Then you could use the command-line option `-dDEBUG' to create a
  1486. version of the program which produced debugging messages, and remove the
  1487. option to generate the final release version of the program.
  1488.    You can test for a macro *not* being defined by using `%ifndef'
  1489. instead of `%ifdef'. You can also test for macro definitions in `%elif'
  1490. blocks by using `%elifdef' and `%elifndef'.
  1491. File: nasm.info,  Node: Section 4.3.2,  Next: Section 4.3.3,  Prev: Section 4.3.1,  Up: Section 4.3
  1492. 4.3.2. `%ifctx': Testing the Context Stack
  1493. ******************************************
  1494.    The conditional-assembly construct `%ifctx ctxname' will cause the
  1495. subsequent code to be assembled if and only if the top context on the
  1496. preprocessor's context stack has the name `ctxname'. As with `%ifdef',
  1497. the inverse and `%elif' forms `%ifnctx', `%elifctx' and `%elifnctx' are
  1498. also supported.
  1499.    For more details of the context stack, see *Note Section 4.6::. For
  1500. a sample use of `%ifctx', see *Note Section 4.6.5::.
  1501. File: nasm.info,  Node: Section 4.3.3,  Next: Section 4.3.4,  Prev: Section 4.3.2,  Up: Section 4.3
  1502. 4.3.3. `%if': Testing Arbitrary Numeric Expressions
  1503. ***************************************************
  1504.    The conditional-assembly construct `%if expr' will cause the
  1505. subsequent code to be assembled if and only if the value of the numeric
  1506. expression `expr' is non-zero. An example of the use of this feature is
  1507. in deciding when to break out of a `%rep' preprocessor loop: see *Note
  1508. Section 4.4:: for a detailed example.
  1509.    The expression given to `%if', and its counterpart `%elif', is a
  1510. critical expression (see *Note Section 3.7::).
  1511.    `%if' extends the normal NASM expression syntax, by providing a set
  1512. of relational operators which are not normally available in
  1513. expressions. The operators `=', `<', `>', `<=', `>=' and `<>' test
  1514. equality, less-than, greater-than, less-or-equal, greater-or-equal and
  1515. not-equal respectively. The C-like forms `==' and `!=' are supported as
  1516. alternative forms of `=' and `<>'. In addition, low- priority logical
  1517. operators `&&', `^^' and `||' are provided, supplying logical AND,
  1518. logical XOR and logical OR. These work like the C logical operators
  1519. (although C has no logical XOR), in that they always return either 0 or
  1520. 1, and treat any non-zero input as 1 (so that `^^', for example,
  1521. returns 1 if exactly one of its inputs is zero, and 0 otherwise). The
  1522. relational operators also return 1 for true and 0 for false.
  1523. File: nasm.info,  Node: Section 4.3.4,  Next: Section 4.3.5,  Prev: Section 4.3.3,  Up: Section 4.3
  1524. 4.3.4. `%ifidn' and `%ifidni': Testing Exact Text Identity
  1525. **********************************************************
  1526.    The construct `%ifidn text1,text2' will cause the subsequent code to
  1527. be assembled if and only if `text1' and `text2', after expanding
  1528. single-line macros, are identical pieces of text. Differences in white
  1529. space are not counted.
  1530.    `%ifidni' is similar to `%ifidn', but is case-insensitive.
  1531.    For example, the following macro pushes a register or number on the
  1532. stack, and allows you to treat `IP' as a real register:
  1533.      %macro pushparam 1
  1534.      %ifidni %1,ip
  1535.                call %%label
  1536.      %%label:
  1537.      %else
  1538.                push %1
  1539.      %endif
  1540.      %endmacro
  1541.    Like most other `%if' constructs, `%ifidn' has a counterpart
  1542. `%elifidn', and negative forms `%ifnidn' and `%elifnidn'.  Similarly,
  1543. `%ifidni' has counterparts `%elifidni', `%ifnidni' and `%elifnidni'.
  1544. File: nasm.info,  Node: Section 4.3.5,  Next: Section 4.3.6,  Prev: Section 4.3.4,  Up: Section 4.3
  1545. 4.3.5. `%ifid', `%ifnum', `%ifstr': Testing Token Types
  1546. *******************************************************
  1547.    Some macros will want to perform different tasks depending on
  1548. whether they are passed a number, a string, or an identifier. For
  1549. example, a string output macro might want to be able to cope with being
  1550. passed either a string constant or a pointer to an existing string.
  1551.    The conditional assembly construct `%ifid', taking one parameter
  1552. (which may be blank), assembles the subsequent code if and only if the
  1553. first token in the parameter exists and is an identifier. `%ifnum'
  1554. works similarly, but tests for the token being a numeric constant;
  1555. `%ifstr' tests for it being a string.
  1556.    For example, the `writefile' macro defined in *Note Section 4.2.3::
  1557. can be extended to take advantage of `%ifstr' in the following fashion:
  1558.      %macro writefile 2-3+
  1559.      %ifstr %2
  1560.                jmp %%endstr
  1561.      %if %0 = 3
  1562.      %%str:      db %2,%3
  1563.      %else
  1564.      %%str:      db %2
  1565.      %endif
  1566.      %%endstr: mov dx,%%str
  1567.                mov cx,%%endstr-%%str
  1568.      %else
  1569.            mov dx,%2
  1570.            mov cx,%3
  1571.      %endif
  1572.                mov bx,%1
  1573.                mov ah,0x40
  1574.                int 0x21
  1575.      %endmacro
  1576.    Then the `writefile' macro can cope with being called in either of
  1577. the following two ways:
  1578.                writefile [file], strpointer, length
  1579.                writefile [file], "hello", 13, 10
  1580.    In the first, `strpointer' is used as the address of an already-
  1581. declared string, and `length' is used as its length; in the second, a
  1582. string is given to the macro, which therefore declares it itself and
  1583. works out the address and length for itself.
  1584.    Note the use of `%if' inside the `%ifstr': this is to detect whether
  1585. the macro was passed two arguments (so the string would be a single
  1586. string constant, and `db %2' would be adequate) or more (in which case,
  1587. all but the first two would be lumped together into `%3', and `db
  1588. %2,%3' would be required).
  1589.    The usual `%elifXXX', `%ifnXXX' and `%elifnXXX' versions exist for
  1590. each of `%ifid', `%ifnum' and `%ifstr'.
  1591. File: nasm.info,  Node: Section 4.3.6,  Next: Section 4.4,  Prev: Section 4.3.5,  Up: Section 4.3
  1592. 4.3.6. `%error': Reporting User-Defined Errors
  1593. **********************************************
  1594.    The preprocessor directive `%error' will cause NASM to report an
  1595. error if it occurs in assembled code. So if other users are going to
  1596. try to assemble your source files, you can ensure that they define the
  1597. right macros by means of code like this:
  1598.      %ifdef SOME_MACRO
  1599.      ; do some setup
  1600.      %elifdef SOME_OTHER_MACRO
  1601.      ; do some different setup
  1602.      %else
  1603.      %error Neither SOME_MACRO nor SOME_OTHER_MACRO was defined.
  1604.      %endif
  1605.    Then any user who fails to understand the way your code is supposed
  1606. to be assembled will be quickly warned of their mistake, rather than
  1607. having to wait until the program crashes on being run and then not
  1608. knowing what went wrong.
  1609. File: nasm.info,  Node: Section 4.4,  Next: Section 4.5,  Prev: Section 4.3.6,  Up: Chapter 4
  1610. 4.4. Preprocessor Loops: `%rep'
  1611. *******************************
  1612.    NASM's `TIMES' prefix, though useful, cannot be used to invoke a
  1613. multi-line macro multiple times, because it is processed by NASM after
  1614. macros have already been expanded. Therefore NASM provides another form
  1615. of loop, this time at the preprocessor level: `%rep'.
  1616.    The directives `%rep' and `%endrep' (`%rep' takes a numeric
  1617. argument, which can be an expression; `%endrep' takes no arguments) can
  1618. be used to enclose a chunk of code, which is then replicated as many
  1619. times as specified by the preprocessor:
  1620.      %assign i 0
  1621.      %rep 64
  1622.                inc word [table+2*i]
  1623.      %assign i i+1
  1624.      %endrep
  1625.    This will generate a sequence of 64 `INC' instructions, incrementing
  1626. every word of memory from `[table]' to `[table+126]'.
  1627.    For more complex termination conditions, or to break out of a repeat
  1628. loop part way along, you can use the `%exitrep' directive to terminate
  1629. the loop, like this:
  1630.      fibonacci:
  1631.      %assign i 0
  1632.      %assign j 1
  1633.      %rep 100
  1634.      %if j > 65535
  1635.      %exitrep
  1636.      %endif
  1637.                dw j
  1638.      %assign k j+i
  1639.      %assign i j
  1640.      %assign j k
  1641.      %endrep
  1642.      fib_number equ ($-fibonacci)/2
  1643.    This produces a list of all the Fibonacci numbers that will fit in
  1644. 16 bits.  Note that a maximum repeat count must still be given to
  1645. `%rep'. This is to prevent the possibility of NASM getting into an
  1646. infinite loop in the preprocessor, which (on multitasking or multi-user
  1647. systems) would typically cause all the system memory to be gradually
  1648. used up and other applications to start crashing.
  1649. File: nasm.info,  Node: Section 4.5,  Next: Section 4.6,  Prev: Section 4.4,  Up: Chapter 4
  1650. 4.5. Including Other Files
  1651. **************************
  1652.    Using, once again, a very similar syntax to the C preprocessor,
  1653. NASM's preprocessor lets you include other source files into your code.
  1654. This is done by the use of the `%include' directive:
  1655.      %include "macros.mac"
  1656.    will include the contents of the file `macros.mac' into the source
  1657. file containing the `%include' directive.
  1658.    Include files are searched for in the current directory (the
  1659. directory you're in when you run NASM, as opposed to the location of
  1660. the NASM executable or the location of the source file), plus any
  1661. directories specified on the NASM command line using the `-i' option.
  1662.    The standard C idiom for preventing a file being included more than
  1663. once is just as applicable in NASM: if the file `macros.mac' has the
  1664.      %ifndef MACROS_MAC
  1665.      %define MACROS_MAC
  1666.      ; now define some macros
  1667.      %endif
  1668.    then including the file more than once will not cause errors,
  1669. because the second time the file is included nothing will happen
  1670. because the macro `MACROS_MAC' will already be defined.
  1671.    You can force a file to be included even if there is no `%include'
  1672. directive that explicitly includes it, by using the `-p' option on the
  1673. NASM command line (see *Note Section 2.1.6::).
  1674. File: nasm.info,  Node: Section 4.6,  Next: Section 4.6.1,  Prev: Section 4.5,  Up: Chapter 4
  1675. 4.6. The Context Stack
  1676. **********************
  1677.    Having labels that are local to a macro definition is sometimes not
  1678. quite powerful enough: sometimes you want to be able to share labels
  1679. between several macro calls. An example might be a `REPEAT' ... `UNTIL'
  1680. loop, in which the expansion of the `REPEAT' macro would need to be
  1681. able to refer to a label which the `UNTIL' macro had defined. However,
  1682. for such a macro you would also want to be able to nest these loops.
  1683.    NASM provides this level of power by means of a *context stack*. The
  1684. preprocessor maintains a stack of *contexts*, each of which is
  1685. characterised by a name. You add a new context to the stack using the
  1686. `%push' directive, and remove one using `%pop'. You can define labels
  1687. that are local to a particular context on the stack.
  1688. * Menu:
  1689. * Section 4.6.1:: `%push' and `%pop': Creating and Removing Contexts
  1690. * Section 4.6.2:: Context-Local Labels
  1691. * Section 4.6.3:: Context-Local Single-Line Macros
  1692. * Section 4.6.4:: `%repl': Renaming a Context
  1693. * Section 4.6.5:: Example Use of the Context Stack: Block IFs
  1694. File: nasm.info,  Node: Section 4.6.1,  Next: Section 4.6.2,  Prev: Section 4.6,  Up: Section 4.6
  1695. 4.6.1. `%push' and `%pop': Creating and Removing Contexts
  1696. *********************************************************
  1697.    The `%push' directive is used to create a new context and place it on
  1698. the top of the context stack. `%push' requires one argument, which is
  1699. the name of the context. For example:
  1700.      %push foobar
  1701.    This pushes a new context called `foobar' on the stack. You can have
  1702. several contexts on the stack with the same name: they can still be
  1703. distinguished.
  1704.    The directive `%pop', requiring no arguments, removes the top context
  1705. from the context stack and destroys it, along with any labels associated
  1706. with it.
  1707. File: nasm.info,  Node: Section 4.6.2,  Next: Section 4.6.3,  Prev: Section 4.6.1,  Up: Section 4.6
  1708. 4.6.2. Context-Local Labels
  1709. ***************************
  1710.    Just as the usage `%%foo' defines a label which is local to the
  1711. particular macro call in which it is used, the usage `%$foo' is used to
  1712. define a label which is local to the context on the top of the context
  1713. stack. So the `REPEAT' and `UNTIL' example given above could be
  1714. implemented by means of:
  1715.      %macro repeat 0
  1716.      %push repeat
  1717.      %$begin:
  1718.      %endmacro
  1719.      %macro until 1
  1720.                j%-1 %$begin
  1721.      %pop
  1722.      %endmacro
  1723.    and invoked by means of, for example,
  1724.                mov cx,string
  1725.                repeat
  1726.                add cx,3
  1727.                scasb
  1728.                until e
  1729.    which would scan every fourth byte of a string in search of the byte
  1730. in `AL'.
  1731.    If you need to define, or access, labels local to the context *below*
  1732. the top one on the stack, you can use `%$$foo', or `%$$$foo' for the
  1733. context below that, and so on.
  1734. File: nasm.info,  Node: Section 4.6.3,  Next: Section 4.6.4,  Prev: Section 4.6.2,  Up: Section 4.6
  1735. 4.6.3. Context-Local Single-Line Macros
  1736. ***************************************
  1737.    NASM also allows you to define single-line macros which are local to
  1738. a particular context, in just the same way:
  1739.      %define %$localmac 3
  1740.    will define the single-line macro `%$localmac' to be local to the top
  1741. context on the stack. Of course, after a subsequent `%push', it can
  1742. then still be accessed by the name `%$$localmac'.
  1743. File: nasm.info,  Node: Section 4.6.4,  Next: Section 4.6.5,  Prev: Section 4.6.3,  Up: Section 4.6
  1744. 4.6.4. `%repl': Renaming a Context
  1745. **********************************
  1746.    If you need to change the name of the top context on the stack (in
  1747. order, for example, to have it respond differently to `%ifctx'), you can
  1748. execute a `%pop' followed by a `%push'; but this will have the side
  1749. effect of destroying all context-local labels and macros associated
  1750. with the context that was just popped.
  1751.    NASM provides the directive `%repl', which *replaces* a context with
  1752. a different name, without touching the associated macros and labels.
  1753. So you could replace the destructive code
  1754.      %pop
  1755.      %push newname
  1756.    with the non-destructive version `%repl newname'.
  1757. File: nasm.info,  Node: Section 4.6.5,  Next: Section 4.7,  Prev: Section 4.6.4,  Up: Section 4.6
  1758. 4.6.5. Example Use of the Context Stack: Block IFs
  1759. **************************************************
  1760.    This example makes use of almost all the context-stack features,
  1761. including the conditional-assembly construct `%ifctx', to implement a
  1762. block IF statement as a set of macros.
  1763.      %macro if 1
  1764.          %push if
  1765.          j%-1 %$ifnot
  1766.      %endmacro
  1767.      %macro else 0
  1768.          %ifctx if
  1769.              %repl else
  1770.              jmp %$ifend
  1771.              %$ifnot:
  1772.          %else
  1773.              %error "expected `if' before `else'"
  1774.          %endif
  1775.      %endmacro
  1776.      %macro endif 0
  1777.          %ifctx if
  1778.              %$ifnot:
  1779.              %pop
  1780.          %elifctx else
  1781.              %$ifend:
  1782.              %pop
  1783.          %else
  1784.              %error "expected `if' or `else' before `endif'"
  1785.          %endif
  1786.      %endmacro
  1787.    This code is more robust than the `REPEAT' and `UNTIL' macros given
  1788. in *Note Section 4.6.2::, because it uses conditional assembly to check
  1789. that the macros are issued in the right order (for example, not calling
  1790. `endif' before `if') and issues a `%error' if they're not.
  1791.    In addition, the `endif' macro has to be able to cope with the two
  1792. distinct cases of either directly following an `if', or following an
  1793. `else'. It achieves this, again, by using conditional assembly to do
  1794. different things depending on whether the context on top of the stack is
  1795. `if' or `else'.
  1796.    The `else' macro has to preserve the context on the stack, in order
  1797. to have the `%$ifnot' referred to by the `if' macro be the same as the
  1798. one defined by the `endif' macro, but has to change the context's name
  1799. so that `endif' will know there was an intervening `else'.  It does
  1800. this by the use of `%repl'.
  1801.    A sample usage of these macros might look like:
  1802.                cmp ax,bx
  1803.                if ae
  1804.                  cmp bx,cx
  1805.                  if ae
  1806.                    mov ax,cx
  1807.                  else
  1808.                    mov ax,bx
  1809.                  endif
  1810.                else
  1811.                  cmp ax,cx
  1812.                  if ae
  1813.                    mov ax,cx
  1814.                  endif
  1815.                endif
  1816.    The block-`IF' macros handle nesting quite happily, by means of
  1817. pushing another context, describing the inner `if', on top of the one
  1818. describing the outer `if'; thus `else' and `endif' always refer to the
  1819. last unmatched `if' or `else'.
  1820. File: nasm.info,  Node: Section 4.7,  Next: Section 4.7.1,  Prev: Section 4.6.5,  Up: Chapter 4
  1821. 4.7. Standard Macros
  1822. ********************
  1823.    NASM defines a set of standard macros, which are already defined
  1824. when it starts to process any source file. If you really need a program
  1825. to be assembled with no pre-defined macros, you can use the `%clear'
  1826. directive to empty the preprocessor of everything.
  1827.    Most user-level assembler directives (see *Note Chapter 5::) are
  1828. implemented as macros which invoke primitive directives; these are
  1829. described in *Note Chapter 5::. The rest of the standard macro set is
  1830. described here.
  1831. * Menu:
  1832. * Section 4.7.1:: `__NASM_MAJOR__' and `__NASM_MINOR__': NASM Version
  1833. * Section 4.7.2:: `__FILE__' and `__LINE__': File Name and Line Number
  1834. * Section 4.7.3:: `STRUC' and `ENDSTRUC': Declaring Structure Data Types
  1835. * Section 4.7.4:: `ISTRUC', `AT' and `IEND': Declaring Instances of Structures
  1836. * Section 4.7.5:: `ALIGN' and `ALIGNB': Data Alignment
  1837. File: nasm.info,  Node: Section 4.7.1,  Next: Section 4.7.2,  Prev: Section 4.7,  Up: Section 4.7
  1838. 4.7.1. `__NASM_MAJOR__' and `__NASM_MINOR__': NASM Version
  1839. **********************************************************
  1840.    The single-line macros `__NASM_MAJOR__' and `__NASM_MINOR__' expand
  1841. to the major and minor parts of the version number of NASM being used.
  1842. So, under NASM 0.96 for example, `__NASM_MAJOR__' would be defined to
  1843. be 0 and `__NASM_MINOR__' would be defined as 96.
  1844. File: nasm.info,  Node: Section 4.7.2,  Next: Section 4.7.3,  Prev: Section 4.7.1,  Up: Section 4.7
  1845. 4.7.2. `__FILE__' and `__LINE__': File Name and Line Number
  1846. ***********************************************************
  1847.    Like the C preprocessor, NASM allows the user to find out the file
  1848. name and line number containing the current instruction. The macro
  1849. `__FILE__' expands to a string constant giving the name of the current
  1850. input file (which may change through the course of assembly if
  1851. `%include' directives are used), and `__LINE__' expands to a numeric
  1852. constant giving the current line number in the input file.
  1853.    These macros could be used, for example, to communicate debugging
  1854. information to a macro, since invoking `__LINE__' inside a macro
  1855. definition (either single-line or multi-line) will return the line
  1856. number of the macro *call*, rather than *definition*. So to determine
  1857. where in a piece of code a crash is occurring, for example, one could
  1858. write a routine `stillhere', which is passed a line number in `EAX' and
  1859. outputs something like `line 155: still here'. You could then write a
  1860. macro
  1861.      %macro notdeadyet 0
  1862.                push eax
  1863.                mov eax,__LINE__
  1864.                call stillhere
  1865.                pop eax
  1866.      %endmacro
  1867.    and then pepper your code with calls to `notdeadyet' until you find
  1868. the crash point.
  1869. File: nasm.info,  Node: Section 4.7.3,  Next: Section 4.7.4,  Prev: Section 4.7.2,  Up: Section 4.7
  1870. 4.7.3. `STRUC' and `ENDSTRUC': Declaring Structure Data Types
  1871. *************************************************************
  1872.    The core of NASM contains no intrinsic means of defining data
  1873. structures; instead, the preprocessor is sufficiently powerful that
  1874. data structures can be implemented as a set of macros. The macros
  1875. `STRUC' and `ENDSTRUC' are used to define a structure data type.
  1876.    `STRUC' takes one parameter, which is the name of the data type. This
  1877. name is defined as a symbol with the value zero, and also has the suffix
  1878. `_size' appended to it and is then defined as an `EQU' giving the size
  1879. of the structure. Once `STRUC' has been issued, you are defining the
  1880. structure, and should define fields using the `RESB' family of
  1881. pseudo-instructions, and then invoke `ENDSTRUC' to finish the
  1882. definition.
  1883.    For example, to define a structure called `mytype' containing a
  1884. longword, a word, a byte and a string of bytes, you might code
  1885.                struc mytype
  1886.      mt_long:  resd 1
  1887.      mt_word:  resw 1
  1888.      mt_byte:  resb 1
  1889.      mt_str:   resb 32
  1890.                endstruc
  1891.    The above code defines six symbols: `mt_long' as 0 (the offset from
  1892. the beginning of a `mytype' structure to the longword field), `mt_word'
  1893. as 4, `mt_byte' as 6, `mt_str' as 7, `mytype_size' as 39, and `mytype'
  1894. itself as zero.
  1895.    The reason why the structure type name is defined at zero is a side
  1896. effect of allowing structures to work with the local label mechanism:
  1897. if your structure members tend to have the same names in more than one
  1898. structure, you can define the above structure like this:
  1899.                struc mytype
  1900.      .long:    resd 1
  1901.      .word:    resw 1
  1902.      .byte:    resb 1
  1903.      .str:     resb 32
  1904.                endstruc
  1905.    This defines the offsets to the structure fields as `mytype.long',
  1906. `mytype.word', `mytype.byte' and `mytype.str'.
  1907.    NASM, since it has no *intrinsic* structure support, does not support
  1908. any form of period notation to refer to the elements of a structure once
  1909. you have one (except the above local-label notation), so code such as
  1910. `mov ax,[mystruc.mt_word]' is not valid. `mt_word' is a constant just
  1911. like any other constant, so the correct syntax is `mov
  1912. ax,[mystruc+mt_word]' or `mov ax,[mystruc+mytype.word]'.
  1913. File: nasm.info,  Node: Section 4.7.4,  Next: Section 4.7.5,  Prev: Section 4.7.3,  Up: Section 4.7
  1914. 4.7.4. `ISTRUC', `AT' and `IEND': Declaring Instances of Structures
  1915. *******************************************************************
  1916.    Having defined a structure type, the next thing you typically want
  1917. to do is to declare instances of that structure in your data segment.
  1918. NASM provides an easy way to do this in the `ISTRUC' mechanism. To
  1919. declare a structure of type `mytype' in a program, you code something
  1920. like this:
  1921.      mystruc:  istruc mytype
  1922.                at mt_long, dd 123456
  1923.                at mt_word, dw 1024
  1924.                at mt_byte, db 'x'
  1925.                at mt_str, db 'hello, world', 13, 10, 0
  1926.                iend
  1927.    The function of the `AT' macro is to make use of the `TIMES' prefix
  1928. to advance the assembly position to the correct point for the specified
  1929. structure field, and then to declare the specified data.  Therefore the
  1930. structure fields must be declared in the same order as they were
  1931. specified in the structure definition.
  1932.    If the data to go in a structure field requires more than one source
  1933. line to specify, the remaining source lines can easily come after the
  1934. `AT' line. For example:
  1935.                at mt_str, db 123,134,145,156,167,178,189
  1936.                db 190,100,0
  1937.    Depending on personal taste, you can also omit the code part of the
  1938. `AT' line completely, and start the structure field on the next line:
  1939.                at mt_str
  1940.                db 'hello, world'
  1941.                db 13,10,0
  1942. File: nasm.info,  Node: Section 4.7.5,  Next: Chapter 5,  Prev: Section 4.7.4,  Up: Section 4.7
  1943. 4.7.5. `ALIGN' and `ALIGNB': Data Alignment
  1944. *******************************************
  1945.    The `ALIGN' and `ALIGNB' macros provides a convenient way to align
  1946. code or data on a word, longword, paragraph or other boundary. (Some
  1947. assemblers call this directive `EVEN'.) The syntax of the `ALIGN' and
  1948. `ALIGNB' macros is
  1949.                align 4                ; align on 4-byte boundary
  1950.                align 16               ; align on 16-byte boundary
  1951.                align 8,db 0           ; pad with 0s rather than NOPs
  1952.                align 4,resb 1         ; align to 4 in the BSS
  1953.                alignb 4               ; equivalent to previous line
  1954.    Both macros require their first argument to be a power of two; they
  1955. both compute the number of additional bytes required to bring the
  1956. length of the current section up to a multiple of that power of two,
  1957. and then apply the `TIMES' prefix to their second argument to perform
  1958. the alignment.
  1959.    If the second argument is not specified, the default for `ALIGN' is
  1960. `NOP', and the default for `ALIGNB' is `RESB 1'. So if the second
  1961. argument is specified, the two macros are equivalent. Normally, you can
  1962. just use `ALIGN' in code and data sections and `ALIGNB' in BSS
  1963. sections, and never need the second argument except for special
  1964. purposes.
  1965.    `ALIGN' and `ALIGNB', being simple macros, perform no error
  1966. checking: they cannot warn you if their first argument fails to be a
  1967. power of two, or if their second argument generates more than one byte
  1968. of code.  In each of these cases they will silently do the wrong thing.
  1969.    `ALIGNB' (or `ALIGN' with a second argument of `RESB 1') can be used
  1970. within structure definitions:
  1971.                struc mytype2
  1972.      mt_byte:  resb 1
  1973.                alignb 2
  1974.      mt_word:  resw 1
  1975.                alignb 4
  1976.      mt_long:  resd 1
  1977.      mt_str:   resb 32
  1978.                endstruc
  1979.    This will ensure that the structure members are sensibly aligned
  1980. relative to the base of the structure.
  1981.    A final caveat: `ALIGN' and `ALIGNB' work relative to the beginning
  1982. of the *section*, not the beginning of the address space in the final
  1983. executable. Aligning to a 16-byte boundary when the section you're in
  1984. is only guaranteed to be aligned to a 4-byte boundary, for example, is
  1985. a waste of effort. Again, NASM does not check that the section's
  1986. alignment characteristics are sensible for the use of `ALIGN' or
  1987. `ALIGNB'.
  1988. File: nasm.info,  Node: Chapter 5,  Next: Section 5.1,  Prev: Section 4.7.5,  Up: Top
  1989. Chapter 5: Assembler Directives
  1990. *******************************
  1991.    NASM, though it attempts to avoid the bureaucracy of assemblers like
  1992. MASM and TASM, is nevertheless forced to support a *few* directives.
  1993. These are described in this chapter.
  1994.    NASM's directives come in two types: user-level
  1995. directives*user-level* directives and primitive directives*primitive*
  1996. directives. Typically, each directive has a user-level form and a
  1997. primitive form. In almost all cases, we recommend that users use the
  1998. user-level forms of the directives, which are implemented as macros
  1999. which call the primitive forms.
  2000.    Primitive directives are enclosed in square brackets; user-level
  2001. directives are not.
  2002.    In addition to the universal directives described in this chapter,
  2003. each object file format can optionally supply extra directives in order
  2004. to control particular features of that file format. These
  2005. format-specific directives*format-specific* directives are documented
  2006. along with the formats that implement them, in *Note Chapter 6::.
  2007. * Menu:
  2008. * Section 5.1:: `BITS': Specifying Target Processor Mode
  2009. * Section 5.2:: `SECTION' or `SEGMENT': Changing and Defining Sections
  2010. * Section 5.3:: `ABSOLUTE': Defining Absolute Labels
  2011. * Section 5.4:: `EXTERN': Importing Symbols from Other Modules
  2012. * Section 5.5:: `GLOBAL': Exporting Symbols to Other Modules
  2013. * Section 5.6:: `COMMON': Defining Common Data Areas
  2014. File: nasm.info,  Node: Section 5.1,  Next: Section 5.2,  Prev: Chapter 5,  Up: Chapter 5
  2015. 5.1. `BITS': Specifying Target Processor Mode
  2016. *********************************************
  2017.    The `BITS' directive specifies whether NASM should generate code
  2018. designed to run on a processor operating in 16-bit mode, or code
  2019. designed to run on a processor operating in 32-bit mode. The syntax is
  2020. `BITS 16' or `BITS 32'.
  2021.    In most cases, you should not need to use `BITS' explicitly. The
  2022. `aout', `coff', `elf' and `win32' object formats, which are designed
  2023. for use in 32-bit operating systems, all cause NASM to select 32-bit
  2024. mode by default. The `obj' object format allows you to specify each
  2025. segment you define as either `USE16' or `USE32', and NASM will set its
  2026. operating mode accordingly, so the use of the `BITS' directive is once
  2027. again unnecessary.
  2028.    The most likely reason for using the `BITS' directive is to write 32-
  2029. bit code in a flat binary file; this is because the `bin' output format
  2030. defaults to 16-bit mode in anticipation of it being used most
  2031. frequently to write DOS `.COM' programs, DOS `.SYS' device drivers and
  2032. boot loader software.
  2033.    You do *not* need to specify `BITS 32' merely in order to use 32-
  2034. bit instructions in a 16-bit DOS program; if you do, the assembler will
  2035. generate incorrect code because it will be writing code targeted at a
  2036. 32- bit platform, to be run on a 16-bit one.
  2037.    When NASM is in `BITS 16' state, instructions which use 32-bit data
  2038. are prefixed with an 0x66 byte, and those referring to 32-bit addresses
  2039. have an 0x67 prefix. In `BITS 32' state, the reverse is true: 32-bit
  2040. instructions require no prefixes, whereas instructions using 16-bit data
  2041. need an 0x66 and those working in 16-bit addresses need an 0x67.
  2042.    The `BITS' directive has an exactly equivalent primitive form,
  2043. `[BITS 16]' and `[BITS 32]'. The user-level form is a macro which has
  2044. no function other than to call the primitive form.
  2045. File: nasm.info,  Node: Section 5.2,  Next: Section 5.2.1,  Prev: Section 5.1,  Up: Chapter 5
  2046. 5.2. `SECTION' or `SEGMENT': Changing and Defining Sections
  2047. ***********************************************************
  2048.    The `SECTION' directive (`SEGMENT' is an exactly equivalent synonym)
  2049. changes which section of the output file the code you write will be
  2050. assembled into. In some object file formats, the number and names of
  2051. sections are fixed; in others, the user may make up as many as they
  2052. wish.  Hence `SECTION' may sometimes give an error message, or may
  2053. define a new section, if you try to switch to a section that does not
  2054. (yet) exist.
  2055.    The Unix object formats, and the `bin' object format, all support the
  2056. standardised section names `.text', `.data' and `.bss' for the code,
  2057. data and uninitialised-data sections. The `obj' format, by contrast,
  2058. does not recognise these section names as being special, and indeed
  2059. will strip off the leading period of any section name that has one.
  2060. * Menu:
  2061. * Section 5.2.1:: The `__SECT__' Macro
  2062. File: nasm.info,  Node: Section 5.2.1,  Next: Section 5.3,  Prev: Section 5.2,  Up: Section 5.2
  2063. 5.2.1. The `__SECT__' Macro
  2064. ***************************
  2065.    The `SECTION' directive is unusual in that its user-level form
  2066. functions differently from its primitive form. The primitive form,
  2067. `[SECTION xyz]', simply switches the current target section to the one
  2068. given. The user-level form, `SECTION xyz', however, first defines the
  2069. single-line macro `__SECT__' to be the primitive `[SECTION]' directive
  2070. which it is about to issue, and then issues it. So the user-level
  2071. directive
  2072.                SECTION .text
  2073.    expands to the two lines
  2074.      %define __SECT__ [SECTION .text]
  2075.                [SECTION .text]
  2076.    Users may find it useful to make use of this in their own macros. For
  2077. example, the `writefile' macro defined in *Note Section 4.2.3:: can be
  2078. usefully rewritten in the following more sophisticated form:
  2079.      %macro writefile 2+
  2080.                [section .data]
  2081.      %%str:    db %2
  2082.      %%endstr:
  2083.                __SECT__
  2084.                mov dx,%%str
  2085.                mov cx,%%endstr-%%str
  2086.                mov bx,%1
  2087.                mov ah,0x40
  2088.                int 0x21
  2089.      %endmacro
  2090.    This form of the macro, once passed a string to output, first
  2091. switches temporarily to the data section of the file, using the
  2092. primitive form of the `SECTION' directive so as not to modify
  2093. `__SECT__'. It then declares its string in the data section, and then
  2094. invokes `__SECT__' to switch back to *whichever* section the user was
  2095. previously working in. It thus avoids the need, in the previous version
  2096. of the macro, to include a `JMP' instruction to jump over the data, and
  2097. also does not fail if, in a complicated `OBJ' format module, the user
  2098. could potentially be assembling the code in any of several separate code
  2099. sections.
  2100. File: nasm.info,  Node: Section 5.3,  Next: Section 5.4,  Prev: Section 5.2.1,  Up: Chapter 5
  2101. 5.3. `ABSOLUTE': Defining Absolute Labels
  2102. *****************************************
  2103.    The `ABSOLUTE' directive can be thought of as an alternative form of
  2104. `SECTION': it causes the subsequent code to be directed at no physical
  2105. section, but at the hypothetical section starting at the given absolute
  2106. address. The only instructions you can use in this mode are the `RESB'
  2107. family.
  2108.    `ABSOLUTE' is used as follows:
  2109.                absolute 0x1A
  2110.      kbuf_chr  resw 1
  2111.      kbuf_free resw 1
  2112.      kbuf      resw 16
  2113.    This example describes a section of the PC BIOS data area, at segment
  2114. address 0x40: the above code defines `kbuf_chr' to be 0x1A, `kbuf_free'
  2115. to be 0x1C, and `kbuf' to be 0x1E.
  2116.    The user-level form of `ABSOLUTE', like that of `SECTION', redefines
  2117. the `__SECT__' macro when it is invoked.
  2118.    `STRUC' and `ENDSTRUC' are defined as macros which use `ABSOLUTE'
  2119. (and also `__SECT__').
  2120.    `ABSOLUTE' doesn't have to take an absolute constant as an argument:
  2121. it can take an expression (actually, a critical expression: see *Note
  2122. Section 3.7::) and it can be a value in a segment. For example, a TSR
  2123. can re-use its setup code as run-time BSS like this:
  2124.                org 100h               ; it's a .COM program
  2125.                jmp setup              ; setup code comes last
  2126.                ; the resident part of the TSR goes here
  2127.      setup:    ; now write the code that installs the TSR here
  2128.                absolute setup
  2129.      runtimevar1 resw 1
  2130.      runtimevar2 resd 20
  2131.      tsr_end:
  2132.    This defines some variables `on top of' the setup code, so that
  2133. after the setup has finished running, the space it took up can be
  2134. re-used as data storage for the running TSR. The symbol `tsr_end' can
  2135. be used to calculate the total size of the part of the TSR that needs
  2136. to be made resident.
  2137. File: nasm.info,  Node: Section 5.4,  Next: Section 5.5,  Prev: Section 5.3,  Up: Chapter 5
  2138. 5.4. `EXTERN': Importing Symbols from Other Modules
  2139. ***************************************************
  2140.    `EXTERN' is similar to the MASM directive `EXTRN' and the C keyword
  2141. `extern': it is used to declare a symbol which is not defined anywhere
  2142. in the module being assembled, but is assumed to be defined in some
  2143. other module and needs to be referred to by this one. Not every
  2144. object-file format can support external variables: the `bin' format
  2145. cannot.
  2146.    The `EXTERN' directive takes as many arguments as you like. Each
  2147. argument is the name of a symbol:
  2148.                extern _printf
  2149.                extern _sscanf,_fscanf
  2150.    Some object-file formats provide extra features to the `EXTERN'
  2151. directive. In all cases, the extra features are used by suffixing a
  2152. colon to the symbol name followed by object-format specific text. For
  2153. example, the `obj' format allows you to declare that the default
  2154. segment base of an external should be the group `dgroup' by means of
  2155. the directive
  2156.                extern _variable:wrt dgroup
  2157.    The primitive form of `EXTERN' differs from the user-level form only
  2158. in that it can take only one argument at a time: the support for
  2159. multiple arguments is implemented at the preprocessor level.
  2160.    You can declare the same variable as `EXTERN' more than once: NASM
  2161. will quietly ignore the second and later redeclarations. You can't
  2162. declare a variable as `EXTERN' as well as something else, though.
  2163. File: nasm.info,  Node: Section 5.5,  Next: Section 5.6,  Prev: Section 5.4,  Up: Chapter 5
  2164. 5.5. `GLOBAL': Exporting Symbols to Other Modules
  2165. *************************************************
  2166.    `GLOBAL' is the other end of `EXTERN': if one module declares a
  2167. symbol as `EXTERN' and refers to it, then in order to prevent linker
  2168. errors, some other module must actually *define* the symbol and declare
  2169. it as `GLOBAL'. Some assemblers use the name `PUBLIC' for this purpose.
  2170.    The `GLOBAL' directive applying to a symbol must appear *before* the
  2171. definition of the symbol.
  2172.    `GLOBAL' uses the same syntax as `EXTERN', except that it must refer
  2173. to symbols which *are* defined in the same module as the `GLOBAL'
  2174. directive. For example:
  2175.                global _main
  2176.      _main:    ; some code
  2177.    `GLOBAL', like `EXTERN', allows object formats to define private
  2178. extensions by means of a colon. The `elf' object format, for example,
  2179. lets you specify whether global data items are functions or data:
  2180.                global hashlookup:function, hashtable:data
  2181.    Like `EXTERN', the primitive form of `GLOBAL' differs from the
  2182. user-level form only in that it can take only one argument at a time.
  2183. File: nasm.info,  Node: Section 5.6,  Next: Chapter 6,  Prev: Section 5.5,  Up: Chapter 5
  2184. 5.6. `COMMON': Defining Common Data Areas
  2185. *****************************************
  2186.    The `COMMON' directive is used to declare *common variables*. A
  2187. common variable is much like a global variable declared in the
  2188. uninitialised data section, so that
  2189.                common intvar 4
  2190.    is similar in function to
  2191.                global intvar
  2192.                section .bss
  2193.      intvar    resd 1
  2194.    The difference is that if more than one module defines the same
  2195. common variable, then at link time those variables will be *merged*, and
  2196. references to `intvar' in all modules will point at the same piece of
  2197. memory.
  2198.    Like `GLOBAL' and `EXTERN', `COMMON' supports object-format specific
  2199. extensions. For example, the `obj' format allows common variables to be
  2200. NEAR or FAR, and the `elf' format allows you to specify the alignment
  2201. requirements of a common variable:
  2202.                common commvar 4:near  ; works in OBJ
  2203.                common intarray 100:4  ; works in ELF: 4 byte aligned
  2204.    Once again, like `EXTERN' and `GLOBAL', the primitive form of
  2205. `COMMON' differs from the user-level form only in that it can take only
  2206. one argument at a time.
  2207. File: nasm.info,  Node: Chapter 6,  Next: Section 6.1,  Prev: Section 5.6,  Up: Top
  2208. Chapter 6: Output Formats
  2209. *************************
  2210.    NASM is a portable assembler, designed to be able to compile on any
  2211. ANSI C- supporting platform and produce output to run on a variety of
  2212. Intel x86 operating systems. For this reason, it has a large number of
  2213. available output formats, selected using the `-f' option on the NASM
  2214. command line. Each of these formats, along with its extensions to the
  2215. base NASM syntax, is detailed in this chapter.
  2216.    As stated in *Note Section 2.1.1::, NASM chooses a default name for
  2217. your output file based on the input file name and the chosen output
  2218. format. This will be generated by removing the extension (`.asm', `.s',
  2219. or whatever you like to use) from the input file name, and substituting
  2220. an extension defined by the output format. The extensions are given
  2221. with each format below.
  2222. * Menu:
  2223. * Section 6.1:: `bin': Flat-Form Binary Output
  2224. * Section 6.2:: `obj': Microsoft OMF Object Files
  2225. * Section 6.3:: `win32': Microsoft Win32 Object Files
  2226. * Section 6.4:: `coff': Common Object File Format
  2227. * Section 6.5:: `elf': Linux ELFObject Files
  2228. * Section 6.6:: `aout': Linux `a.out' Object Files
  2229. * Section 6.7:: `aoutb': NetBSD/FreeBSD/OpenBSD `a.out' Object Files
  2230. * Section 6.8:: `as86': Linux `as86' Object Files
  2231. * Section 6.9:: `rdf': Relocatable Dynamic Object File Format
  2232. * Section 6.10:: `dbg': Debugging Format
  2233. File: nasm.info,  Node: Section 6.1,  Next: Section 6.1.1,  Prev: Chapter 6,  Up: Chapter 6
  2234. 6.1. `bin': Flat-Form Binary Output
  2235. ***********************************
  2236.    The `bin' format does not produce object files: it generates nothing
  2237. in the output file except the code you wrote. Such `pure binary' files
  2238. are used by MS-DOS: `.COM' executables and `.SYS' device drivers are
  2239. pure binary files. Pure binary output is also useful for
  2240. operating-system and boot loader development.
  2241.    `bin' supports the three standardised section names `.text', `.data'
  2242. and `.bss' only. The file NASM outputs will contain the contents of the
  2243. `.text' section first, followed by the contents of the `.data' section,
  2244. aligned on a four-byte boundary. The `.bss' section is not stored in
  2245. the output file at all, but is assumed to appear directly after the end
  2246. of the `.data' section, again aligned on a four-byte boundary.
  2247.    If you specify no explicit `SECTION' directive, the code you write
  2248. will be directed by default into the `.text' section.
  2249.    Using the `bin' format puts NASM by default into 16-bit mode (see
  2250. *Note Section 5.1::). In order to use `bin' to write 32-bit code such as
  2251. an OS kernel, you need to explicitly issue the `BITS 32' directive.
  2252.    `bin' has no default output file name extension: instead, it leaves
  2253. your file name as it is once the original extension has been removed.
  2254. Thus, the default is for NASM to assemble `binprog.asm' into a binary
  2255. file called `binprog'.
  2256. * Menu:
  2257. * Section 6.1.1:: `ORG': Binary File Program Origin
  2258. * Section 6.1.2:: `bin' Extensions to the `SECTION' Directive
  2259. File: nasm.info,  Node: Section 6.1.1,  Next: Section 6.1.2,  Prev: Section 6.1,  Up: Section 6.1
  2260. 6.1.1. `ORG': Binary File Program Origin
  2261. ****************************************
  2262.    The `bin' format provides an additional directive to the list given
  2263. in *Note Chapter 5::: `ORG'. The function of the `ORG' directive is to
  2264. specify the origin address which NASM will assume the program begins at
  2265. when it is loaded into memory.
  2266.    For example, the following code will generate the longword
  2267. `0x00000104':
  2268.                org 0x100
  2269.                dd label
  2270.      label:
  2271.    Unlike the `ORG' directive provided by MASM-compatible assemblers,
  2272. which allows you to jump around in the object file and overwrite code
  2273. you have already generated, NASM's `ORG' does exactly what the directive
  2274. says: *origin*. Its sole function is to specify one offset which is
  2275. added to all internal address references within the file; it does not
  2276. permit any of the trickery that MASM's version does. See *Note Section
  2277. 10.1.3:: for further comments.
  2278. File: nasm.info,  Node: Section 6.1.2,  Next: Section 6.2,  Prev: Section 6.1.1,  Up: Section 6.1
  2279. 6.1.2. `bin' Extensions to the `SECTION' Directive
  2280. **************************************************
  2281.    The `bin' output format extends the `SECTION' (or `SEGMENT')
  2282. directive to allow you to specify the alignment requirements of
  2283. segments.  This is done by appending the `ALIGN' qualifier to the end
  2284. of the section-definition line. For example,
  2285.                section .data align=16
  2286.    switches to the section `.data' and also specifies that it must be
  2287. aligned on a 16-byte boundary.
  2288.    The parameter to `ALIGN' specifies how many low bits of the section
  2289. start address must be forced to zero. The alignment value given may be
  2290. any power of two.
  2291. File: nasm.info,  Node: Section 6.2,  Next: Section 6.2.1,  Prev: Section 6.1.2,  Up: Chapter 6
  2292. 6.2. `obj': Microsoft OMF Object Files
  2293. **************************************
  2294.    The `obj' file format (NASM calls it `obj' rather than `omf' for
  2295. historical reasons) is the one produced by MASM and TASM, which is
  2296. typically fed to 16-bit DOS linkers to produce `.EXE' files. It is also
  2297. the format used by OS/2.
  2298.    `obj' provides a default output file-name extension of `.obj'.
  2299.    `obj' is not exclusively a 16-bit format, though: NASM has full
  2300. support for the 32-bit extensions to the format. In particular, 32-bit
  2301. `obj' format files are used by Borland's Win32 compilers, instead of
  2302. using Microsoft's newer `win32' object file format.
  2303.    The `obj' format does not define any special segment names: you can
  2304. call your segments anything you like. Typical names for segments in
  2305. `obj' format files are `CODE', `DATA' and `BSS'.
  2306.    If your source file contains code before specifying an explicit
  2307. `SEGMENT' directive, then NASM will invent its own segment called
  2308. `__NASMDEFSEG' for you.
  2309.    When you define a segment in an `obj' file, NASM defines the segment
  2310. name as a symbol as well, so that you can access the segment address of
  2311. the segment. So, for example:
  2312.                segment data
  2313.      dvar:     dw 1234
  2314.                segment code
  2315.      function: mov ax,data            ; get segment address of data
  2316.                mov ds,ax              ; and move it into DS
  2317.                inc word [dvar]        ; now this reference will work
  2318.                ret
  2319.    The `obj' format also enables the use of the `SEG' and `WRT'
  2320. operators, so that you can write code which does things like
  2321.                extern foo
  2322.                mov ax,seg foo         ; get preferred segment of foo
  2323.                mov ds,ax
  2324.                mov ax,data            ; a different segment
  2325.                mov es,ax
  2326.                mov ax,[ds:foo]        ; this accesses `foo'
  2327.                mov [es:foo wrt data],bx  ; so does this
  2328. * Menu:
  2329. * Section 6.2.1:: `obj' Extensions to the `SEGMENT' Directive
  2330. * Section 6.2.2:: `GROUP': Defining Groups of Segments
  2331. * Section 6.2.3:: `UPPERCASE': Disabling Case Sensitivity in Output
  2332. * Section 6.2.4:: `IMPORT': Importing DLL Symbols
  2333. * Section 6.2.5:: `EXPORT': Exporting DLL Symbols
  2334. * Section 6.2.6:: `..start': Defining the Program Entry Point
  2335. * Section 6.2.7:: `obj' Extensions to the `EXTERN' Directive
  2336. * Section 6.2.8:: `obj' Extensions to the `COMMON' Directive
  2337. File: nasm.info,  Node: Section 6.2.1,  Next: Section 6.2.2,  Prev: Section 6.2,  Up: Section 6.2
  2338. 6.2.1. `obj' Extensions to the `SEGMENT' Directive
  2339. **************************************************
  2340.    The `obj' output format extends the `SEGMENT' (or `SECTION')
  2341. directive to allow you to specify various properties of the segment you
  2342. are defining. This is done by appending extra qualifiers to the end of
  2343. the segment-definition line. For example,
  2344.                segment code private align=16
  2345.    defines the segment `code', but also declares it to be a private
  2346. segment, and requires that the portion of it described in this code
  2347. module must be aligned on a 16-byte boundary.
  2348.    The available qualifiers are:
  2349.    * `PRIVATE', `PUBLIC', `COMMON' and `STACK' specify the combination
  2350.      characteristics of the segment. `PRIVATE' segments do not get
  2351.      combined with any others by the linker; `PUBLIC' and `STACK'
  2352.      segments get concatenated together at link time; and `COMMON'
  2353.      segments all get overlaid on top of each other rather than stuck
  2354.      end-to-end.
  2355.    * `ALIGN' is used, as shown above, to specify how many low bits of
  2356.      the segment start address must be forced to zero. The alignment
  2357.      value given may be any power of two from 1 to 4096; in reality,
  2358.      the only values supported are 1, 2, 4, 16, 256 and 4096, so if 8
  2359.      is specified it will be rounded up to 16, and 32, 64 and 128 will
  2360.      all be rounded up to 256, and so on. Note that alignment to
  2361.      4096-byte boundaries is a PharLap extension to the format and may
  2362.      not be supported by all linkers.
  2363.    * `CLASS' can be used to specify the segment class; this feature
  2364.      indicates to the linker that segments of the same class should be
  2365.      placed near each other in the output file. The class name can be
  2366.      any word, e.g.  `CLASS=CODE'.
  2367.    * `OVERLAY', like `CLASS', is specified with an arbitrary word as an
  2368.      argument, and provides overlay information to an overlay-capable
  2369.      linker.
  2370.    * Segments can be declared as `USE16' or `USE32', which has the
  2371.      effect of recording the choice in the object file and also
  2372.      ensuring that NASM's default assembly mode when assembling in that
  2373.      segment is 16-bit or 32-bit respectively.
  2374.    * When writing OS/2 object files, you should declare 32-bit segments
  2375.      as `FLAT', which causes the default segment base for anything in
  2376.      the segment to be the special group `FLAT', and also defines the
  2377.      group if it is not already defined.
  2378.    * The `obj' file format also allows segments to be declared as
  2379.      having a pre-defined absolute segment address, although no linkers
  2380.      are currently known to make sensible use of this feature;
  2381.      nevertheless, NASM allows you to declare a segment such as
  2382.      `SEGMENT SCREEN ABSOLUTE=0xB800' if you need to. The `ABSOLUTE'
  2383.      and `ALIGN' keywords are mutually exclusive.
  2384.    NASM's default segment attributes are `PUBLIC', `ALIGN=1', no class,
  2385. no overlay, and `USE16'.
  2386. File: nasm.info,  Node: Section 6.2.2,  Next: Section 6.2.3,  Prev: Section 6.2.1,  Up: Section 6.2
  2387. 6.2.2. `GROUP': Defining Groups of Segments
  2388. *******************************************
  2389.    The `obj' format also allows segments to be grouped, so that a single
  2390. segment register can be used to refer to all the segments in a group.
  2391. NASM therefore supplies the `GROUP' directive, whereby you can code
  2392.                segment data
  2393.                ; some data
  2394.                segment bss
  2395.                ; some uninitialised data
  2396.                group dgroup data bss
  2397.    which will define a group called `dgroup' to contain the segments
  2398. `data' and `bss'. Like `SEGMENT', `GROUP' causes the group name to be
  2399. defined as a symbol, so that you can refer to a variable `var' in the
  2400. `data' segment as `var wrt data' or as `var wrt dgroup', depending on
  2401. which segment value is currently in your segment register.
  2402.    If you just refer to `var', however, and `var' is declared in a
  2403. segment which is part of a group, then NASM will default to giving you
  2404. the offset of `var' from the beginning of the *group*, not the
  2405. *segment*. Therefore `SEG var', also, will return the group base rather
  2406. than the segment base.
  2407.    NASM will allow a segment to be part of more than one group, but will
  2408. generate a warning if you do this. Variables declared in a segment
  2409. which is part of more than one group will default to being relative to
  2410. the first group that was defined to contain the segment.
  2411.    A group does not have to contain any segments; you can still make
  2412. `WRT' references to a group which does not contain the variable you are
  2413. referring to. OS/2, for example, defines the special group `FLAT' with
  2414. no segments in it.
  2415. File: nasm.info,  Node: Section 6.2.3,  Next: Section 6.2.4,  Prev: Section 6.2.2,  Up: Section 6.2
  2416. 6.2.3. `UPPERCASE': Disabling Case Sensitivity in Output
  2417. ********************************************************
  2418.    Although NASM itself is case sensitive, some OMF linkers are not;
  2419. therefore it can be useful for NASM to output single-case object files.
  2420. The `UPPERCASE' format-specific directive causes all segment, group and
  2421. symbol names that are written to the object file to be forced to upper
  2422. case just before being written. Within a source file, NASM is still
  2423. case- sensitive; but the object file can be written entirely in upper
  2424. case if desired.
  2425.    `UPPERCASE' is used alone on a line; it requires no parameters.
  2426. File: nasm.info,  Node: Section 6.2.4,  Next: Section 6.2.5,  Prev: Section 6.2.3,  Up: Section 6.2
  2427. 6.2.4. `IMPORT': Importing DLL Symbols
  2428. **************************************
  2429.    The `IMPORT' format-specific directive defines a symbol to be
  2430. imported from a DLL, for use if you are writing a DLL's import library
  2431. in NASM. You still need to declare the symbol as `EXTERN' as well as
  2432. using the `IMPORT' directive.
  2433.    The `IMPORT' directive takes two required parameters, separated by
  2434. white space, which are (respectively) the name of the symbol you wish to
  2435. import and the name of the library you wish to import it from. For
  2436. example:
  2437.                import WSAStartup wsock32.dll
  2438.    A third optional parameter gives the name by which the symbol is
  2439. known in the library you are importing it from, in case this is not the
  2440. same as the name you wish the symbol to be known by to your code once
  2441. you have imported it. For example:
  2442.                import asyncsel wsock32.dll WSAAsyncSelect
  2443. File: nasm.info,  Node: Section 6.2.5,  Next: Section 6.2.6,  Prev: Section 6.2.4,  Up: Section 6.2
  2444. 6.2.5. `EXPORT': Exporting DLL Symbols
  2445. **************************************
  2446.    The `EXPORT' format-specific directive defines a global symbol to be
  2447. exported as a DLL symbol, for use if you are writing a DLL in NASM. You
  2448. still need to declare the symbol as `GLOBAL' as well as using the
  2449. `EXPORT' directive.
  2450.    `EXPORT' takes one required parameter, which is the name of the
  2451. symbol you wish to export, as it was defined in your source file. An
  2452. optional second parameter (separated by white space from the first)
  2453. gives the *external* name of the symbol: the name by which you wish the
  2454. symbol to be known to programs using the DLL. If this name is the same
  2455. as the internal name, you may leave the second parameter off.
  2456.    Further parameters can be given to define attributes of the exported
  2457. symbol. These parameters, like the second, are separated by white
  2458. space. If further parameters are given, the external name must also be
  2459. specified, even if it is the same as the internal name. The available
  2460. attributes are:
  2461.    * `resident' indicates that the exported name is to be kept resident
  2462.      by the system loader. This is an optimisation for frequently used
  2463.      symbols imported by name.
  2464.    * `nodata' indicates that the exported symbol is a function which
  2465.      does not make use of any initialised data.
  2466.    * `parm=NNN', where `NNN' is an integer, sets the number of
  2467.      parameter words for the case in which the symbol is a call gate
  2468.      between 32- bit and 16-bit segments.
  2469.    * An attribute which is just a number indicates that the symbol
  2470.      should be exported with an identifying number (ordinal), and gives
  2471.      the desired number.
  2472.    For example:
  2473.                export myfunc
  2474.                export myfunc TheRealMoreFormalLookingFunctionName
  2475.                export myfunc myfunc 1234  ; export by ordinal
  2476.                export myfunc myfunc resident parm=23 nodata
  2477. File: nasm.info,  Node: Section 6.2.6,  Next: Section 6.2.7,  Prev: Section 6.2.5,  Up: Section 6.2
  2478. 6.2.6. `..start': Defining the Program Entry Point
  2479. **************************************************
  2480.    OMF linkers require exactly one of the object files being linked to
  2481. define the program entry point, where execution will begin when the
  2482. program is run. If the object file that defines the entry point is
  2483. assembled using NASM, you specify the entry point by declaring the
  2484. special symbol `..start' at the point where you wish execution to begin.
  2485. File: nasm.info,  Node: Section 6.2.7,  Next: Section 6.2.8,  Prev: Section 6.2.6,  Up: Section 6.2
  2486. 6.2.7. `obj' Extensions to the `EXTERN' Directive
  2487. *************************************************
  2488.    If you declare an external symbol with the directive
  2489.                extern foo
  2490.    then references such as `mov ax,foo' will give you the offset of
  2491. `foo' from its preferred segment base (as specified in whichever module
  2492. `foo' is actually defined in). So to access the contents of `foo' you
  2493. will usually need to do something like
  2494.                mov ax,seg foo         ; get preferred segment base
  2495.                mov es,ax              ; move it into ES
  2496.                mov ax,[es:foo]        ; and use offset `foo' from it
  2497.    This is a little unwieldy, particularly if you know that an external
  2498. is going to be accessible from a given segment or group, say `dgroup'.
  2499. So if `DS' already contained `dgroup', you could simply code
  2500.                mov ax,[foo wrt dgroup]
  2501.    However, having to type this every time you want to access `foo' can
  2502. be a pain; so NASM allows you to declare `foo' in the alternative form
  2503.                extern foo:wrt dgroup
  2504.    This form causes NASM to pretend that the preferred segment base of
  2505. `foo' is in fact `dgroup'; so the expression `seg foo' will now return
  2506. `dgroup', and the expression `foo' is equivalent to `foo wrt dgroup'.
  2507.    This default-`WRT' mechanism can be used to make externals appear to
  2508. be relative to any group or segment in your program. It can also be
  2509. applied to common variables: see *Note Section 6.2.8::.
  2510. File: nasm.info,  Node: Section 6.2.8,  Next: Section 6.3,  Prev: Section 6.2.7,  Up: Section 6.2
  2511. 6.2.8. `obj' Extensions to the `COMMON' Directive
  2512. *************************************************
  2513.    The `obj' format allows common variables to be either near or far;
  2514. NASM allows you to specify which your variables should be by the use of
  2515. the syntax
  2516.                common nearvar 2:near  ; `nearvar' is a near common
  2517.                common farvar 10:far   ; and `farvar' is far
  2518.    Far common variables may be greater in size than 64Kb, and so the OMF
  2519. specification says that they are declared as a number of *elements* of
  2520. a given size. So a 10-byte far common variable could be declared as ten
  2521. one-byte elements, five two-byte elements, two five-byte elements or one
  2522. ten-byte element.
  2523.    Some OMF linkers require the element size, as well as the variable
  2524. size, to match when resolving common variables declared in more than
  2525. one module.  Therefore NASM must allow you to specify the element size
  2526. on your far common variables. This is done by the following syntax:
  2527.                common c_5by2 10:far 5 ; two five-byte elements
  2528.                common c_2by5 10:far 2 ; five two-byte elements
  2529.    If no element size is specified, the default is 1. Also, the `FAR'
  2530. keyword is not required when an element size is specified, since only
  2531. far commons may have element sizes at all. So the above declarations
  2532. could equivalently be
  2533.                common c_5by2 10:5     ; two five-byte elements
  2534.                common c_2by5 10:2     ; five two-byte elements
  2535.    In addition to these extensions, the `COMMON' directive in `obj'
  2536. also supports default-`WRT' specification like `EXTERN' does (explained
  2537. in *Note Section 6.2.7::). So you can also declare things like
  2538.                common foo 10:wrt dgroup
  2539.                common bar 16:far 2:wrt data
  2540.                common baz 24:wrt data:6
  2541. File: nasm.info,  Node: Section 6.3,  Next: Section 6.3.1,  Prev: Section 6.2.8,  Up: Chapter 6
  2542. 6.3. `win32': Microsoft Win32 Object Files
  2543. ******************************************
  2544.    The `win32' output format generates Microsoft Win32 object files,
  2545. suitable for passing to Microsoft linkers such as Visual C++. Note that
  2546. Borland Win32 compilers do not use this format, but use `obj' instead
  2547. (see *Note Section 6.2::).
  2548.    `win32' provides a default output file-name extension of `.obj'.
  2549.    Note that although Microsoft say that Win32 object files follow the
  2550. COFF (Common Object File Format) standard, the object files produced by
  2551. Microsoft Win32 compilers are not compatible with COFF linkers such as
  2552. DJGPP's, and vice versa. This is due to a difference of opinion over the
  2553. precise semantics of PC-relative relocations. To produce COFF files
  2554. suitable for DJGPP, use NASM's `coff' output format; conversely, the
  2555. `coff' format does not produce object files that Win32 linkers can
  2556. generate correct output from.
  2557. * Menu:
  2558. * Section 6.3.1:: `win32' Extensions to the `SECTION' Directive
  2559. File: nasm.info,  Node: Section 6.3.1,  Next: Section 6.4,  Prev: Section 6.3,  Up: Section 6.3
  2560. 6.3.1. `win32' Extensions to the `SECTION' Directive
  2561. ****************************************************
  2562.    Like the `obj' format, `win32' allows you to specify additional
  2563. information on the `SECTION' directive line, to control the type and
  2564. properties of sections you declare. Section types and properties are
  2565. generated automatically by NASM for the standard section names `.text',
  2566. `.data' and `.bss', but may still be overridden by these qualifiers.
  2567.    The available qualifiers are:
  2568.    * `code', or equivalently `text', defines the section to be a code
  2569.      section. This marks the section as readable and executable, but not
  2570.      writable, and also indicates to the linker that the type of the
  2571.      section is code.
  2572.    * `data' and `bss' define the section to be a data section,
  2573.      analogously to `code'. Data sections are marked as readable and
  2574.      writable, but not executable. `data' declares an initialised data
  2575.      section, whereas `bss' declares an uninitialised data section.
  2576.    * `info' defines the section to be an informational section, which is
  2577.      not included in the executable file by the linker, but may (for
  2578.      example) pass information *to* the linker. For example, declaring
  2579.      an `info'-type section called `.drectve' causes the linker to
  2580.      interpret the contents of the section as command-line options.
  2581.    * `align=', used with a trailing number as in `obj', gives the
  2582.      alignment requirements of the section. The maximum you may specify
  2583.      is 64: the Win32 object file format contains no means to request a
  2584.      greater section alignment than this. If alignment is not
  2585.      explicitly specified, the defaults are 16-byte alignment for code
  2586.      sections, and 4-byte alignment for data (and BSS) sections.
  2587.      Informational sections get a default alignment of 1 byte (no
  2588.      alignment), though the value does not matter.
  2589.    The defaults assumed by NASM if you do not specify the above
  2590. qualifiers are:
  2591.                section .text code align=16
  2592.                section .data data align=4
  2593.                section .bss bss align=4
  2594.    Any other section name is treated by default like `.text'.
  2595. File: nasm.info,  Node: Section 6.4,  Next: Section 6.5,  Prev: Section 6.3.1,  Up: Chapter 6
  2596. 6.4. `coff': Common Object File Format
  2597. **************************************
  2598.    The `coff' output type produces COFF object files suitable for
  2599. linking with the DJGPP linker.
  2600.    `coff' provides a default output file-name extension of `.o'.
  2601.    The `coff' format supports the same extensions to the `SECTION'
  2602. directive as `win32' does, except that the `align' qualifier and the
  2603. `info' section type are not supported.
  2604. File: nasm.info,  Node: Section 6.5,  Next: Section 6.5.1,  Prev: Section 6.4,  Up: Chapter 6
  2605. 6.5. `elf': Linux ELFObject Files
  2606. *********************************
  2607.    The `elf' output format generates ELF32 (Executable and Linkable
  2608. Format) object files, as used by Linux. `elf' provides a default output
  2609. file-name extension of `.o'.
  2610. * Menu:
  2611. * Section 6.5.1:: `elf' Extensions to the `SECTION' Directive
  2612. * Section 6.5.2:: Position-Independent Code: `elf' Special Symbols and `WRT'
  2613. * Section 6.5.3:: `elf' Extensions to the `GLOBAL' Directive
  2614. * Section 6.5.4:: `elf' Extensions to the `COMMON' Directive
  2615. File: nasm.info,  Node: Section 6.5.1,  Next: Section 6.5.2,  Prev: Section 6.5,  Up: Section 6.5
  2616. 6.5.1. `elf' Extensions to the `SECTION' Directive
  2617. **************************************************
  2618.    Like the `obj' format, `elf' allows you to specify additional
  2619. information on the `SECTION' directive line, to control the type and
  2620. properties of sections you declare. Section types and properties are
  2621. generated automatically by NASM for the standard section names `.text',
  2622. `.data' and `.bss', but may still be overridden by these qualifiers.
  2623.    The available qualifiers are:
  2624.    * `alloc' defines the section to be one which is loaded into memory
  2625.      when the program is run. `noalloc' defines it to be one which is
  2626.      not, such as an informational or comment section.
  2627.    * `exec' defines the section to be one which should have execute
  2628.      permission when the program is run. `noexec' defines it as one
  2629.      which should not.
  2630.    * `write' defines the section to be one which should be writable when
  2631.      the program is run. `nowrite' defines it as one which should not.
  2632.    * `progbits' defines the section to be one with explicit contents
  2633.      stored in the object file: an ordinary code or data section, for
  2634.      example, `nobits' defines the section to be one with no explicit
  2635.      contents given, such as a BSS section.
  2636.    * `align=', used with a trailing number as in `obj', gives the
  2637.      alignment requirements of the section.
  2638.    The defaults assumed by NASM if you do not specify the above
  2639. qualifiers are:
  2640.                section .text progbits alloc   exec nowrite align=16
  2641.                section .data progbits alloc noexec   write align=4
  2642.                section .bss    nobits alloc noexec   write align=4
  2643.                section other progbits alloc noexec nowrite align=1
  2644.    (Any section name other than `.text', `.data' and `.bss' is treated
  2645. by default like `other' in the above code.)
  2646. File: nasm.info,  Node: Section 6.5.2,  Next: Section 6.5.3,  Prev: Section 6.5.1,  Up: Section 6.5
  2647. 6.5.2. Position-Independent Code: `elf' Special Symbols and `WRT'
  2648. *****************************************************************
  2649.    The ELF specification contains enough features to allow position-
  2650. independent code (PIC) to be written, which makes ELF shared libraries
  2651. very flexible. However, it also means NASM has to be able to generate a
  2652. variety of strange relocation types in ELF object files, if it is to be
  2653. an assembler which can write PIC.
  2654.    Since ELF does not support segment-base references, the `WRT'
  2655. operator is not used for its normal purpose; therefore NASM's `elf'
  2656. output format makes use of `WRT' for a different purpose, namely the
  2657. PIC- specific relocation types.
  2658.    `elf' defines five special symbols which you can use as the
  2659. right-hand side of the `WRT' operator to obtain PIC relocation types.
  2660. They are `..gotpc', `..gotoff', `..got', `..plt' and `..sym'. Their
  2661. functions are summarised here:
  2662.    * Referring to the symbol marking the global offset table base using
  2663.      `wrt ..gotpc' will end up giving the distance from the beginning of
  2664.      the current section to the global offset table.
  2665.      (`_GLOBAL_OFFSET_TABLE_' is the standard symbol name used to refer
  2666.      to the GOT.) So you would then need to add `$$' to the result to
  2667.      get the real address of the GOT.
  2668.    * Referring to a location in one of your own sections using `wrt
  2669.      ..gotoff' will give the distance from the beginning of the GOT to
  2670.      the specified location, so that adding on the address of the GOT
  2671.      would give the real address of the location you wanted.
  2672.    * Referring to an external or global symbol using `wrt ..got' causes
  2673.      the linker to build an entry *in* the GOT containing the address
  2674.      of the symbol, and the reference gives the distance from the
  2675.      beginning of the GOT to the entry; so you can add on the address
  2676.      of the GOT, load from the resulting address, and end up with the
  2677.      address of the symbol.
  2678.    * Referring to a procedure name using `wrt ..plt' causes the linker
  2679.      to build a procedure linkage table entry for the symbol, and the
  2680.      reference gives the address of the PLT entry. You can only use
  2681.      this in contexts which would generate a PC-relative relocation
  2682.      normally (i.e. as the destination for `CALL' or `JMP'), since ELF
  2683.      contains no relocation type to refer to PLT entries absolutely.
  2684.    * Referring to a symbol name using `wrt ..sym' causes NASM to write
  2685.      an ordinary relocation, but instead of making the relocation
  2686.      relative to the start of the section and then adding on the offset
  2687.      to the symbol, it will write a relocation record aimed directly at
  2688.      the symbol in question. The distinction is a necessary one due to
  2689.      a peculiarity of the dynamic linker.
  2690.    A fuller explanation of how to use these relocation types to write
  2691. shared libraries entirely in NASM is given in *Note Section 8.2::.
  2692. File: nasm.info,  Node: Section 6.5.3,  Next: Section 6.5.4,  Prev: Section 6.5.2,  Up: Section 6.5
  2693. 6.5.3. `elf' Extensions to the `GLOBAL' Directive
  2694. *************************************************
  2695.    ELF object files can contain more information about a global symbol
  2696. than just its address: they can contain the size of the symbol and its
  2697. type as well. These are not merely debugger conveniences, but are
  2698. actually necessary when the program being written is a shared library.
  2699. NASM therefore supports some extensions to the `GLOBAL' directive,
  2700. allowing you to specify these features.
  2701.    You can specify whether a global variable is a function or a data
  2702. object by suffixing the name with a colon and the word `function' or
  2703. `data'. (`object' is a synonym for `data'.) For example:
  2704.                global hashlookup:function, hashtable:data
  2705.    exports the global symbol `hashlookup' as a function and `hashtable'
  2706. as a data object.
  2707.    You can also specify the size of the data associated with the
  2708. symbol, as a numeric expression (which may involve labels, and even
  2709. forward references) after the type specifier. Like this:
  2710.                global hashtable:data (hashtable.end - hashtable)
  2711.      hashtable:
  2712.                db this,that,theother  ; some data here
  2713.      .end:
  2714.    This makes NASM automatically calculate the length of the table and
  2715. place that information into the ELF symbol table.
  2716.    Declaring the type and size of global symbols is necessary when
  2717. writing shared library code. For more information, see *Note Section
  2718. 8.2.4::.
  2719. File: nasm.info,  Node: Section 6.5.4,  Next: Section 6.6,  Prev: Section 6.5.3,  Up: Section 6.5
  2720. 6.5.4. `elf' Extensions to the `COMMON' Directive
  2721. *************************************************
  2722.    ELF also allows you to specify alignment requirements on common
  2723. variables.  This is done by putting a number (which must be a power of
  2724. two) after the name and size of the common variable, separated (as
  2725. usual) by a colon. For example, an array of doublewords would benefit
  2726. from 4-byte alignment:
  2727.                common dwordarray 128:4
  2728.    This declares the total size of the array to be 128 bytes, and
  2729. requires that it be aligned on a 4-byte boundary.
  2730. File: nasm.info,  Node: Section 6.6,  Next: Section 6.7,  Prev: Section 6.5.4,  Up: Chapter 6
  2731. 6.6. `aout': Linux `a.out' Object Files
  2732. ***************************************
  2733.    The `aout' format generates `a.out' object files, in the form used
  2734. by early Linux systems. (These differ from other `a.out' object files
  2735. in that the magic number in the first four bytes of the file is
  2736. different. Also, some implementations of `a.out', for example NetBSD's,
  2737. support position-independent code, which Linux's implementation
  2738. doesn't.)
  2739.    `a.out' provides a default output file-name extension of `.o'.
  2740.    `a.out' is a very simple object format. It supports no special
  2741. directives, no special symbols, no use of `SEG' or `WRT', and no
  2742. extensions to any standard directives. It supports only the three
  2743. standard section names `.text', `.data' and `.bss'.
  2744. File: nasm.info,  Node: Section 6.7,  Next: Section 6.8,  Prev: Section 6.6,  Up: Chapter 6
  2745. 6.7. `aoutb': NetBSD/FreeBSD/OpenBSD `a.out' Object Files
  2746. *********************************************************
  2747.    The `aoutb' format generates `a.out' object files, in the form used
  2748. by the various free BSD Unix clones, NetBSD, FreeBSD and OpenBSD. For
  2749. simple object files, this object format is exactly the same as `aout'
  2750. except for the magic number in the first four bytes of the file.
  2751. However, the `aoutb' format supports position-independent code in the
  2752. same way as the `elf' format, so you can use it to write BSD shared
  2753. libraries.
  2754.    `aoutb' provides a default output file-name extension of `.o'.
  2755.    `aoutb' supports no special directives, no special symbols, and only
  2756. the three standard section names `.text', `.data' and `.bss'. However,
  2757. it also supports the same use of `WRT' as `elf' does, to provide
  2758. position-independent code relocation types. See *Note Section 6.5.2::
  2759. for full documentation of this feature.
  2760.    `aoutb' also supports the same extensions to the `GLOBAL' directive
  2761. as `elf' does: see *Note Section 6.5.3:: for documentation of this.
  2762. File: nasm.info,  Node: Section 6.8,  Next: Section 6.9,  Prev: Section 6.7,  Up: Chapter 6
  2763. 6.8. `as86': Linux `as86' Object Files
  2764. **************************************
  2765.    The Linux 16-bit assembler `as86' has its own non-standard object
  2766. file format. Although its companion linker `ld86' produces something
  2767. close to ordinary `a.out' binaries as output, the object file format
  2768. used to communicate between `as86' and `ld86' is not itself `a.out'.
  2769.    NASM supports this format, just in case it is useful, as `as86'.
  2770. `as86' provides a default output file-name extension of `.o'.
  2771.    `as86' is a very simple object format (from the NASM user's point of
  2772. view). It supports no special directives, no special symbols, no use of
  2773. `SEG' or `WRT', and no extensions to any standard directives. It
  2774. supports only the three standard section names `.text', `.data' and
  2775. `.bss'.
  2776. File: nasm.info,  Node: Section 6.9,  Next: Section 6.9.1,  Prev: Section 6.8,  Up: Chapter 6
  2777. 6.9. `rdf': Relocatable Dynamic Object File Format
  2778. **************************************************
  2779.    The `rdf' output format produces RDOFF object files. RDOFF
  2780. (Relocatable Dynamic Object File Format) is a home-grown object-file
  2781. format, designed alongside NASM itself and reflecting in its file format
  2782. the internal structure of the assembler.
  2783.    RDOFF is not used by any well-known operating systems. Those writing
  2784. their own systems, however, may well wish to use RDOFF as their object
  2785. format, on the grounds that it is designed primarily for simplicity and
  2786. contains very little file-header bureaucracy.
  2787.    The Unix NASM archive, and the DOS archive which includes sources,
  2788. both contain an `rdoff' subdirectory holding a set of RDOFF utilities:
  2789. an RDF linker, an RDF static-library manager, an RDF file dump utility,
  2790. and a program which will load and execute an RDF executable under Linux.
  2791.    `rdf' supports only the standard section names `.text', `.data' and
  2792. `.bss'.
  2793. * Menu:
  2794. * Section 6.9.1:: Requiring a Library: The `LIBRARY' Directive
  2795. File: nasm.info,  Node: Section 6.9.1,  Next: Section 6.10,  Prev: Section 6.9,  Up: Section 6.9
  2796. 6.9.1. Requiring a Library: The `LIBRARY' Directive
  2797. ***************************************************
  2798.    RDOFF contains a mechanism for an object file to demand a given
  2799. library to be linked to the module, either at load time or run time.
  2800. This is done by the `LIBRARY' directive, which takes one argument which
  2801. is the name of the module:
  2802.                library mylib.rdl
  2803. File: nasm.info,  Node: Section 6.10,  Next: Chapter 7,  Prev: Section 6.9.1,  Up: Chapter 6
  2804. 6.10. `dbg': Debugging Format
  2805. *****************************
  2806.    The `dbg' output format is not built into NASM in the default
  2807. configuration. If you are building your own NASM executable from the
  2808. sources, you can define `OF_DBG' in `outform.h' or on the compiler
  2809. command line, and obtain the `dbg' output format.
  2810.    The `dbg' format does not output an object file as such; instead, it
  2811. outputs a text file which contains a complete list of all the
  2812. transactions between the main body of NASM and the output-format back
  2813. end module. It is primarily intended to aid people who want to write
  2814. their own output drivers, so that they can get a clearer idea of the
  2815. various requests the main program makes of the output driver, and in
  2816. what order they happen.
  2817.    For simple files, one can easily use the `dbg' format like this:
  2818.      nasm -f dbg filename.asm
  2819.    which will generate a diagnostic file called `filename.dbg'. However,
  2820. this will not work well on files which were designed for a different
  2821. object format, because each object format defines its own macros
  2822. (usually user- level forms of directives), and those macros will not be
  2823. defined in the `dbg' format. Therefore it can be useful to run NASM
  2824. twice, in order to do the preprocessing with the native object format
  2825. selected:
  2826.      nasm -e -f rdf -o rdfprog.i rdfprog.asm
  2827.      nasm -a -f dbg rdfprog.i
  2828.    This preprocesses `rdfprog.asm' into `rdfprog.i', keeping the `rdf'
  2829. object format selected in order to make sure RDF special directives are
  2830. converted into primitive form correctly. Then the preprocessed source
  2831. is fed through the `dbg' format to generate the final diagnostic output.
  2832.    This workaround will still typically not work for programs intended
  2833. for `obj' format, because the `obj' `SEGMENT' and `GROUP' directives
  2834. have side effects of defining the segment and group names as symbols;
  2835. `dbg' will not do this, so the program will not assemble. You will have
  2836. to work around that by defining the symbols yourself (using `EXTERN',
  2837. for example) if you really need to get a `dbg' trace of an
  2838. `obj'-specific source file.
  2839.    `dbg' accepts any section name and any directives at all, and logs
  2840. them all to its output file.
  2841. File: nasm.info,  Node: Chapter 7,  Next: Section 7.1,  Prev: Section 6.10,  Up: Top
  2842. Chapter 7: Writing 16-bit Code (DOS, Windows 3/3.1)
  2843. ***************************************************
  2844.    This chapter attempts to cover some of the common issues encountered
  2845. when writing 16-bit code to run under MS-DOS or Windows 3.x. It covers
  2846. how to link programs to produce `.EXE' or `.COM' files, how to write
  2847. `.SYS' device drivers, and how to interface assembly language code with
  2848. 16-bit C compilers and with Borland Pascal.
  2849. * Menu:
  2850. * Section 7.1:: Producing `.EXE' Files
  2851. * Section 7.2:: Producing `.COM' Files
  2852. * Section 7.3:: Producing `.SYS' Files
  2853. * Section 7.4:: Interfacing to 16-bit C Programs
  2854. * Section 7.5:: Interfacing to Borland Pascal Programs
  2855. File: nasm.info,  Node: Section 7.1,  Next: Section 7.1.1,  Prev: Chapter 7,  Up: Chapter 7
  2856. 7.1. Producing `.EXE' Files
  2857. ***************************
  2858.    Any large program written under DOS needs to be built as a `.EXE'
  2859. file: only `.EXE' files have the necessary internal structure required
  2860. to span more than one 64K segment. Windows programs, also, have to be
  2861. built as `.EXE' files, since Windows does not support the `.COM' format.
  2862.    In general, you generate `.EXE' files by using the `obj' output
  2863. format to produce one or more `.OBJ' files, and then linking them
  2864. together using a linker. However, NASM also supports the direct
  2865. generation of simple DOS `.EXE' files using the `bin' output format (by
  2866. using `DB' and `DW' to construct the `.EXE' file header), and a macro
  2867. package is supplied to do this. Thanks to Yann Guidon for contributing
  2868. the code for this.
  2869.    NASM may also support `.EXE' natively as another output format in
  2870. future releases.
  2871. * Menu:
  2872. * Section 7.1.1:: Using the `obj' Format To Generate `.EXE' Files
  2873. * Section 7.1.2:: Using the `bin' Format To Generate `.EXE' Files
  2874. File: nasm.info,  Node: Section 7.1.1,  Next: Section 7.1.2,  Prev: Section 7.1,  Up: Section 7.1
  2875. 7.1.1. Using the `obj' Format To Generate `.EXE' Files
  2876. ******************************************************
  2877.    This section describes the usual method of generating `.EXE' files by
  2878. linking `.OBJ' files together.
  2879.    Most 16-bit programming language packages come with a suitable
  2880. linker; if you have none of these, there is a free linker called VAL,
  2881. available in `LZH' archive format from `x2ftp.oulu.fi'. An LZH archiver
  2882. can be found at `ftp.simtel.net'. There is another `free' linker
  2883. (though this one doesn't come with sources) called FREELINK, available
  2884. from `www.pcorner.com'. A third, `djlink', written by DJ Delorie, is
  2885. available at `www.delorie.com'.
  2886.    When linking several `.OBJ' files into a `.EXE' file, you should
  2887. ensure that exactly one of them has a start point defined (using the
  2888. `..start' special symbol defined by the `obj' format: see *Note Section
  2889. 6.2.6::). If no module defines a start point, the linker will not know
  2890. what value to give the entry-point field in the output file header; if
  2891. more than one defines a start point, the linker will not know *which*
  2892. value to use.
  2893.    An example of a NASM source file which can be assembled to a `.OBJ'
  2894. file and linked on its own to a `.EXE' is given here. It demonstrates
  2895. the basic principles of defining a stack, initialising the segment
  2896. registers, and declaring a start point. This file is also provided in
  2897. the `test' subdirectory of the NASM archives, under the name
  2898. `objexe.asm'.
  2899.                segment code
  2900.      
  2901.      ..start:  mov ax,data
  2902.                mov ds,ax
  2903.                mov ax,stack
  2904.                mov ss,ax
  2905.                mov sp,stacktop
  2906.    This initial piece of code sets up `DS' to point to the data segment,
  2907. and initialises `SS' and `SP' to point to the top of the provided
  2908. stack. Notice that interrupts are implicitly disabled for one
  2909. instruction after a move into `SS', precisely for this situation, so
  2910. that there's no chance of an interrupt occurring between the loads of
  2911. `SS' and `SP' and not having a stack to execute on.
  2912.    Note also that the special symbol `..start' is defined at the
  2913. beginning of this code, which means that will be the entry point into
  2914. the resulting executable file.
  2915.                mov dx,hello
  2916.                mov ah,9
  2917.                int 0x21
  2918.    The above is the main program: load `DS:DX' with a pointer to the
  2919. greeting message (`hello' is implicitly relative to the segment `data',
  2920. which was loaded into `DS' in the setup code, so the full pointer is
  2921. valid), and call the DOS print-string function.
  2922.                mov ax,0x4c00
  2923.                int 0x21
  2924.    This terminates the program using another DOS system call.
  2925.                segment data
  2926.      hello:    db 'hello, world', 13, 10, '$'
  2927.    The data segment contains the string we want to display.
  2928.                segment stack stack
  2929.                resb 64
  2930.      stacktop:
  2931.    The above code declares a stack segment containing 64 bytes of
  2932. uninitialised stack space, and points `stacktop' at the top of it. The
  2933. directive `segment stack stack' defines a segment *called* `stack', and
  2934. also of *type* `STACK'. The latter is not necessary to the correct
  2935. running of the program, but linkers are likely to issue warnings or
  2936. errors if your program has no segment of type `STACK'.
  2937.    The above file, when assembled into a `.OBJ' file, will link on its
  2938. own to a valid `.EXE' file, which when run will print `hello, world'
  2939. and then exit.
  2940. File: nasm.info,  Node: Section 7.1.2,  Next: Section 7.2,  Prev: Section 7.1.1,  Up: Section 7.1
  2941. 7.1.2. Using the `bin' Format To Generate `.EXE' Files
  2942. ******************************************************
  2943.    The `.EXE' file format is simple enough that it's possible to build a
  2944. `.EXE' file by writing a pure-binary program and sticking a 32-byte
  2945. header on the front. This header is simple enough that it can be
  2946. generated using `DB' and `DW' commands by NASM itself, so that you can
  2947. use the `bin' output format to directly generate `.EXE' files.
  2948.    Included in the NASM archives, in the `misc' subdirectory, is a file
  2949. `exebin.mac' of macros. It defines three macros: `EXE_begin',
  2950. `EXE_stack' and `EXE_end'.
  2951.    To produce a `.EXE' file using this method, you should start by using
  2952. `%include' to load the `exebin.mac' macro package into your source
  2953. file. You should then issue the `EXE_begin' macro call (which takes no
  2954. arguments) to generate the file header data. Then write code as normal
  2955. for the `bin' format - you can use all three standard sections `.text',
  2956. `.data' and `.bss'. At the end of the file you should call the
  2957. `EXE_end' macro (again, no arguments), which defines some symbols to
  2958. mark section sizes, and these symbols are referred to in the header
  2959. code generated by `EXE_begin'.
  2960.    In this model, the code you end up writing starts at `0x100', just
  2961. like a `.COM' file - in fact, if you strip off the 32-byte header from
  2962. the resulting `.EXE' file, you will have a valid `.COM' program. All
  2963. the segment bases are the same, so you are limited to a 64K program,
  2964. again just like a `.COM' file. Note that an `ORG' directive is issued
  2965. by the `EXE_begin' macro, so you should not explicitly issue one of
  2966. your own.
  2967.    You can't directly refer to your segment base value, unfortunately,
  2968. since this would require a relocation in the header, and things would
  2969. get a lot more complicated. So you should get your segment base by
  2970. copying it out of `CS' instead.
  2971.    On entry to your `.EXE' file, `SS:SP' are already set up to point to
  2972. the top of a 2Kb stack. You can adjust the default stack size of 2Kb by
  2973. calling the `EXE_stack' macro. For example, to change the stack size of
  2974. your program to 64 bytes, you would call `EXE_stack 64'.
  2975.    A sample program which generates a `.EXE' file in this way is given
  2976. in the `test' subdirectory of the NASM archive, as `binexe.asm'.
  2977. File: nasm.info,  Node: Section 7.2,  Next: Section 7.2.1,  Prev: Section 7.1.2,  Up: Chapter 7
  2978. 7.2. Producing `.COM' Files
  2979. ***************************
  2980.    While large DOS programs must be written as `.EXE' files, small ones
  2981. are often better written as `.COM' files. `.COM' files are pure binary,
  2982. and therefore most easily produced using the `bin' output format.
  2983. * Menu:
  2984. * Section 7.2.1:: Using the `bin' Format To Generate `.COM' Files
  2985. * Section 7.2.2:: Using the `obj' Format To Generate `.COM' Files
  2986. File: nasm.info,  Node: Section 7.2.1,  Next: Section 7.2.2,  Prev: Section 7.2,  Up: Section 7.2
  2987. 7.2.1. Using the `bin' Format To Generate `.COM' Files
  2988. ******************************************************
  2989.    `.COM' files expect to be loaded at offset `100h' into their segment
  2990. (though the segment may change). Execution then begins at `100h', i.e.
  2991. right at the start of the program. So to write a `.COM' program, you
  2992. would create a source file looking like
  2993.                org 100h
  2994.                section .text
  2995.      start:    ; put your code here
  2996.                section .data
  2997.                ; put data items here
  2998.                section .bss
  2999.                ; put uninitialised data here
  3000.    The `bin' format puts the `.text' section first in the file, so you
  3001. can declare data or BSS items before beginning to write code if you
  3002. want to and the code will still end up at the front of the file where it
  3003. belongs.
  3004.    The BSS (uninitialised data) section does not take up space in the
  3005. `.COM' file itself: instead, addresses of BSS items are resolved to
  3006. point at space beyond the end of the file, on the grounds that this
  3007. will be free memory when the program is run. Therefore you should not
  3008. rely on your BSS being initialised to all zeros when you run.
  3009.    To assemble the above program, you should use a command line like
  3010.      nasm myprog.asm -fbin -o myprog.com
  3011.    The `bin' format would produce a file called `myprog' if no explicit
  3012. output file name were specified, so you have to override it and give
  3013. the desired file name.
  3014. File: nasm.info,  Node: Section 7.2.2,  Next: Section 7.3,  Prev: Section 7.2.1,  Up: Section 7.2
  3015. 7.2.2. Using the `obj' Format To Generate `.COM' Files
  3016. ******************************************************
  3017.    If you are writing a `.COM' program as more than one module, you may
  3018. wish to assemble several `.OBJ' files and link them together into a
  3019. `.COM' program. You can do this, provided you have a linker capable of
  3020. outputting `.COM' files directly (TLINK does this), or alternatively a
  3021. converter program such as `EXE2BIN' to transform the `.EXE' file output
  3022. from the linker into a `.COM' file.
  3023.    If you do this, you need to take care of several things:
  3024.    * The first object file containing code should start its code
  3025.      segment with a line like `RESB 100h'. This is to ensure that the
  3026.      code begins at offset `100h' relative to the beginning of the code
  3027.      segment, so that the linker or converter program does not have to
  3028.      adjust address references within the file when generating the
  3029.      `.COM' file. Other assemblers use an `ORG' directive for this
  3030.      purpose, but `ORG' in NASM is a format-specific directive to the
  3031.      `bin' output format, and does not mean the same thing as it does
  3032.      in MASM-compatible assemblers.
  3033.    * You don't need to define a stack segment.
  3034.    * All your segments should be in the same group, so that every time
  3035.      your code or data references a symbol offset, all offsets are
  3036.      relative to the same segment base. This is because, when a `.COM'
  3037.      file is loaded, all the segment registers contain the same value.
  3038. File: nasm.info,  Node: Section 7.3,  Next: Section 7.4,  Prev: Section 7.2.2,  Up: Chapter 7
  3039. 7.3. Producing `.SYS' Files
  3040. ***************************
  3041.    MS-DOS device drivers - `.SYS' files - are pure binary files,
  3042. similar to `.COM' files, except that they start at origin zero rather
  3043. than `100h'. Therefore, if you are writing a device driver using the
  3044. `bin' format, you do not need the `ORG' directive, since the default
  3045. origin for `bin' is zero. Similarly, if you are using `obj', you do not
  3046. need the `RESB 100h' at the start of your code segment.
  3047.    `.SYS' files start with a header structure, containing pointers to
  3048. the various routines inside the driver which do the work. This
  3049. structure should be defined at the start of the code segment, even
  3050. though it is not actually code.
  3051.    For more information on the format of `.SYS' files, and the data
  3052. which has to go in the header structure, a list of books is given in the
  3053. Frequently Asked Questions list for the newsgroup
  3054. `comp.os.msdos.programmer'.
  3055. File: nasm.info,  Node: Section 7.4,  Next: Section 7.4.1,  Prev: Section 7.3,  Up: Chapter 7
  3056. 7.4. Interfacing to 16-bit C Programs
  3057. *************************************
  3058.    This section covers the basics of writing assembly routines that
  3059. call, or are called from, C programs. To do this, you would typically
  3060. write an assembly module as a `.OBJ' file, and link it with your C
  3061. modules to produce a mixed-language program.
  3062. * Menu:
  3063. * Section 7.4.1:: External Symbol Names
  3064. * Section 7.4.2:: Memory Models
  3065. * Section 7.4.3:: Function Definitions and Function Calls
  3066. * Section 7.4.4:: Accessing Data Items
  3067. * Section 7.4.5:: `c16.mac': Helper Macros for the 16-bit C Interface
  3068. File: nasm.info,  Node: Section 7.4.1,  Next: Section 7.4.2,  Prev: Section 7.4,  Up: Section 7.4
  3069. 7.4.1. External Symbol Names
  3070. ****************************
  3071.    C compilers have the convention that the names of all global symbols
  3072. (functions or data) they define are formed by prefixing an underscore to
  3073. the name as it appears in the C program. So, for example, the function
  3074. a C programmer thinks of as `printf' appears to an assembly language
  3075. programmer as `_printf'. This means that in your assembly programs, you
  3076. can define symbols without a leading underscore, and not have to worry
  3077. about name clashes with C symbols.
  3078.    If you find the underscores inconvenient, you can define macros to
  3079. replace the `GLOBAL' and `EXTERN' directives as follows:
  3080.      %macro cglobal 1
  3081.                global _%1
  3082.      %define %1 _%1
  3083.      %endmacro
  3084.      %macro cextern 1
  3085.                extern _%1
  3086.      %define %1 _%1
  3087.      %endmacro
  3088.    (These forms of the macros only take one argument at a time; a `%rep'
  3089. construct could solve this.)
  3090.    If you then declare an external like this:
  3091.                cextern printf
  3092.    then the macro will expand it as
  3093.                extern _printf
  3094.      %define printf _printf
  3095.    Thereafter, you can reference `printf' as if it was a symbol, and the
  3096. preprocessor will put the leading underscore on where necessary.
  3097.    The `cglobal' macro works similarly. You must use `cglobal' before
  3098. defining the symbol in question, but you would have had to do that
  3099. anyway if you used `GLOBAL'.
  3100. File: nasm.info,  Node: Section 7.4.2,  Next: Section 7.4.3,  Prev: Section 7.4.1,  Up: Section 7.4
  3101. 7.4.2. Memory Models
  3102. ********************
  3103.    NASM contains no mechanism to support the various C memory models
  3104. directly; you have to keep track yourself of which one you are writing
  3105. for. This means you have to keep track of the following things:
  3106.    * In models using a single code segment (tiny, small and compact),
  3107.      functions are near. This means that function pointers, when stored
  3108.      in data segments or pushed on the stack as function arguments, are
  3109.      16 bits long and contain only an offset field (the `CS' register
  3110.      never changes its value, and always gives the segment part of the
  3111.      full function address), and that functions are called using
  3112.      ordinary near `CALL' instructions and return using `RETN' (which,
  3113.      in NASM, is synonymous with `RET' anyway). This means both that
  3114.      you should write your own routines to return with `RETN', and that
  3115.      you should call external C routines with near `CALL' instructions.
  3116.    * In models using more than one code segment (medium, large and
  3117.      huge), functions are far. This means that function pointers are 32
  3118.      bits long (consisting of a 16-bit offset followed by a 16-bit
  3119.      segment), and that functions are called using `CALL FAR' (or `CALL
  3120.      seg:offset') and return using `RETF'. Again, you should therefore
  3121.      write your own routines to return with `RETF' and use `CALL FAR'
  3122.      to call external routines.
  3123.    * In models using a single data segment (tiny, small and medium),
  3124.      data pointers are 16 bits long, containing only an offset field
  3125.      (the `DS' register doesn't change its value, and always gives the
  3126.      segment part of the full data item address).
  3127.    * In models using more than one data segment (compact, large and
  3128.      huge), data pointers are 32 bits long, consisting of a 16-bit
  3129.      offset followed by a 16- bit segment. You should still be careful
  3130.      not to modify `DS' in your routines without restoring it
  3131.      afterwards, but `ES' is free for you to use to access the contents
  3132.      of 32-bit data pointers you are passed.
  3133.    * The huge memory model allows single data items to exceed 64K in
  3134.      size. In all other memory models, you can access the whole of a
  3135.      data item just by doing arithmetic on the offset field of the
  3136.      pointer you are given, whether a segment field is present or not;
  3137.      in huge model, you have to be more careful of your pointer
  3138.      arithmetic.
  3139.    * In most memory models, there is a *default* data segment, whose
  3140.      segment address is kept in `DS' throughout the program. This data
  3141.      segment is typically the same segment as the stack, kept in `SS',
  3142.      so that functions' local variables (which are stored on the stack)
  3143.      and global data items can both be accessed easily without changing
  3144.      `DS'.  Particularly large data items are typically stored in other
  3145.      segments.  However, some memory models (though not the standard
  3146.      ones, usually) allow the assumption that `SS' and `DS' hold the
  3147.      same value to be removed. Be careful about functions' local
  3148.      variables in this latter case.
  3149.    In models with a single code segment, the segment is called `_TEXT',
  3150. so your code segment must also go by this name in order to be linked
  3151. into the same place as the main code segment. In models with a single
  3152. data segment, or with a default data segment, it is called `_DATA'.
  3153. File: nasm.info,  Node: Section 7.4.3,  Next: Section 7.4.4,  Prev: Section 7.4.2,  Up: Section 7.4
  3154. 7.4.3. Function Definitions and Function Calls
  3155. **********************************************
  3156.    The C calling convention in 16-bit programs is as follows. In the
  3157. following description, the words *caller* and *callee* are used to
  3158. denote the function doing the calling and the function which gets
  3159. called.
  3160.    * The caller pushes the function's parameters on the stack, one after
  3161.      another, in reverse order (right to left, so that the first
  3162.      argument specified to the function is pushed last).
  3163.    * The caller then executes a `CALL' instruction to pass control to
  3164.      the callee. This `CALL' is either near or far depending on the
  3165.      memory model.
  3166.    * The callee receives control, and typically (although this is not
  3167.      actually necessary, in functions which do not need to access their
  3168.      parameters) starts by saving the value of `SP' in `BP' so as to be
  3169.      able to use `BP' as a base pointer to find its parameters on the
  3170.      stack.  However, the caller was probably doing this too, so part
  3171.      of the calling convention states that `BP' must be preserved by
  3172.      any C function. Hence the callee, if it is going to set up `BP' as
  3173.      a *frame pointer*, must push the previous value first.
  3174.    * The callee may then access its parameters relative to `BP'. The
  3175.      word at `[BP]' holds the previous value of `BP' as it was pushed;
  3176.      the next word, at `[BP+2]', holds the offset part of the return
  3177.      address, pushed implicitly by `CALL'. In a small-model (near)
  3178.      function, the parameters start after that, at `[BP+4]'; in a
  3179.      large-model (far) function, the segment part of the return address
  3180.      lives at `[BP+4]', and the parameters begin at `[BP+6]'. The
  3181.      leftmost parameter of the function, since it was pushed last, is
  3182.      accessible at this offset from `BP'; the others follow, at
  3183.      successively greater offsets. Thus, in a function such as `printf'
  3184.      which takes a variable number of parameters, the pushing of the
  3185.      parameters in reverse order means that the function knows where to
  3186.      find its first parameter, which tells it the number and type of
  3187.      the remaining ones.
  3188.    * The callee may also wish to decrease `SP' further, so as to
  3189.      allocate space on the stack for local variables, which will then
  3190.      be accessible at negative offsets from `BP'.
  3191.    * The callee, if it wishes to return a value to the caller, should
  3192.      leave the value in `AL', `AX' or `DX:AX' depending on the size of
  3193.      the value. Floating-point results are sometimes (depending on the
  3194.      compiler) returned in `ST0'.
  3195.    * Once the callee has finished processing, it restores `SP' from
  3196.      `BP' if it had allocated local stack space, then pops the previous
  3197.      value of `BP', and returns via `RETN' or `RETF' depending on
  3198.      memory model.
  3199.    * When the caller regains control from the callee, the function
  3200.      parameters are still on the stack, so it typically adds an
  3201.      immediate constant to `SP' to remove them (instead of executing a
  3202.      number of slow `POP' instructions). Thus, if a function is
  3203.      accidentally called with the wrong number of parameters due to a
  3204.      prototype mismatch, the stack will still be returned to a sensible
  3205.      state since the caller, which *knows* how many parameters it
  3206.      pushed, does the removing.
  3207.    It is instructive to compare this calling convention with that for
  3208. Pascal programs (described in *Note Section 7.5.1::). Pascal has a
  3209. simpler convention, since no functions have variable numbers of
  3210. parameters.  Therefore the callee knows how many parameters it should
  3211. have been passed, and is able to deallocate them from the stack itself
  3212. by passing an immediate argument to the `RET' or `RETF' instruction, so
  3213. the caller does not have to do it. Also, the parameters are pushed in
  3214. left-to- right order, not right-to-left, which means that a compiler
  3215. can give better guarantees about sequence points without performance
  3216. suffering.
  3217.    Thus, you would define a function in C style in the following way.
  3218. The following example is for small model:
  3219.                global _myfunc
  3220.      _myfunc:  push bp
  3221.                mov bp,sp
  3222.                sub sp,0x40            ; 64 bytes of local stack space
  3223.                mov bx,[bp+4]          ; first parameter to function
  3224.                ; some more code
  3225.                mov sp,bp              ; undo "sub sp,0x40" above
  3226.                pop bp
  3227.                ret
  3228.    For a large-model function, you would replace `RET' by `RETF', and
  3229. look for the first parameter at `[BP+6]' instead of `[BP+4]'.  Of
  3230. course, if one of the parameters is a pointer, then the offsets of
  3231. *subsequent* parameters will change depending on the memory model as
  3232. well: far pointers take up four bytes on the stack when passed as a
  3233. parameter, whereas near pointers take up two.
  3234.    At the other end of the process, to call a C function from your
  3235. assembly code, you would do something like this:
  3236.                extern _printf
  3237.                ; and then, further down...
  3238.                push word [myint]      ; one of my integer variables
  3239.                push word mystring     ; pointer into my data segment
  3240.                call _printf
  3241.                add sp,byte 4          ; `byte' saves space
  3242.                ; then those data items...
  3243.                segment _DATA
  3244.      myint     dw 1234
  3245.      mystring  db 'This number -> %d <- should be 1234',10,0
  3246.    This piece of code is the small-model assembly equivalent of the C
  3247.          int myint = 1234;
  3248.          printf("This number -> %d <- should be 1234\n", myint);
  3249.    In large model, the function-call code might look more like this. In
  3250. this example, it is assumed that `DS' already holds the segment base of
  3251. the segment `_DATA'. If not, you would have to initialise it first.
  3252.                push word [myint]
  3253.                push word seg mystring ; Now push the segment, and...
  3254.                push word mystring     ; ... offset of "mystring"
  3255.                call far _printf
  3256.                add sp,byte 6
  3257.    The integer value still takes up one word on the stack, since large
  3258. model does not affect the size of the `int' data type. The first
  3259. argument (pushed last) to `printf', however, is a data pointer, and
  3260. therefore has to contain a segment and offset part. The segment should
  3261. be stored second in memory, and therefore must be pushed first. (Of
  3262. course, `PUSH DS' would have been a shorter instruction than `PUSH WORD
  3263. SEG mystring', if `DS' was set up as the above example assumed.) Then
  3264. the actual call becomes a far call, since functions expect far calls in
  3265. large model; and `SP' has to be increased by 6 rather than 4 afterwards
  3266. to make up for the extra word of parameters.
  3267. File: nasm.info,  Node: Section 7.4.4,  Next: Section 7.4.5,  Prev: Section 7.4.3,  Up: Section 7.4
  3268. 7.4.4. Accessing Data Items
  3269. ***************************
  3270.    To get at the contents of C variables, or to declare variables which
  3271. C can access, you need only declare the names as `GLOBAL' or `EXTERN'.
  3272. (Again, the names require leading underscores, as stated in *Note
  3273. Section 7.4.1::.) Thus, a C variable declared as `int i' can be
  3274. accessed from assembler as
  3275.                extern _i
  3276.                mov ax,[_i]
  3277.    And to declare your own integer variable which C programs can access
  3278. as `extern int j', you do this (making sure you are assembling in the
  3279. `_DATA' segment, if necessary):
  3280.                global _j
  3281.      _j        dw 0
  3282.    To access a C array, you need to know the size of the components of
  3283. the array. For example, `int' variables are two bytes long, so if a C
  3284. program declares an array as `int a[10]', you can access `a[3]' by
  3285. coding `mov ax,[_a+6]'. (The byte offset 6 is obtained by multiplying
  3286. the desired array index, 3, by the size of the array element, 2.) The
  3287. sizes of the C base types in 16-bit compilers are: 1 for `char', 2 for
  3288. `short' and `int', 4 for `long' and `float', and 8 for `double'.
  3289.    To access a C data structure, you need to know the offset from the
  3290. base of the structure to the field you are interested in. You can
  3291. either do this by converting the C structure definition into a NASM
  3292. structure definition (using `STRUC'), or by calculating the one offset
  3293. and using just that.
  3294.    To do either of these, you should read your C compiler's manual to
  3295. find out how it organises data structures. NASM gives no special
  3296. alignment to structure members in its own `STRUC' macro, so you have to
  3297. specify alignment yourself if the C compiler generates it. Typically,
  3298. you might find that a structure like
  3299.      struct {
  3300.          char c;
  3301.          int i;
  3302.      } foo;
  3303.    might be four bytes long rather than three, since the `int' field
  3304. would be aligned to a two-byte boundary. However, this sort of feature
  3305. tends to be a configurable option in the C compiler, either using
  3306. command- line options or `#pragma' lines, so you have to find out how
  3307. your own compiler does it.
  3308. File: nasm.info,  Node: Section 7.4.5,  Next: Section 7.5,  Prev: Section 7.4.4,  Up: Section 7.4
  3309. 7.4.5. `c16.mac': Helper Macros for the 16-bit C Interface
  3310. **********************************************************
  3311.    Included in the NASM archives, in the `misc' directory, is a file
  3312. `c16.mac' of macros. It defines three macros: `proc', `arg' and
  3313. `endproc'. These are intended to be used for C-style procedure
  3314. definitions, and they automate a lot of the work involved in keeping
  3315. track of the calling convention.
  3316.    An example of an assembly function using the macro set is given here:
  3317.                proc _nearproc
  3318.      %$i       arg
  3319.      %$j       arg
  3320.                mov ax,[bp + %$i]
  3321.                mov bx,[bp + %$j]
  3322.                add ax,[bx]
  3323.                endproc
  3324.    This defines `_nearproc' to be a procedure taking two arguments, the
  3325. first (`i') an integer and the second (`j') a pointer to an integer. It
  3326. returns `i + *j'.
  3327.    Note that the `arg' macro has an `EQU' as the first line of its
  3328. expansion, and since the label before the macro call gets prepended to
  3329. the first line of the expanded macro, the `EQU' works, defining `%$i'
  3330. to be an offset from `BP'. A context-local variable is used, local to
  3331. the context pushed by the `proc' macro and popped by the `endproc'
  3332. macro, so that the same argument name can be used in later procedures.
  3333. Of course, you don't *have* to do that.
  3334.    The macro set produces code for near functions (tiny, small and
  3335. compact- model code) by default. You can have it generate far functions
  3336. (medium, large and huge-model code) by means of coding `%define
  3337. FARCODE'. This changes the kind of return instruction generated by
  3338. `endproc', and also changes the starting point for the argument
  3339. offsets. The macro set contains no intrinsic dependency on whether data
  3340. pointers are far or not.
  3341.    `arg' can take an optional parameter, giving the size of the
  3342. argument.  If no size is given, 2 is assumed, since it is likely that
  3343. many function parameters will be of type `int'.
  3344.    The large-model equivalent of the above function would look like
  3345. this:
  3346.      %define FARCODE
  3347.                proc _farproc
  3348.      %$i       arg
  3349.      %$j       arg 4
  3350.                mov ax,[bp + %$i]
  3351.                mov bx,[bp + %$j]
  3352.                mov es,[bp + %$j + 2]
  3353.                add ax,[bx]
  3354.                endproc
  3355.    This makes use of the argument to the `arg' macro to define a
  3356. parameter of size 4, because `j' is now a far pointer. When we load
  3357. from `j', we must load a segment and an offset.
  3358. File: nasm.info,  Node: Section 7.5,  Next: Section 7.5.1,  Prev: Section 7.4.5,  Up: Chapter 7
  3359. 7.5. Interfacing to Borland Pascal Programs
  3360. *******************************************
  3361.    Interfacing to Borland Pascal programs is similar in concept to
  3362. interfacing to 16-bit C programs. The differences are:
  3363.    * The leading underscore required for interfacing to C programs is
  3364.      not required for Pascal.
  3365.    * The memory model is always large: functions are far, data pointers
  3366.      are far, and no data item can be more than 64K long. (Actually,
  3367.      some functions are near, but only those functions that are local
  3368.      to a Pascal unit and never called from outside it. All assembly
  3369.      functions that Pascal calls, and all Pascal functions that
  3370.      assembly routines are able to call, are far.) However, all static
  3371.      data declared in a Pascal program goes into the default data
  3372.      segment, which is the one whose segment address will be in `DS'
  3373.      when control is passed to your assembly code. The only things that
  3374.      do not live in the default data segment are local variables (they
  3375.      live in the stack segment) and dynamically allocated variables.
  3376.      All data *pointers*, however, are far.
  3377.    * The function calling convention is different - described below.
  3378.    * Some data types, such as strings, are stored differently.
  3379.    * There are restrictions on the segment names you are allowed to use
  3380.      - Borland Pascal will ignore code or data declared in a segment it
  3381.      doesn't like the name of. The restrictions are described below.
  3382. * Menu:
  3383. * Section 7.5.1:: The Pascal Calling Convention
  3384. * Section 7.5.2:: Borland Pascal Segment Name Restrictions
  3385. * Section 7.5.3:: Using `c16.mac' With Pascal Programs
  3386. File: nasm.info,  Node: Section 7.5.1,  Next: Section 7.5.2,  Prev: Section 7.5,  Up: Section 7.5
  3387. 7.5.1. The Pascal Calling Convention
  3388. ************************************
  3389.    The 16-bit Pascal calling convention is as follows. In the following
  3390. description, the words *caller* and *callee* are used to denote the
  3391. function doing the calling and the function which gets called.
  3392.    * The caller pushes the function's parameters on the stack, one after
  3393.      another, in normal order (left to right, so that the first argument
  3394.      specified to the function is pushed first).
  3395.    * The caller then executes a far `CALL' instruction to pass control
  3396.      to the callee.
  3397.    * The callee receives control, and typically (although this is not
  3398.      actually necessary, in functions which do not need to access their
  3399.      parameters) starts by saving the value of `SP' in `BP' so as to be
  3400.      able to use `BP' as a base pointer to find its parameters on the
  3401.      stack.  However, the caller was probably doing this too, so part
  3402.      of the calling convention states that `BP' must be preserved by
  3403.      any function. Hence the callee, if it is going to set up `BP' as a
  3404.      frame pointer, must push the previous value first.
  3405.    * The callee may then access its parameters relative to `BP'. The
  3406.      word at `[BP]' holds the previous value of `BP' as it was pushed.
  3407.      The next word, at `[BP+2]', holds the offset part of the return
  3408.      address, and the next one at `[BP+4]' the segment part. The
  3409.      parameters begin at `[BP+6]'. The rightmost parameter of the
  3410.      function, since it was pushed last, is accessible at this offset
  3411.      from `BP'; the others follow, at successively greater offsets.
  3412.    * The callee may also wish to decrease `SP' further, so as to
  3413.      allocate space on the stack for local variables, which will then
  3414.      be accessible at negative offsets from `BP'.
  3415.    * The callee, if it wishes to return a value to the caller, should
  3416.      leave the value in `AL', `AX' or `DX:AX' depending on the size of
  3417.      the value. Floating-point results are returned in `ST0'. Results
  3418.      of type `Real' (Borland's own custom floating-point data type, not
  3419.      handled directly by the FPU) are returned in `DX:BX:AX'. To return
  3420.      a result of type `String', the caller pushes a pointer to a
  3421.      temporary string before pushing the parameters, and the callee
  3422.      places the returned string value at that location. The pointer is
  3423.      not a parameter, and should not be removed from the stack by the
  3424.      `RETF' instruction.
  3425.    * Once the callee has finished processing, it restores `SP' from
  3426.      `BP' if it had allocated local stack space, then pops the previous
  3427.      value of `BP', and returns via `RETF'. It uses the form of `RETF'
  3428.      with an immediate parameter, giving the number of bytes taken up
  3429.      by the parameters on the stack. This causes the parameters to be
  3430.      removed from the stack as a side effect of the return instruction.
  3431.    * When the caller regains control from the callee, the function
  3432.      parameters have already been removed from the stack, so it needs
  3433.      to do nothing further.
  3434.    Thus, you would define a function in Pascal style, taking two
  3435. `Integer'-type parameters, in the following way:
  3436.                global myfunc
  3437.      myfunc:   push bp
  3438.                mov bp,sp
  3439.                sub sp,0x40            ; 64 bytes of local stack space
  3440.                mov bx,[bp+8]          ; first parameter to function
  3441.                mov bx,[bp+6]          ; second parameter to function
  3442.                ; some more code
  3443.                mov sp,bp              ; undo "sub sp,0x40" above
  3444.                pop bp
  3445.                retf 4                 ; total size of params is 4
  3446.    At the other end of the process, to call a Pascal function from your
  3447. assembly code, you would do something like this:
  3448.                extern SomeFunc
  3449.                ; and then, further down...
  3450.                push word seg mystring ; Now push the segment, and...
  3451.                push word mystring     ; ... offset of "mystring"
  3452.                push word [myint]      ; one of my variables
  3453.                call far SomeFunc
  3454.    This is equivalent to the Pascal code
  3455.      procedure SomeFunc(String: PChar; Int: Integer);
  3456.          SomeFunc(@mystring, myint);
  3457. File: nasm.info,  Node: Section 7.5.2,  Next: Section 7.5.3,  Prev: Section 7.5.1,  Up: Section 7.5
  3458. 7.5.2. Borland Pascal Segment Name Restrictions
  3459. ***********************************************
  3460.    Since Borland Pascal's internal unit file format is completely
  3461. different from `OBJ', it only makes a very sketchy job of actually
  3462. reading and understanding the various information contained in a real
  3463. `OBJ' file when it links that in. Therefore an object file intended to
  3464. be linked to a Pascal program must obey a number of restrictions:
  3465.    * Procedures and functions must be in a segment whose name is either
  3466.      `CODE', `CSEG', or something ending in `_TEXT'.
  3467.    * Initialised data must be in a segment whose name is either `CONST'
  3468.      or something ending in `_DATA'.
  3469.    * Uninitialised data must be in a segment whose name is either
  3470.      `DATA', `DSEG', or something ending in `_BSS'.
  3471.    * Any other segments in the object file are completely ignored.
  3472.      `GROUP' directives and segment attributes are also ignored.
  3473. File: nasm.info,  Node: Section 7.5.3,  Next: Chapter 8,  Prev: Section 7.5.2,  Up: Section 7.5
  3474. 7.5.3. Using `c16.mac' With Pascal Programs
  3475. *******************************************
  3476.    The `c16.mac' macro package, described in *Note Section 7.4.5::, can
  3477. also be used to simplify writing functions to be called from Pascal
  3478. programs, if you code `%define PASCAL'. This definition ensures that
  3479. functions are far (it implies `FARCODE'), and also causes procedure
  3480. return instructions to be generated with an operand.
  3481.    Defining `PASCAL' does not change the code which calculates the
  3482. argument offsets; you must declare your function's arguments in reverse
  3483. order. For example:
  3484.      %define PASCAL
  3485.                proc _pascalproc
  3486.      %$j       arg 4
  3487.      %$i       arg
  3488.                mov ax,[bp + %$i]
  3489.                mov bx,[bp + %$j]
  3490.                mov es,[bp + %$j + 2]
  3491.                add ax,[bx]
  3492.                endproc
  3493.    This defines the same routine, conceptually, as the example in *Note
  3494. Section 7.4.5::: it defines a function taking two arguments, an integer
  3495. and a pointer to an integer, which returns the sum of the integer and
  3496. the contents of the pointer. The only difference between this code and
  3497. the large-model C version is that `PASCAL' is defined instead of
  3498. `FARCODE', and that the arguments are declared in reverse order.
  3499. File: nasm.info,  Node: Chapter 8,  Next: Section 8.1,  Prev: Section 7.5.3,  Up: Top
  3500. Chapter 8: Writing 32-bit Code (Unix, Win32, DJGPP)
  3501. ***************************************************
  3502.    This chapter attempts to cover some of the common issues involved
  3503. when writing 32-bit code, to run under Win32 or Unix, or to be linked
  3504. with C code generated by a Unix-style C compiler such as DJGPP. It
  3505. covers how to write assembly code to interface with 32-bit C routines,
  3506. and how to write position-independent code for shared libraries.
  3507.    Almost all 32-bit code, and in particular all code running under
  3508. Win32, DJGPP or any of the PC Unix variants, runs in *flat* memory
  3509. model.  This means that the segment registers and paging have already
  3510. been set up to give you the same 32-bit 4Gb address space no matter
  3511. what segment you work relative to, and that you should ignore all
  3512. segment registers completely. When writing flat-model application code,
  3513. you never need to use a segment override or modify any segment
  3514. register, and the code-section addresses you pass to `CALL' and `JMP'
  3515. live in the same address space as the data-section addresses you access
  3516. your variables by and the stack-section addresses you access local
  3517. variables and procedure parameters by. Every address is 32 bits long
  3518. and contains only an offset part.
  3519. * Menu:
  3520. * Section 8.1:: Interfacing to 32-bit C Programs
  3521. * Section 8.2:: Writing NetBSD/FreeBSD/OpenBSD and Linux/ELF Shared Libraries
  3522. File: nasm.info,  Node: Section 8.1,  Next: Section 8.1.1,  Prev: Chapter 8,  Up: Chapter 8
  3523. 8.1. Interfacing to 32-bit C Programs
  3524. *************************************
  3525.    A lot of the discussion in *Note Section 7.4::, about interfacing to
  3526. 16-bit C programs, still applies when working in 32 bits. The absence
  3527. of memory models or segmentation worries simplifies things a lot.
  3528. * Menu:
  3529. * Section 8.1.1:: External Symbol Names
  3530. * Section 8.1.2:: Function Definitions and Function Calls
  3531. * Section 8.1.3:: Accessing Data Items
  3532. * Section 8.1.4:: `c32.mac': Helper Macros for the 32-bit C Interface
  3533. File: nasm.info,  Node: Section 8.1.1,  Next: Section 8.1.2,  Prev: Section 8.1,  Up: Section 8.1
  3534. 8.1.1. External Symbol Names
  3535. ****************************
  3536.    Most 32-bit C compilers share the convention used by 16-bit
  3537. compilers, that the names of all global symbols (functions or data)
  3538. they define are formed by prefixing an underscore to the name as it
  3539. appears in the C program.  However, not all of them do: the ELF
  3540. specification states that C symbols do *not* have a leading underscore
  3541. on their assembly-language names.
  3542.    The older Linux `a.out' C compiler, all Win32 compilers, DJGPP, and
  3543. NetBSD and FreeBSD, all use the leading underscore; for these compilers,
  3544. the macros `cextern' and `cglobal', as given in *Note Section 7.4.1::,
  3545. will still work. For ELF, though, the leading underscore should not be
  3546. used.
  3547. File: nasm.info,  Node: Section 8.1.2,  Next: Section 8.1.3,  Prev: Section 8.1.1,  Up: Section 8.1
  3548. 8.1.2. Function Definitions and Function Calls
  3549. **********************************************
  3550.    The C calling conventionThe C calling convention in 32-bit programs
  3551. is as follows. In the following description, the words *caller* and
  3552. *callee* are used to denote the function doing the calling and the
  3553. function which gets called.
  3554.    * The caller pushes the function's parameters on the stack, one after
  3555.      another, in reverse order (right to left, so that the first
  3556.      argument specified to the function is pushed last).
  3557.    * The caller then executes a near `CALL' instruction to pass control
  3558.      to the callee.
  3559.    * The callee receives control, and typically (although this is not
  3560.      actually necessary, in functions which do not need to access their
  3561.      parameters) starts by saving the value of `ESP' in `EBP' so as to
  3562.      be able to use `EBP' as a base pointer to find its parameters on
  3563.      the stack.  However, the caller was probably doing this too, so
  3564.      part of the calling convention states that `EBP' must be preserved
  3565.      by any C function.  Hence the callee, if it is going to set up
  3566.      `EBP' as a frame pointer, must push the previous value first.
  3567.    * The callee may then access its parameters relative to `EBP'. The
  3568.      doubleword at `[EBP]' holds the previous value of `EBP' as it was
  3569.      pushed; the next doubleword, at `[EBP+4]', holds the return
  3570.      address, pushed implicitly by `CALL'. The parameters start after
  3571.      that, at `[EBP+8]'. The leftmost parameter of the function, since
  3572.      it was pushed last, is accessible at this offset from `EBP'; the
  3573.      others follow, at successively greater offsets. Thus, in a
  3574.      function such as `printf' which takes a variable number of
  3575.      parameters, the pushing of the parameters in reverse order means
  3576.      that the function knows where to find its first parameter, which
  3577.      tells it the number and type of the remaining ones.
  3578.    * The callee may also wish to decrease `ESP' further, so as to
  3579.      allocate space on the stack for local variables, which will then
  3580.      be accessible at negative offsets from `EBP'.
  3581.    * The callee, if it wishes to return a value to the caller, should
  3582.      leave the value in `AL', `AX' or `EAX' depending on the size of the
  3583.      value. Floating-point results are typically returned in `ST0'.
  3584.    * Once the callee has finished processing, it restores `ESP' from
  3585.      `EBP' if it had allocated local stack space, then pops the previous
  3586.      value of `EBP', and returns via `RET' (equivalently, `RETN').
  3587.    * When the caller regains control from the callee, the function
  3588.      parameters are still on the stack, so it typically adds an
  3589.      immediate constant to `ESP' to remove them (instead of executing a
  3590.      number of slow `POP' instructions). Thus, if a function is
  3591.      accidentally called with the wrong number of parameters due to a
  3592.      prototype mismatch, the stack will still be returned to a sensible
  3593.      state since the caller, which *knows* how many parameters it
  3594.      pushed, does the removing.
  3595.    There is an alternative calling convention used by Win32 programs for
  3596. Windows API calls, and also for functions called *by* the Windows API
  3597. such as window procedures: they follow what Microsoft calls the
  3598. `__stdcall' convention. This is slightly closer to the Pascal
  3599. convention, in that the callee clears the stack by passing a parameter
  3600. to the `RET' instruction. However, the parameters are still pushed in
  3601. right-to-left order.
  3602.    Thus, you would define a function in C style in the following way:
  3603.                global _myfunc
  3604.      _myfunc:  push ebp
  3605.                mov ebp,esp
  3606.                sub esp,0x40           ; 64 bytes of local stack space
  3607.                mov ebx,[ebp+8]        ; first parameter to function
  3608.                ; some more code
  3609.                leave                  ; mov esp,ebp / pop ebp
  3610.                ret
  3611.    At the other end of the process, to call a C function from your
  3612. assembly code, you would do something like this:
  3613.                extern _printf
  3614.                ; and then, further down...
  3615.                push dword [myint]     ; one of my integer variables
  3616.                push dword mystring    ; pointer into my data segment
  3617.                call _printf
  3618.                add esp,byte 8         ; `byte' saves space
  3619.                ; then those data items...
  3620.                segment _DATA
  3621.      myint     dd 1234
  3622.      mystring  db 'This number -> %d <- should be 1234',10,0
  3623.    This piece of code is the assembly equivalent of the C code
  3624.          int myint = 1234;
  3625.          printf("This number -> %d <- should be 1234\n", myint);
  3626. File: nasm.info,  Node: Section 8.1.3,  Next: Section 8.1.4,  Prev: Section 8.1.2,  Up: Section 8.1
  3627. 8.1.3. Accessing Data Items
  3628. ***************************
  3629.    To get at the contents of C variables, or to declare variables which
  3630. C can access, you need only declare the names as `GLOBAL' or `EXTERN'.
  3631. (Again, the names require leading underscores, as stated in *Note
  3632. Section 8.1.1::.) Thus, a C variable declared as `int i' can be
  3633. accessed from assembler as
  3634.                extern _i
  3635.                mov eax,[_i]
  3636.    And to declare your own integer variable which C programs can access
  3637. as `extern int j', you do this (making sure you are assembling in the
  3638. `_DATA' segment, if necessary):
  3639.                global _j
  3640.      _j        dd 0
  3641.    To access a C array, you need to know the size of the components of
  3642. the array. For example, `int' variables are four bytes long, so if a C
  3643. program declares an array as `int a[10]', you can access `a[3]' by
  3644. coding `mov ax,[_a+12]'. (The byte offset 12 is obtained by multiplying
  3645. the desired array index, 3, by the size of the array element, 4.) The
  3646. sizes of the C base types in 32-bit compilers are: 1 for `char', 2 for
  3647. `short', 4 for `int', `long' and `float', and 8 for `double'. Pointers,
  3648. being 32-bit addresses, are also 4 bytes long.
  3649.    To access a C data structure, you need to know the offset from the
  3650. base of the structure to the field you are interested in. You can
  3651. either do this by converting the C structure definition into a NASM
  3652. structure definition (using `STRUC'), or by calculating the one offset
  3653. and using just that.
  3654.    To do either of these, you should read your C compiler's manual to
  3655. find out how it organises data structures. NASM gives no special
  3656. alignment to structure members in its own `STRUC' macro, so you have to
  3657. specify alignment yourself if the C compiler generates it. Typically,
  3658. you might find that a structure like
  3659.      struct {
  3660.          char c;
  3661.          int i;
  3662.      } foo;
  3663.    might be eight bytes long rather than five, since the `int' field
  3664. would be aligned to a four-byte boundary. However, this sort of feature
  3665. is sometimes a configurable option in the C compiler, either using
  3666. command- line options or `#pragma' lines, so you have to find out how
  3667. your own compiler does it.
  3668. File: nasm.info,  Node: Section 8.1.4,  Next: Section 8.2,  Prev: Section 8.1.3,  Up: Section 8.1
  3669. 8.1.4. `c32.mac': Helper Macros for the 32-bit C Interface
  3670. **********************************************************
  3671.    Included in the NASM archives, in the `misc' directory, is a file
  3672. `c32.mac' of macros. It defines three macros: `proc', `arg' and
  3673. `endproc'. These are intended to be used for C-style procedure
  3674. definitions, and they automate a lot of the work involved in keeping
  3675. track of the calling convention.
  3676.    An example of an assembly function using the macro set is given here:
  3677.                proc _proc32
  3678.      %$i       arg
  3679.      %$j       arg
  3680.                mov eax,[ebp + %$i]
  3681.                mov ebx,[ebp + %$j]
  3682.                add eax,[ebx]
  3683.                endproc
  3684.    This defines `_proc32' to be a procedure taking two arguments, the
  3685. first (`i') an integer and the second (`j') a pointer to an integer. It
  3686. returns `i + *j'.
  3687.    Note that the `arg' macro has an `EQU' as the first line of its
  3688. expansion, and since the label before the macro call gets prepended to
  3689. the first line of the expanded macro, the `EQU' works, defining `%$i'
  3690. to be an offset from `BP'. A context-local variable is used, local to
  3691. the context pushed by the `proc' macro and popped by the `endproc'
  3692. macro, so that the same argument name can be used in later procedures.
  3693. Of course, you don't *have* to do that.
  3694.    `arg' can take an optional parameter, giving the size of the
  3695. argument.  If no size is given, 4 is assumed, since it is likely that
  3696. many function parameters will be of type `int' or pointers.
  3697. File: nasm.info,  Node: Section 8.2,  Next: Section 8.2.1,  Prev: Section 8.1.4,  Up: Chapter 8
  3698. 8.2. Writing NetBSD/FreeBSD/OpenBSD and Linux/ELF Shared Libraries
  3699. ******************************************************************
  3700.    ELF replaced the older `a.out' object file format under Linux because
  3701. it contains support for position-independent code (PIC), which makes
  3702. writing shared libraries much easier. NASM supports the ELF position-
  3703. independent code features, so you can write Linux ELF shared libraries
  3704. in NASM.
  3705.    NetBSD, and its close cousins FreeBSD and OpenBSD, take a different
  3706. approach by hacking PIC support into the `a.out' format. NASM supports
  3707. this as the `aoutb' output format, so you can write BSD shared
  3708. libraries in NASM too.
  3709.    The operating system loads a PIC shared library by memory-mapping the
  3710. library file at an arbitrarily chosen point in the address space of the
  3711. running process. The contents of the library's code section must
  3712. therefore not depend on where it is loaded in memory.
  3713.    Therefore, you cannot get at your variables by writing code like
  3714. this:
  3715.                mov eax,[myvar]        ; WRONG
  3716.    Instead, the linker provides an area of memory called the *global
  3717. offset table*, or GOT; the GOT is situated at a constant distance from
  3718. your library's code, so if you can find out where your library is
  3719. loaded (which is typically done using a `CALL' and `POP' combination),
  3720. you can obtain the address of the GOT, and you can then load the
  3721. addresses of your variables out of linker-generated entries in the GOT.
  3722.    The *data* section of a PIC shared library does not have these
  3723. restrictions: since the data section is writable, it has to be copied
  3724. into memory anyway rather than just paged in from the library file, so
  3725. as long as it's being copied it can be relocated too. So you can put
  3726. ordinary types of relocation in the data section without too much worry
  3727. (but see *Note Section 8.2.4:: for a caveat).
  3728. * Menu:
  3729. * Section 8.2.1:: Obtaining the Address of the GOT
  3730. * Section 8.2.2:: Finding Your Local Data Items
  3731. * Section 8.2.3:: Finding External and Common Data Items
  3732. * Section 8.2.4:: Exporting Symbols to the Library User
  3733. * Section 8.2.5:: Calling Procedures Outside the Library
  3734. * Section 8.2.6:: Generating the Library File
  3735. File: nasm.info,  Node: Section 8.2.1,  Next: Section 8.2.2,  Prev: Section 8.2,  Up: Section 8.2
  3736. 8.2.1. Obtaining the Address of the GOT
  3737. ***************************************
  3738.    Each code module in your shared library should define the GOT as an
  3739. external symbol:
  3740.                extern _GLOBAL_OFFSET_TABLE_   ; in ELF
  3741.                extern __GLOBAL_OFFSET_TABLE_  ; in BSD a.out
  3742.    At the beginning of any function in your shared library which plans
  3743. to access your data or BSS sections, you must first calculate the
  3744. address of the GOT. This is typically done by writing the function in
  3745. this form:
  3746.      func:     push ebp
  3747.                mov ebp,esp
  3748.                push ebx
  3749.                call .get_GOT
  3750.      .get_GOT: pop ebx
  3751.                add ebx,_GLOBAL_OFFSET_TABLE_+$$-.get_GOT wrt ..gotpc
  3752.                ; the function body comes here
  3753.                mov ebx,[ebp-4]
  3754.                mov esp,ebp
  3755.                pop ebp
  3756.                ret
  3757.    (For BSD, again, the symbol `_GLOBAL_OFFSET_TABLE' requires a second
  3758. leading underscore.)
  3759.    The first two lines of this function are simply the standard C
  3760. prologue to set up a stack frame, and the last three lines are standard
  3761. C function epilogue. The third line, and the fourth to last line, save
  3762. and restore the `EBX' register, because PIC shared libraries use this
  3763. register to store the address of the GOT.
  3764.    The interesting bit is the `CALL' instruction and the following two
  3765. lines. The `CALL' and `POP' combination obtains the address of the
  3766. label `.get_GOT', without having to know in advance where the program
  3767. was loaded (since the `CALL' instruction is encoded relative to the
  3768. current position). The `ADD' instruction makes use of one of the
  3769. special PIC relocation types: GOTPC relocation. With the `WRT ..gotpc'
  3770. qualifier specified, the symbol referenced (here
  3771. `_GLOBAL_OFFSET_TABLE_', the special symbol assigned to the GOT) is
  3772. given as an offset from the beginning of the section. (Actually, ELF
  3773. encodes it as the offset from the operand field of the `ADD'
  3774. instruction, but NASM simplifies this deliberately, so you do things the
  3775. same way for both ELF and BSD.) So the instruction then *adds* the
  3776. beginning of the section, to get the real address of the GOT, and
  3777. subtracts the value of `.get_GOT' which it knows is in `EBX'.
  3778. Therefore, by the time that instruction has finished, `EBX' contains
  3779. the address of the GOT.
  3780.    If you didn't follow that, don't worry: it's never necessary to
  3781. obtain the address of the GOT by any other means, so you can put those
  3782. three instructions into a macro and safely ignore them:
  3783.      %macro get_GOT 0
  3784.                call %%getgot
  3785.      %%getgot: pop ebx
  3786.                add ebx,_GLOBAL_OFFSET_TABLE_+$$-%%getgot wrt ..gotpc
  3787.      %endmacro
  3788. File: nasm.info,  Node: Section 8.2.2,  Next: Section 8.2.3,  Prev: Section 8.2.1,  Up: Section 8.2
  3789. 8.2.2. Finding Your Local Data Items
  3790. ************************************
  3791.    Having got the GOT, you can then use it to obtain the addresses of
  3792. your data items. Most variables will reside in the sections you have
  3793. declared; they can be accessed using the `..gotoff' special `WRT' type.
  3794. The way this works is like this:
  3795.                lea eax,[ebx+myvar wrt ..gotoff]
  3796.    The expression `myvar wrt ..gotoff' is calculated, when the shared
  3797. library is linked, to be the offset to the local variable `myvar' from
  3798. the beginning of the GOT. Therefore, adding it to `EBX' as above will
  3799. place the real address of `myvar' in `EAX'.
  3800.    If you declare variables as `GLOBAL' without specifying a size for
  3801. them, they are shared between code modules in the library, but do not
  3802. get exported from the library to the program that loaded it. They will
  3803. still be in your ordinary data and BSS sections, so you can access them
  3804. in the same way as local variables, using the above `..gotoff'
  3805. mechanism.
  3806.    Note that due to a peculiarity of the way BSD `a.out' format handles
  3807. this relocation type, there must be at least one non-local symbol in the
  3808. same section as the address you're trying to access.
  3809. File: nasm.info,  Node: Section 8.2.3,  Next: Section 8.2.4,  Prev: Section 8.2.2,  Up: Section 8.2
  3810. 8.2.3. Finding External and Common Data Items
  3811. *********************************************
  3812.    If your library needs to get at an external variable (external to the
  3813. *library*, not just to one of the modules within it), you must use the
  3814. `..got' type to get at it. The `..got' type, instead of giving you the
  3815. offset from the GOT base to the variable, gives you the offset from the
  3816. GOT base to a GOT *entry* containing the address of the variable.  The
  3817. linker will set up this GOT entry when it builds the library, and the
  3818. dynamic linker will place the correct address in it at load time. So to
  3819. obtain the address of an external variable `extvar' in `EAX', you would
  3820.                mov eax,[ebx+extvar wrt ..got]
  3821.    This loads the address of `extvar' out of an entry in the GOT. The
  3822. linker, when it builds the shared library, collects together every
  3823. relocation of type `..got', and builds the GOT so as to ensure it has
  3824. every necessary entry present.
  3825.    Common variables must also be accessed in this way.
  3826. File: nasm.info,  Node: Section 8.2.4,  Next: Section 8.2.5,  Prev: Section 8.2.3,  Up: Section 8.2
  3827. 8.2.4. Exporting Symbols to the Library User
  3828. ********************************************
  3829.    If you want to export symbols to the user of the library, you have to
  3830. declare whether they are functions or data, and if they are data, you
  3831. have to give the size of the data item. This is because the dynamic
  3832. linker has to build procedure linkage table entries for any exported
  3833. functions, and also moves exported data items away from the library's
  3834. data section in which they were declared.
  3835.    So to export a function to users of the library, you must use
  3836.                global func:function   ; declare it as a function
  3837.      func:     push ebp
  3838.                ; etc.
  3839.    And to export a data item such as an array, you would have to code
  3840.                global array:data array.end-array ; give the size too
  3841.      array:    resd 128
  3842.      .end:
  3843.    Be careful: If you export a variable to the library user, by
  3844. declaring it as `GLOBAL' and supplying a size, the variable will end up
  3845. living in the data section of the main program, rather than in your
  3846. library's data section, where you declared it. So you will have to
  3847. access your own global variable with the `..got' mechanism rather than
  3848. `..gotoff', as if it were external (which, effectively, it has become).
  3849.    Equally, if you need to store the address of an exported global in
  3850. one of your data sections, you can't do it by means of the standard
  3851. sort of code:
  3852.      dataptr:  dd global_data_item    ; WRONG
  3853.    NASM will interpret this code as an ordinary relocation, in which
  3854. `global_data_item' is merely an offset from the beginning of the
  3855. `.data' section (or whatever); so this reference will end up pointing
  3856. at your data section instead of at the exported global which resides
  3857. elsewhere.
  3858.    Instead of the above code, then, you must write
  3859.      dataptr:  dd global_data_item wrt ..sym
  3860.    which makes use of the special `WRT' type `..sym' to instruct NASM
  3861. to search the symbol table for a particular symbol at that address,
  3862. rather than just relocating by section base.
  3863.    Either method will work for functions: referring to one of your
  3864. functions by means of
  3865.      funcptr:  dd my_function
  3866.    will give the user the address of the code you wrote, whereas
  3867.      funcptr:  dd my_function wrt ..sym
  3868.    will give the address of the procedure linkage table for the
  3869. function, which is where the calling program will *believe* the
  3870. function lives.  Either address is a valid way to call the function.
  3871. File: nasm.info,  Node: Section 8.2.5,  Next: Section 8.2.6,  Prev: Section 8.2.4,  Up: Section 8.2
  3872. 8.2.5. Calling Procedures Outside the Library
  3873. *********************************************
  3874.    Calling procedures outside your shared library has to be done by
  3875. means of a *procedure linkage table*, or PLT. The PLT is placed at a
  3876. known offset from where the library is loaded, so the library code can
  3877. make calls to the PLT in a position-independent way. Within the PLT
  3878. there is code to jump to offsets contained in the GOT, so function
  3879. calls to other shared libraries or to routines in the main program can
  3880. be transparently passed off to their real destinations.
  3881.    To call an external routine, you must use another special PIC
  3882. relocation type, `WRT ..plt'. This is much easier than the GOT-based
  3883. ones: you simply replace calls such as `CALL printf' with the
  3884. PLT-relative version `CALL printf WRT ..plt'.
  3885. File: nasm.info,  Node: Section 8.2.6,  Next: Chapter 9,  Prev: Section 8.2.5,  Up: Section 8.2
  3886. 8.2.6. Generating the Library File
  3887. **********************************
  3888.    Having written some code modules and assembled them to `.o' files,
  3889. you then generate your shared library with a command such as
  3890.      ld -shared -o library.so module1.o module2.o       # for ELF
  3891.      ld -Bshareable -o library.so module1.o module2.o   # for BSD
  3892.    For ELF, if your shared library is going to reside in system
  3893. directories such as `/usr/lib' or `/lib', it is usually worth using the
  3894. `-soname' flag to the linker, to store the final library file name,
  3895. with a version number, into the library:
  3896.      ld -shared -soname library.so.1 -o library.so.1.2 *.o
  3897.    You would then copy `library.so.1.2' into the library directory, and
  3898. create `library.so.1' as a symbolic link to it.
  3899. File: nasm.info,  Node: Chapter 9,  Next: Section 9.1,  Prev: Section 8.2.6,  Up: Top
  3900. Chapter 9: Mixing 16 and 32 Bit Code
  3901. ************************************
  3902.    This chapter tries to cover some of the issues, largely related to
  3903. unusual forms of addressing and jump instructions, encountered when
  3904. writing operating system code such as protected-mode initialisation
  3905. routines, which require code that operates in mixed segment sizes, such
  3906. as code in a 16-bit segment trying to modify data in a 32-bit one, or
  3907. jumps between different- size segments.
  3908. * Menu:
  3909. * Section 9.1:: Mixed-Size Jumps
  3910. * Section 9.2:: Addressing Between Different-Size Segments
  3911. * Section 9.3:: Other Mixed-Size Instructions
  3912. File: nasm.info,  Node: Section 9.1,  Next: Section 9.2,  Prev: Chapter 9,  Up: Chapter 9
  3913. 9.1. Mixed-Size Jumps
  3914. *********************
  3915.    The most common form of mixed-size instruction is the one used when
  3916. writing a 32-bit OS: having done your setup in 16-bit mode, such as
  3917. loading the kernel, you then have to boot it by switching into
  3918. protected mode and jumping to the 32-bit kernel start address. In a
  3919. fully 32-bit OS, this tends to be the *only* mixed-size instruction you
  3920. need, since everything before it can be done in pure 16-bit code, and
  3921. everything after it can be pure 32-bit.
  3922.    This jump must specify a 48-bit far address, since the target
  3923. segment is a 32-bit one. However, it must be assembled in a 16-bit
  3924. segment, so just coding, for example,
  3925.                jmp 0x1234:0x56789ABC  ; wrong!
  3926.    will not work, since the offset part of the address will be
  3927. truncated to `0x9ABC' and the jump will be an ordinary 16-bit far one.
  3928.    The Linux kernel setup code gets round the inability of `as86' to
  3929. generate the required instruction by coding it manually, using `DB'
  3930. instructions. NASM can go one better than that, by actually generating
  3931. the right instruction itself. Here's how to do it right:
  3932.                jmp dword 0x1234:0x56789ABC  ; right
  3933.    The `DWORD' prefix (strictly speaking, it should come *after* the
  3934. colon, since it is declaring the *offset* field to be a doubleword; but
  3935. NASM will accept either form, since both are unambiguous) forces the
  3936. offset part to be treated as far, in the assumption that you are
  3937. deliberately writing a jump from a 16-bit segment to a 32-bit one.
  3938.    You can do the reverse operation, jumping from a 32-bit segment to a
  3939. 16-bit one, by means of the `WORD' prefix:
  3940.                jmp word 0x8765:0x4321 ; 32 to 16 bit
  3941.    If the `WORD' prefix is specified in 16-bit mode, or the `DWORD'
  3942. prefix in 32-bit mode, they will be ignored, since each is explicitly
  3943. forcing NASM into a mode it was in anyway.
  3944. File: nasm.info,  Node: Section 9.2,  Next: Section 9.3,  Prev: Section 9.1,  Up: Chapter 9
  3945. 9.2. Addressing Between Different-Size Segments
  3946. ***********************************************
  3947.    If your OS is mixed 16 and 32-bit, or if you are writing a DOS
  3948. extender, you are likely to have to deal with some 16-bit segments and
  3949. some 32-bit ones. At some point, you will probably end up writing code
  3950. in a 16-bit segment which has to access data in a 32-bit segment, or
  3951. vice versa.
  3952.    If the data you are trying to access in a 32-bit segment lies within
  3953. the first 64K of the segment, you may be able to get away with using an
  3954. ordinary 16-bit addressing operation for the purpose; but sooner or
  3955. later, you will want to do 32-bit addressing from 16-bit mode.
  3956.    The easiest way to do this is to make sure you use a register for the
  3957. address, since any effective address containing a 32-bit register is
  3958. forced to be a 32-bit address. So you can do
  3959.                mov eax,offset_into_32_bit_segment_specified_by_fs
  3960.                mov dword [fs:eax],0x11223344
  3961.    This is fine, but slightly cumbersome (since it wastes an
  3962. instruction and a register) if you already know the precise offset you
  3963. are aiming at. The x86 architecture does allow 32-bit effective
  3964. addresses to specify nothing but a 4-byte offset, so why shouldn't NASM
  3965. be able to generate the best instruction for the purpose?
  3966.    It can. As in *Note Section 9.1::, you need only prefix the address
  3967. with the `DWORD' keyword, and it will be forced to be a 32-bit address:
  3968.                mov dword [fs:dword my_offset],0x11223344
  3969.    Also as in *Note Section 9.1::, NASM is not fussy about whether the
  3970. `DWORD' prefix comes before or after the segment override, so arguably
  3971. a nicer-looking way to code the above instruction is
  3972.                mov dword [dword fs:my_offset],0x11223344
  3973.    Don't confuse the `DWORD' prefix *outside* the square brackets,
  3974. which controls the size of the data stored at the address, with the one
  3975. `inside' the square brackets which controls the length of the address
  3976. itself. The two can quite easily be different:
  3977.                mov word [dword 0x12345678],0x9ABC
  3978.    This moves 16 bits of data to an address specified by a 32-bit
  3979. offset.
  3980.    You can also specify `WORD' or `DWORD' prefixes along with the `FAR'
  3981. prefix to indirect far jumps or calls. For example:
  3982.                call dword far [fs:word 0x4321]
  3983.    This instruction contains an address specified by a 16-bit offset;
  3984. it loads a 48-bit far pointer from that (16-bit segment and 32-bit
  3985. offset), and calls that address.
  3986. File: nasm.info,  Node: Section 9.3,  Next: Chapter 10,  Prev: Section 9.2,  Up: Chapter 9
  3987. 9.3. Other Mixed-Size Instructions
  3988. **********************************
  3989.    The other way you might want to access data might be using the string
  3990. instructions (`LODSx', `STOSx' and so on) or the `XLATB' instruction.
  3991. These instructions, since they take no parameters, might seem to have
  3992. no easy way to make them perform 32-bit addressing when assembled in a
  3993. 16-bit segment.
  3994.    This is the purpose of NASM's `a16' and `a32' prefixes. If you are
  3995. coding `LODSB' in a 16-bit segment but it is supposed to be accessing a
  3996. string in a 32-bit segment, you should load the desired address into
  3997. `ESI' and then code
  3998.                a32 lodsb
  3999.    The prefix forces the addressing size to 32 bits, meaning that
  4000. `LODSB' loads from `[DS:ESI]' instead of `[DS:SI]'. To access a string
  4001. in a 16-bit segment when coding in a 32-bit one, the corresponding `a16'
  4002. prefix can be used.
  4003.    The `a16' and `a32' prefixes can be applied to any instruction in
  4004. NASM's instruction table, but most of them can generate all the useful
  4005. forms without them. The prefixes are necessary only for instructions
  4006. with implicit addressing: `CMPSx' (*Note Section A.19::), `SCASx'
  4007. (*Note Section A.149::), `LODSx' (*Note Section A.98::), `STOSx' (*Note
  4008. Section A.157::), `MOVSx' (*Note Section A.105::), `INSx' (*Note
  4009. Section A.80::), `OUTSx' (*Note Section A.112::), and `XLATB' (*Note
  4010. Section A.169::). Also, the various push and pop instructions (`PUSHA'
  4011. and `POPF' as well as the more usual `PUSH' and `POP') can accept `a16'
  4012. or `a32' prefixes to force a particular one of `SP' or `ESP' to be used
  4013. as a stack pointer, in case the stack segment in use is a different
  4014. size from the code segment.
  4015.    `PUSH' and `POP', when applied to segment registers in 32-bit mode,
  4016. also have the slightly odd behaviour that they push and pop 4 bytes at
  4017. a time, of which the top two are ignored and the bottom two give the
  4018. value of the segment register being manipulated. To force the 16-bit
  4019. behaviour of segment-register push and pop instructions, you can use the
  4020. operand-size prefix `o16':
  4021.                o16 push ss
  4022.                o16 push ds
  4023.    This code saves a doubleword of stack space by fitting two segment
  4024. registers into the space which would normally be consumed by pushing
  4025.    (You can also use the `o32' prefix to force the 32-bit behaviour when
  4026. in 16-bit mode, but this seems less useful.)
  4027. File: nasm.info,  Node: Chapter 10,  Next: Section 10.1,  Prev: Section 9.3,  Up: Top
  4028. Chapter 10: Troubleshooting
  4029. ***************************
  4030.    This chapter describes some of the common problems that users have
  4031. been known to encounter with NASM, and answers them. It also gives
  4032. instructions for reporting bugs in NASM if you find a difficulty that
  4033. isn't listed here.
  4034. * Menu:
  4035. * Section 10.1:: Common Problems
  4036. * Section 10.2:: Bugs
  4037. File: nasm.info,  Node: Section 10.1,  Next: Section 10.1.1,  Prev: Chapter 10,  Up: Chapter 10
  4038. 10.1. Common Problems
  4039. *********************
  4040. * Menu:
  4041. * Section 10.1.1:: NASM Generates Inefficient Code
  4042. * Section 10.1.2:: My Jumps are Out of Range
  4043. * Section 10.1.3:: `ORG' Doesn't Work
  4044. * Section 10.1.4:: `TIMES' Doesn't Work
  4045. File: nasm.info,  Node: Section 10.1.1,  Next: Section 10.1.2,  Prev: Section 10.1,  Up: Section 10.1
  4046. 10.1.1. NASM Generates Inefficient Code
  4047. ***************************************
  4048.    I get a lot of `bug' reports about NASM generating inefficient, or
  4049. even `wrong', code on instructions such as `ADD ESP,8'. This is a
  4050. deliberate design feature, connected to predictability of output: NASM,
  4051. on seeing `ADD ESP,8', will generate the form of the instruction which
  4052. leaves room for a 32-bit offset. You need to code `ADD ESP,BYTE 8' if
  4053. you want the space-efficient form of the instruction. This isn't a bug:
  4054. at worst it's a misfeature, and that's a matter of opinion only.
  4055. File: nasm.info,  Node: Section 10.1.2,  Next: Section 10.1.3,  Prev: Section 10.1.1,  Up: Section 10.1
  4056. 10.1.2. My Jumps are Out of Range
  4057. *********************************
  4058.    Similarly, people complain that when they issue conditional jumps
  4059. (which are `SHORT' by default) that try to jump too far, NASM reports
  4060. `short jump out of range' instead of making the jumps longer.
  4061.    This, again, is partly a predictability issue, but in fact has a more
  4062. practical reason as well. NASM has no means of being told what type of
  4063. processor the code it is generating will be run on; so it cannot decide
  4064. for itself that it should generate `Jcc NEAR' type instructions, because
  4065. it doesn't know that it's working for a 386 or above. Alternatively, it
  4066. could replace the out-of-range short `JNE' instruction with a very
  4067. short `JE' instruction that jumps over a `JMP NEAR'; this is a sensible
  4068. solution for processors below a 386, but hardly efficient on processors
  4069. which have good branch prediction *and* could have used `JNE NEAR'
  4070. instead. So, once again, it's up to the user, not the assembler, to
  4071. decide what instructions should be generated.
  4072. File: nasm.info,  Node: Section 10.1.3,  Next: Section 10.1.4,  Prev: Section 10.1.2,  Up: Section 10.1
  4073. 10.1.3. `ORG' Doesn't Work
  4074. **************************
  4075.    People writing boot sector programs in the `bin' format often
  4076. complain that `ORG' doesn't work the way they'd like: in order to place
  4077. the `0xAA55' signature word at the end of a 512-byte boot sector, people
  4078. who are used to MASM tend to code
  4079.                ORG 0
  4080.                ; some boot sector code
  4081.                ORG 510
  4082.                DW 0xAA55
  4083.    This is not the intended use of the `ORG' directive in NASM, and will
  4084. not work. The correct way to solve this problem in NASM is to use the
  4085. `TIMES' directive, like this:
  4086.                ORG 0
  4087.                ; some boot sector code
  4088.                TIMES 510-($-$$) DB 0
  4089.                DW 0xAA55
  4090.    The `TIMES' directive will insert exactly enough zero bytes into the
  4091. output to move the assembly point up to 510. This method also has the
  4092. advantage that if you accidentally fill your boot sector too full, NASM
  4093. will catch the problem at assembly time and report it, so you won't end
  4094. up with a boot sector that you have to disassemble to find out what's
  4095. wrong with it.
  4096. File: nasm.info,  Node: Section 10.1.4,  Next: Section 10.2,  Prev: Section 10.1.3,  Up: Section 10.1
  4097. 10.1.4. `TIMES' Doesn't Work
  4098. ****************************
  4099.    The other common problem with the above code is people who write the
  4100. `TIMES' line as
  4101.                TIMES 510-$ DB 0
  4102.    by reasoning that `$' should be a pure number, just like 510, so the
  4103. difference between them is also a pure number and can happily be fed to
  4104. `TIMES'.
  4105.    NASM is a *modular* assembler: the various component parts are
  4106. designed to be easily separable for re-use, so they don't exchange
  4107. information unnecessarily. In consequence, the `bin' output format,
  4108. even though it has been told by the `ORG' directive that the `.text'
  4109. section should start at 0, does not pass that information back to the
  4110. expression evaluator. So from the evaluator's point of view, `$' isn't
  4111. a pure number: it's an offset from a section base. Therefore the
  4112. difference between `$' and 510 is also not a pure number, but involves
  4113. a section base. Values involving section bases cannot be passed as
  4114. arguments to `TIMES'.
  4115.    The solution, as in the previous section, is to code the `TIMES' line
  4116. in the form
  4117.                TIMES 510-($-$$) DB 0
  4118.    in which `$' and `$$' are offsets from the same section base, and so
  4119. their difference is a pure number. This will solve the problem and
  4120. generate sensible code.
  4121. File: nasm.info,  Node: Section 10.2,  Next: Appendix A,  Prev: Section 10.1.4,  Up: Chapter 10
  4122. 10.2. Bugs
  4123. **********
  4124.    We have never yet released a version of NASM with any *known* bugs.
  4125. That doesn't usually stop there being plenty we didn't know about,
  4126. though.  Any that you find should be reported to `anakin@pobox.com'.
  4127.    Please read *Note Section 2.2:: first, and don't report the bug if
  4128. it's listed in there as a deliberate feature. (If you think the feature
  4129. is badly thought out, feel free to send us reasons why you think it
  4130. should be changed, but don't just send us mail saying `This is a bug'
  4131. if the documentation says we did it on purpose.) Then read *Note
  4132. Section 10.1::, and don't bother reporting the bug if it's listed there.
  4133.    If you do report a bug, *please* give us all of the following
  4134. information:
  4135.    * What operating system you're running NASM under. DOS, Linux,
  4136.      NetBSD, Win16, Win32, VMS (I'd be impressed), whatever.
  4137.    * If you're running NASM under DOS or Win32, tell us whether you've
  4138.      compiled your own executable from the DOS source archive, or
  4139.      whether you were using the standard distribution binaries out of
  4140.      the archive. If you were using a locally built executable, try to
  4141.      reproduce the problem using one of the standard binaries, as this
  4142.      will make it easier for us to reproduce your problem prior to
  4143.      fixing it.
  4144.    * Which version of NASM you're using, and exactly how you invoked
  4145.      it. Give us the precise command line, and the contents of the
  4146.      `NASM' environment variable if any.
  4147.    * Which versions of any supplementary programs you're using, and how
  4148.      you invoked them. If the problem only becomes visible at link
  4149.      time, tell us what linker you're using, what version of it you've
  4150.      got, and the exact linker command line. If the problem involves
  4151.      linking against object files generated by a compiler, tell us what
  4152.      compiler, what version, and what command line or options you used.
  4153.      (If you're compiling in an IDE, please try to reproduce the
  4154.      problem with the command-line version of the compiler.)
  4155.    * If at all possible, send us a NASM source file which exhibits the
  4156.      problem.  If this causes copyright problems (e.g. you can only
  4157.      reproduce the bug in restricted-distribution code) then bear in
  4158.      mind the following two points: firstly, we guarantee that any
  4159.      source code sent to us for the purposes of debugging NASM will be
  4160.      used *only* for the purposes of debugging NASM, and that we will
  4161.      delete all our copies of it as soon as we have found and fixed the
  4162.      bug or bugs in question; and secondly, we would prefer *not* to be
  4163.      mailed large chunks of code anyway. The smaller the file, the
  4164.      better.  A three-line sample file that does nothing useful
  4165.      *except* demonstrate the problem is much easier to work with than
  4166.      a fully fledged ten-thousand- line program. (Of course, some
  4167.      errors *do* only crop up in large files, so this may not be
  4168.      possible.)
  4169.    * A description of what the problem actually *is*. `It doesn't work'
  4170.      is *not* a helpful description! Please describe exactly what is
  4171.      happening that shouldn't be, or what isn't happening that should.
  4172.      Examples might be: `NASM generates an error message saying Line 3
  4173.      for an error that's actually on Line 5'; `NASM generates an error
  4174.      message that I believe it shouldn't be generating at all'; `NASM
  4175.      fails to generate an error message that I believe it *should* be
  4176.      generating'; `the object file produced from this source code
  4177.      crashes my linker'; `the ninth byte of the output file is 66 and I
  4178.      think it should be 77 instead'.
  4179.    * If you believe the output file from NASM to be faulty, send it to
  4180.      us. That allows us to determine whether our own copy of NASM
  4181.      generates the same file, or whether the problem is related to
  4182.      portability issues between our development platforms and yours. We
  4183.      can handle binary files mailed to us as MIME attachments,
  4184.      uuencoded, and even BinHex. Alternatively, we may be able to
  4185.      provide an FTP site you can upload the suspect files to; but
  4186.      mailing them is easier for us.
  4187.    * Any other information or data files that might be helpful. If, for
  4188.      example, the problem involves NASM failing to generate an object
  4189.      file while TASM can generate an equivalent file without trouble,
  4190.      then send us *both* object files, so we can see what TASM is doing
  4191.      differently from us.
  4192. File: nasm.info,  Node: Appendix A,  Next: Section A.1,  Prev: Section 10.2,  Up: Top
  4193. Appendix A: Intel x86 Instruction Reference
  4194. *******************************************
  4195.    This appendix provides a complete list of the machine instructions
  4196. which NASM will assemble, and a short description of the function of
  4197. each one.
  4198.    It is not intended to be exhaustive documentation on the fine
  4199. details of the instructions' function, such as which exceptions they
  4200. can trigger: for such documentation, you should go to Intel's Web site,
  4201. `http://www.intel.com'.
  4202.    Instead, this appendix is intended primarily to provide
  4203. documentation on the way the instructions may be used within NASM. For
  4204. example, looking up `LOOP' will tell you that NASM allows `CX' or `ECX'
  4205. to be specified as an optional second argument to the `LOOP'
  4206. instruction, to enforce which of the two possible counter registers
  4207. should be used if the default is not the one desired.
  4208.    The instructions are not quite listed in alphabetical order, since
  4209. groups of instructions with similar functions are lumped together in
  4210. the same entry. Most of them don't move very far from their alphabetic
  4211. position because of this.
  4212. * Menu:
  4213. * Section A.1:: Key to Operand Specifications
  4214. * Section A.2:: Key to Opcode Descriptions
  4215. * Section A.3:: Key to Instruction Flags
  4216. * Section A.4:: `AAA', `AAS', `AAM', `AAD': ASCII Adjustments
  4217. * Section A.5:: `ADC': Add with Carry
  4218. * Section A.6:: `ADD': Add Integers
  4219. * Section A.7:: `AND': Bitwise AND
  4220. * Section A.8:: `ARPL': Adjust RPL Field of Selector
  4221. * Section A.9:: `BOUND': Check Array Index against Bounds
  4222. * Section A.10:: `BSF', `BSR': Bit Scan
  4223. * Section A.11:: `BSWAP': Byte Swap
  4224. * Section A.12:: `BT', `BTC', `BTR', `BTS': Bit Test
  4225. * Section A.13:: `CALL': Call Subroutine
  4226. * Section A.14:: `CBW', `CWD', `CDQ', `CWDE': Sign Extensions
  4227. * Section A.15:: `CLC', `CLD', `CLI', `CLTS': Clear Flags
  4228. * Section A.16:: `CMC': Complement Carry Flag
  4229. * Section A.17:: `CMOVcc': Conditional Move
  4230. * Section A.18:: `CMP': Compare Integers
  4231. * Section A.19:: `CMPSB', `CMPSW', `CMPSD': Compare Strings
  4232. * Section A.20:: `CMPXCHG', `CMPXCHG486': Compare and Exchange
  4233. * Section A.21:: `CMPXCHG8B': Compare and Exchange Eight Bytes
  4234. * Section A.22:: `CPUID': Get CPU Identification Code
  4235. * Section A.23:: `DAA', `DAS': Decimal Adjustments
  4236. * Section A.24:: `DEC': Decrement Integer
  4237. * Section A.25:: `DIV': Unsigned Integer Divide
  4238. * Section A.26:: `EMMS': Empty MMX State
  4239. * Section A.27:: `ENTER': Create Stack Frame
  4240. * Section A.28:: `F2XM1': Calculate 2**X-1
  4241. * Section A.29:: `FABS': Floating-Point Absolute Value
  4242. * Section A.30:: `FADD', `FADDP': Floating-Point Addition
  4243. * Section A.31:: `FBLD', `FBSTP': BCD Floating-Point Load and Store
  4244. * Section A.32:: `FCHS': Floating-Point Change Sign
  4245. * Section A.33:: `FCLEX', {FNCLEX}: Clear Floating-Point Exceptions
  4246. * Section A.34:: `FCMOVcc': Floating-Point Conditional Move
  4247. * Section A.35:: `FCOM', `FCOMP', `FCOMPP', `FCOMI', `FCOMIP': Floating-Point Compare
  4248. * Section A.36:: `FCOS': Cosine
  4249. * Section A.37:: `FDECSTP': Decrement Floating-Point Stack Pointer
  4250. * Section A.38:: `FxDISI', `FxENI': Disable and Enable Floating-Point Interrupts
  4251. * Section A.39:: `FDIV', `FDIVP', `FDIVR', `FDIVRP': Floating-Point Division
  4252. * Section A.40:: `FFREE': Flag Floating-Point Register as Unused
  4253. * Section A.41:: `FIADD': Floating-Point/Integer Addition
  4254. * Section A.42:: `FICOM', `FICOMP': Floating-Point/Integer Compare
  4255. * Section A.43:: `FIDIV', `FIDIVR': Floating-Point/Integer Division
  4256. * Section A.44:: `FILD', `FIST', `FISTP': Floating-Point/Integer Conversion
  4257. * Section A.45:: `FIMUL': Floating-Point/Integer Multiplication
  4258. * Section A.46:: `FINCSTP': Increment Floating-Point Stack Pointer
  4259. * Section A.47:: `FINIT', `FNINIT': Initialise Floating-Point Unit
  4260. * Section A.48:: `FISUB': Floating-Point/Integer Subtraction
  4261. * Section A.49:: `FLD': Floating-Point Load
  4262. * Section A.50:: `FLDxx': Floating-Point Load Constants
  4263. * Section A.51:: `FLDCW': Load Floating-Point Control Word
  4264. * Section A.52:: `FLDENV': Load Floating-Point Environment
  4265. * Section A.53:: `FMUL', `FMULP': Floating-Point Multiply
  4266. * Section A.54:: `FNOP': Floating-Point No Operation
  4267. * Section A.55:: `FPATAN', `FPTAN': Arctangent and Tangent
  4268. * Section A.56:: `FPREM', `FPREM1': Floating-Point Partial Remainder
  4269. * Section A.57:: `FRNDINT': Floating-Point Round to Integer
  4270. * Section A.58:: `FSAVE', `FRSTOR': Save/Restore Floating-Point State
  4271. * Section A.59:: `FSCALE': Scale Floating-Point Value by Power of Two
  4272. * Section A.60:: `FSETPM': Set Protected Mode
  4273. * Section A.61:: `FSIN', `FSINCOS': Sine and Cosine
  4274. * Section A.62:: `FSQRT': Floating-Point Square Root
  4275. * Section A.63:: `FST', `FSTP': Floating-Point Store
  4276. * Section A.64:: `FSTCW': Store Floating-Point Control Word
  4277. * Section A.65:: `FSTENV': Store Floating-Point Environment
  4278. * Section A.66:: `FSTSW': Store Floating-Point Status Word
  4279. * Section A.67:: `FSUB', `FSUBP', `FSUBR', `FSUBRP': Floating-Point Subtract
  4280. * Section A.68:: `FTST': Test `ST0' Against Zero
  4281. * Section A.69:: `FUCOMxx': Floating-Point Unordered Compare
  4282. * Section A.70:: `FXAM': Examine Class of Value in `ST0'
  4283. * Section A.71:: `FXCH': Floating-Point Exchange
  4284. * Section A.72:: `FXTRACT': Extract Exponent and Significand
  4285. * Section A.73:: `FYL2X', `FYL2XP1': Compute Y times Log2(X) or Log2(X+1)
  4286. * Section A.74:: `HLT': Halt Processor
  4287. * Section A.75:: `IBTS': Insert Bit String
  4288. * Section A.76:: `IDIV': Signed Integer Divide
  4289. * Section A.77:: `IMUL': Signed Integer Multiply
  4290. * Section A.78:: `IN': Input from I/O Port
  4291. * Section A.79:: `INC': Increment Integer
  4292. * Section A.80:: `INSB', `INSW', `INSD': Input String from I/O Port
  4293. * Section A.81:: `INT': Software Interrupt
  4294. * Section A.82:: `INT3', `INT1', `ICEBP', `INT01': Breakpoints
  4295. * Section A.83:: `INTO': Interrupt if Overflow
  4296. * Section A.84:: `INVD': Invalidate Internal Caches
  4297. * Section A.85:: `INVLPG': Invalidate TLB Entry
  4298. * Section A.86:: `IRET', `IRETW', `IRETD': Return from Interrupt
  4299. * Section A.87:: `JCXZ', `JECXZ': Jump if CX/ECX Zero
  4300. * Section A.88:: `JMP': Jump
  4301. * Section A.89:: `Jcc': Conditional Branch
  4302. * Section A.90:: `LAHF': Load AH from Flags
  4303. * Section A.91:: `LAR': Load Access Rights
  4304. * Section A.92:: `LDS', `LES', `LFS', `LGS', `LSS': Load Far Pointer
  4305. * Section A.93:: `LEA': Load Effective Address
  4306. * Section A.94:: `LEAVE': Destroy Stack Frame
  4307. * Section A.95:: `LGDT', `LIDT', `LLDT': Load Descriptor Tables
  4308. * Section A.96:: `LMSW': Load/Store Machine Status Word
  4309. * Section A.97:: `LOADALL', `LOADALL286': Load Processor State
  4310. * Section A.98:: `LODSB', `LODSW', `LODSD': Load from String
  4311. * Section A.99:: `LOOP', `LOOPE', `LOOPZ', `LOOPNE', `LOOPNZ': Loop with Counter
  4312. * Section A.100:: `LSL': Load Segment Limit
  4313. * Section A.101:: `LTR': Load Task Register
  4314. * Section A.102:: `MOV': Move Data
  4315. * Section A.103:: `MOVD': Move Doubleword to/from MMX Register
  4316. * Section A.104:: `MOVQ': Move Quadword to/from MMX Register
  4317. * Section A.105:: `MOVSB', `MOVSW', `MOVSD': Move String
  4318. * Section A.106:: `MOVSX', `MOVZX': Move Data with Sign or Zero Extend
  4319. * Section A.107:: `MUL': Unsigned Integer Multiply
  4320. * Section A.108:: `NEG', `NOT': Two's and One's Complement
  4321. * Section A.109:: `NOP': No Operation
  4322. * Section A.110:: `OR': Bitwise OR
  4323. * Section A.111:: `OUT': Output Data to I/O Port
  4324. * Section A.112:: `OUTSB', `OUTSW', `OUTSD': Output String to I/O Port
  4325. * Section A.113:: `PACKSSDW', `PACKSSWB', `PACKUSWB': Pack Data
  4326. * Section A.114:: `PADDxx': MMX Packed Addition
  4327. * Section A.115:: `PADDSIW': MMX Packed Addition to Implicit Destination
  4328. * Section A.116:: `PAND', `PANDN': MMX Bitwise AND and AND-NOT
  4329. * Section A.117:: `PAVEB': MMX Packed Average
  4330. * Section A.118:: `PCMPxx': MMX Packed Comparison
  4331. * Section A.119:: `PDISTIB': MMX Packed Distance and Accumulate with Implied Register
  4332. * Section A.120:: `PMACHRIW': MMX Packed Multiply and Accumulate with Rounding
  4333. * Section A.121:: `PMADDWD': MMX Packed Multiply and Add
  4334. * Section A.122:: `PMAGW': MMX Packed Magnitude
  4335. * Section A.123:: `PMULHRW', `PMULHRIW': MMX Packed Multiply High with Rounding
  4336. * Section A.124:: `PMULHW', `PMULLW': MMX Packed Multiply
  4337. * Section A.125:: `PMVccZB': MMX Packed Conditional Move
  4338. * Section A.126:: `POP': Pop Data from Stack
  4339. * Section A.127:: `POPAx': Pop All General-Purpose Registers
  4340. * Section A.128:: `POPFx': Pop Flags Register
  4341. * Section A.129:: `POR': MMX Bitwise OR
  4342. * Section A.130:: `PSLLx', `PSRLx', `PSRAx': MMX Bit Shifts
  4343. * Section A.131:: `PSUBxx': MMX Packed Subtraction
  4344. * Section A.132:: `PSUBSIW': MMX Packed Subtract with Saturation to Implied Destination
  4345. * Section A.133:: `PUNPCKxxx': Unpack Data
  4346. * Section A.134:: `PUSH': Push Data on Stack
  4347. * Section A.135:: `PUSHAx': Push All General-Purpose Registers
  4348. * Section A.136:: `PUSHFx': Push Flags Register
  4349. * Section A.137:: `PXOR': MMX Bitwise XOR
  4350. * Section A.138:: `RCL', `RCR': Bitwise Rotate through Carry Bit
  4351. * Section A.139:: `RDMSR': Read Model-Specific Registers
  4352. * Section A.140:: `RDPMC': Read Performance-Monitoring Counters
  4353. * Section A.141:: `RDTSC': Read Time-Stamp Counter
  4354. * Section A.142:: `RET', `RETF', `RETN': Return from Procedure Call
  4355. * Section A.143:: `ROL', `ROR': Bitwise Rotate
  4356. * Section A.144:: `RSM': Resume from System-Management Mode
  4357. * Section A.145:: `SAHF': Store AH to Flags
  4358. * Section A.146:: `SAL', `SAR': Bitwise Arithmetic Shifts
  4359. * Section A.147:: `SALC': Set AL from Carry Flag
  4360. * Section A.148:: `SBB': Subtract with Borrow
  4361. * Section A.149:: `SCASB', `SCASW', `SCASD': Scan String
  4362. * Section A.150:: `SETcc': Set Register from Condition
  4363. * Section A.151:: `SGDT', `SIDT', `SLDT': Store Descriptor Table Pointers
  4364. * Section A.152:: `SHL', `SHR': Bitwise Logical Shifts
  4365. * Section A.153:: `SHLD', `SHRD': Bitwise Double-Precision Shifts
  4366. * Section A.154:: `SMI': System Management Interrupt
  4367. * Section A.155:: `SMSW': Store Machine Status Word
  4368. * Section A.156:: `STC', `STD', `STI': Set Flags
  4369. * Section A.157:: `STOSB', `STOSW', `STOSD': Store Byte to String
  4370. * Section A.158:: `STR': Store Task Register
  4371. * Section A.159:: `SUB': Subtract Integers
  4372. * Section A.160:: `TEST': Test Bits (notional bitwise AND)
  4373. * Section A.161:: `UMOV': User Move Data
  4374. * Section A.162:: `VERR', `VERW': Verify Segment Readability/Writability
  4375. * Section A.163:: `WAIT': Wait for Floating-Point Processor
  4376. * Section A.164:: `WBINVD': Write Back and Invalidate Cache
  4377. * Section A.165:: `WRMSR': Write Model-Specific Registers
  4378. * Section A.166:: `XADD': Exchange and Add
  4379. * Section A.167:: `XBTS': Extract Bit String
  4380. * Section A.168:: `XCHG': Exchange
  4381. * Section A.169:: `XLATB': Translate Byte in Lookup Table
  4382. * Section A.170:: `XOR': Bitwise Exclusive OR
  4383. File: nasm.info,  Node: Section A.1,  Next: Section A.2,  Prev: Appendix A,  Up: Appendix A
  4384. A.1. Key to Operand Specifications
  4385. **********************************
  4386.    The instruction descriptions in this appendix specify their operands
  4387. using the following notation:
  4388.    * Registers: `reg8' denotes an 8-bit general purpose register,
  4389.      `reg16' denotes a 16-bit general purpose register, and `reg32' a
  4390.      32-bit one. `fpureg' denotes one of the eight FPU stack registers,
  4391.      `mmxreg' denotes one of the eight 64-bit MMX registers, and
  4392.      `segreg' denotes a segment register. In addition, some registers
  4393.      (such as `AL', `DX' or `ECX') may be specified explicitly.
  4394.    * Immediate operands: `imm' denotes a generic immediate operand.
  4395.      `imm8', `imm16' and `imm32' are used when the operand is intended
  4396.      to be a specific size. For some of these instructions, NASM needs
  4397.      an explicit specifier: for example, `ADD ESP,16' could be
  4398.      interpreted as either `ADD r/m32,imm32' or `ADD r/m32,imm8'. NASM
  4399.      chooses the former by default, and so you must specify `ADD
  4400.      ESP,BYTE 16' for the latter.
  4401.    * Memory references: `mem' denotes a generic memory reference;
  4402.      `mem8', `mem16', `mem32', `mem64' and `mem80' are used when the
  4403.      operand needs to be a specific size. Again, a specifier is needed
  4404.      in some cases: `DEC [address]' is ambiguous and will be rejected
  4405.      by NASM. You must specify `DEC BYTE [address]', `DEC WORD
  4406.      [address]' or `DEC DWORD [address]' instead.
  4407.    * Restricted memory references: one form of the `MOV' instruction
  4408.      allows a memory address to be specified *without* allowing the
  4409.      normal range of register combinations and effective address
  4410.      processing. This is denoted by `memoffs8', `memoffs16' and
  4411.      `memoffs32'.
  4412.    * Register or memory choices: many instructions can accept either a
  4413.      register *or* a memory reference as an operand. `r/m8' is a
  4414.      shorthand for `reg8/mem8'; similarly `r/m16' and `r/m32'. `r/m64'
  4415.      is MMX-related, and is a shorthand for `mmxreg/mem64'.
  4416. File: nasm.info,  Node: Section A.2,  Next: Section A.2.1,  Prev: Section A.1,  Up: Appendix A
  4417. A.2. Key to Opcode Descriptions
  4418. *******************************
  4419.    This appendix also provides the opcodes which NASM will generate for
  4420. each form of each instruction. The opcodes are listed in the following
  4421.    * A hex number, such as `3F', indicates a fixed byte containing that
  4422.      number.
  4423.    * A hex number followed by `+r', such as `C8+r', indicates that one
  4424.      of the operands to the instruction is a register, and the
  4425.      `register value' of that register should be added to the hex
  4426.      number to produce the generated byte. For example, EDX has
  4427.      register value 2, so the code `C8+r', when the register operand is
  4428.      EDX, generates the hex byte `CA'. Register values for specific
  4429.      registers are given in *Note Section A.2.1::.
  4430.    * A hex number followed by `+cc', such as `40+cc', indicates that
  4431.      the instruction name has a condition code suffix, and the numeric
  4432.      representation of the condition code should be added to the hex
  4433.      number to produce the generated byte. For example, the code
  4434.      `40+cc', when the instruction contains the `NE' condition,
  4435.      generates the hex byte `45'. Condition codes and their numeric
  4436.      representations are given in *Note Section A.2.2::.
  4437.    * A slash followed by a digit, such as `/2', indicates that one of
  4438.      the operands to the instruction is a memory address or register
  4439.      (denoted `mem' or `r/m', with an optional size). This is to be
  4440.      encoded as an effective address, with a ModR/M byte, an optional
  4441.      SIB byte, and an optional displacement, and the spare (register)
  4442.      field of the ModR/M byte should be the digit given (which will be
  4443.      from 0 to 7, so it fits in three bits). The encoding of effective
  4444.      addresses is given in *Note Section A.2.3::.
  4445.    * The code `/r' combines the above two: it indicates that one of the
  4446.      operands is a memory address or `r/m', and another is a register,
  4447.      and that an effective address should be generated with the spare
  4448.      (register) field in the ModR/M byte being equal to the `register
  4449.      value' of the register operand. The encoding of effective
  4450.      addresses is given in *Note Section A.2.3::; register values are
  4451.      given in *Note Section A.2.1::.
  4452.    * The codes `ib', `iw' and `id' indicate that one of the operands to
  4453.      the instruction is an immediate value, and that this is to be
  4454.      encoded as a byte, little-endian word or little-endian doubleword
  4455.      respectively.
  4456.    * The codes `rb', `rw' and `rd' indicate that one of the operands to
  4457.      the instruction is an immediate value, and that the *difference*
  4458.      between this value and the address of the end of the instruction
  4459.      is to be encoded as a byte, word or doubleword respectively.
  4460.      Where the form `rw/rd' appears, it indicates that either `rw' or
  4461.      `rd' should be used according to whether assembly is being
  4462.      performed in `BITS 16' or `BITS 32' state respectively.
  4463.    * The codes `ow' and `od' indicate that one of the operands to the
  4464.      instruction is a reference to the contents of a memory address
  4465.      specified as an immediate value: this encoding is used in some
  4466.      forms of the `MOV' instruction in place of the standard
  4467.      effective-address mechanism. The displacement is encoded as a word
  4468.      or doubleword. Again, `ow/od' denotes that `ow' or `od' should be
  4469.      chosen according to the `BITS' setting.
  4470.    * The codes `o16' and `o32' indicate that the given form of the
  4471.      instruction should be assembled with operand size 16 or 32 bits.
  4472.      In other words, `o16' indicates a `66' prefix in `BITS 32' state,
  4473.      but generates no code in `BITS 16' state; and `o32' indicates a
  4474.      `66' prefix in `BITS 16' state but generates nothing in `BITS 32'.
  4475.    * The codes `a16' and `a32', similarly to `o16' and `o32', indicate
  4476.      the address size of the given form of the instruction.  Where this
  4477.      does not match the `BITS' setting, a `67' prefix is required.
  4478. * Menu:
  4479. * Section A.2.1:: Register Values
  4480. * Section A.2.2:: Condition Codes
  4481. * Section A.2.3:: Effective Address Encoding: ModR/M and SIB
  4482. File: nasm.info,  Node: Section A.2.1,  Next: Section A.2.2,  Prev: Section A.2,  Up: Section A.2
  4483. A.2.1. Register Values
  4484. **********************
  4485.    Where an instruction requires a register value, it is already
  4486. implicit in the encoding of the rest of the instruction what type of
  4487. register is intended: an 8-bit general-purpose register, a segment
  4488. register, a debug register, an MMX register, or whatever. Therefore
  4489. there is no problem with registers of different types sharing an
  4490. encoding value.
  4491.    The encodings for the various classes of register are:
  4492.    * 8-bit general registers: `AL' is 0, `CL' is 1, `DL' is 2, `BL' is
  4493.      3, `AH' is 4, `CH' is 5, `DH' is 6, and `BH' is 7.
  4494.    * 16-bit general registers: `AX' is 0, `CX' is 1, `DX' is 2, `BX' is
  4495.      3, `SP' is 4, `BP' is 5, `SI' is 6, and `DI' is 7.
  4496.    * 32-bit general registers: `EAX' is 0, `ECX' is 1, `EDX' is 2,
  4497.      `EBX' is 3, `ESP' is 4, `EBP' is 5, `ESI' is 6, and `EDI' is 7.
  4498.    * Segment registers: `ES' is 0, `CS' is 1, `SS' is 2, `DS' is 3,
  4499.      `FS' is 4, and `GS' is 5.
  4500.    * {Floating-point registers}: `ST0' is 0, `ST1' is 1, `ST2' is 2,
  4501.      `ST3' is 3, `ST4' is 4, `ST5' is 5, `ST6' is 6, and `ST7' is 7.
  4502.    * 64-bit MMX registers: `MM0' is 0, `MM1' is 1, `MM2' is 2, `MM3' is
  4503.      3, `MM4' is 4, `MM5' is 5, `MM6' is 6, and `MM7' is 7.
  4504.    * Control registers: `CR0' is 0, `CR2' is 2, `CR3' is 3, and `CR4'
  4505.      is 4.
  4506.    * Debug registers: `DR0' is 0, `DR1' is 1, `DR2' is 2, `DR3' is 3,
  4507.      `DR6' is 6, and `DR7' is 7.
  4508.    * Test registers: `TR3' is 3, `TR4' is 4, `TR5' is 5, `TR6' is 6,
  4509.      and `TR7' is 7.
  4510.    (Note that wherever a register name contains a number, that number
  4511. is also the register value for that register.)
  4512. File: nasm.info,  Node: Section A.2.2,  Next: Section A.2.3,  Prev: Section A.2.1,  Up: Section A.2
  4513. A.2.2. Condition Codes
  4514. **********************
  4515.    The available condition codes are given here, along with their
  4516. numeric representations as part of opcodes. Many of these condition
  4517. codes have synonyms, so several will be listed at a time.
  4518.    In the following descriptions, the word `either', when applied to two
  4519. possible trigger conditions, is used to mean `either or both'. If
  4520. `either but not both' is meant, the phrase `exactly one of' is used.
  4521.    * `O' is 0 (trigger if the overflow flag is set); `NO' is 1.
  4522.    * `B', `C' and `NAE' are 2 (trigger if the carry flag is set); `AE',
  4523.      `NB' and `NC' are 3.
  4524.    * `E' and `Z' are 4 (trigger if the zero flag is set); `NE' and `NZ'
  4525.      are 5.
  4526.    * `BE' and `NA' are 6 (trigger if either of the carry or zero flags
  4527.      is set); `A' and `NBE' are 7.
  4528.    * `S' is 8 (trigger if the sign flag is set); `NS' is 9.
  4529.    * `P' and `PE' are 10 (trigger if the parity flag is set); `NP' and
  4530.      `PO' are 11.
  4531.    * `L' and `NGE' are 12 (trigger if exactly one of the sign and
  4532.      overflow flags is set); `GE' and `NL' are 13.
  4533.    * `LE' and `NG' are 14 (trigger if either the zero flag is set, or
  4534.      exactly one of the sign and overflow flags is set); `G' and `NLE'
  4535.      are 15.
  4536.    Note that in all cases, the sense of a condition code may be
  4537. reversed by changing the low bit of the numeric representation.
  4538. File: nasm.info,  Node: Section A.2.3,  Next: Section A.3,  Prev: Section A.2.2,  Up: Section A.2
  4539. A.2.3. Effective Address Encoding: ModR/M and SIB
  4540. *************************************************
  4541.    An effective address is encoded in up to three parts: a ModR/M byte,
  4542. an optional SIB byte, and an optional byte, word or doubleword
  4543. displacement field.
  4544.    The ModR/M byte consists of three fields: the `mod' field, ranging
  4545. from 0 to 3, in the upper two bits of the byte, the `r/m' field,
  4546. ranging from 0 to 7, in the lower three bits, and the spare (register)
  4547. field in the middle (bit 3 to bit 5). The spare field is not relevant to
  4548. the effective address being encoded, and either contains an extension to
  4549. the instruction opcode or the register value of another operand.
  4550.    The ModR/M system can be used to encode a direct register reference
  4551. rather than a memory access. This is always done by setting the `mod'
  4552. field to 3 and the `r/m' field to the register value of the register in
  4553. question (it must be a general-purpose register, and the size of the
  4554. register must already be implicit in the encoding of the rest of the
  4555. instruction). In this case, the SIB byte and displacement field are both
  4556. absent.
  4557.    In 16-bit addressing mode (either `BITS 16' with no `67' prefix, or
  4558. `BITS 32' with a `67' prefix), the SIB byte is never used. The general
  4559. rules for `mod' and `r/m' (there is an exception, given below) are:
  4560.    * The `mod' field gives the length of the displacement field: 0
  4561.      means no displacement, 1 means one byte, and 2 means two bytes.
  4562.    * The `r/m' field encodes the combination of registers to be added to
  4563.      the displacement to give the accessed address: 0 means `BX+SI', 1
  4564.      means `BX+DI', 2 means `BP+SI', 3 means `BP+DI', 4 means `SI'
  4565.      only, 5 means `DI' only, 6 means `BP' only, and 7 means `BX' only.
  4566.    However, there is a special case:
  4567.    * If `mod' is 0 and `r/m' is 6, the effective address encoded is not
  4568.      `[BP]' as the above rules would suggest, but instead `[disp16]':
  4569.      the displacement field is present and is two bytes long, and no
  4570.      registers are added to the displacement.
  4571.    Therefore the effective address `[BP]' cannot be encoded as
  4572. efficiently as `[BX]'; so if you code `[BP]' in a program, NASM adds a
  4573. notional 8-bit zero displacement, and sets `mod' to 1, `r/m' to 6, and
  4574. the one-byte displacement field to 0.
  4575.    In 32-bit addressing mode (either `BITS 16' with a `67' prefix, or
  4576. `BITS 32' with no `67' prefix) the general rules (again, there are
  4577. exceptions) for `mod' and `r/m' are:
  4578.    * The `mod' field gives the length of the displacement field: 0
  4579.      means no displacement, 1 means one byte, and 2 means four bytes.
  4580.    * If only one register is to be added to the displacement, and it is
  4581.      not `ESP', the `r/m' field gives its register value, and the SIB
  4582.      byte is absent. If the `r/m' field is 4 (which would encode `ESP'),
  4583.      the SIB byte is present and gives the combination and scaling of
  4584.      registers to be added to the displacement.
  4585.    If the SIB byte is present, it describes the combination of
  4586. registers (an optional base register, and an optional index register
  4587. scaled by multiplication by 1, 2, 4 or 8) to be added to the
  4588. displacement. The SIB byte is divided into the `scale' field, in the
  4589. top two bits, the `index' field in the next three, and the `base' field
  4590. in the bottom three. The general rules are:
  4591.    * The `base' field encodes the register value of the base register.
  4592.    * The `index' field encodes the register value of the index register,
  4593.      unless it is 4, in which case no index register is used (so `ESP'
  4594.      cannot be used as an index register).
  4595.    * The `scale' field encodes the multiplier by which the index
  4596.      register is scaled before adding it to the base and displacement:
  4597.      0 encodes a multiplier of 1, 1 encodes 2, 2 encodes 4 and 3
  4598.      encodes 8.
  4599.    The exceptions to the 32-bit encoding rules are:
  4600.    * If `mod' is 0 and `r/m' is 5, the effective address encoded is not
  4601.      `[EBP]' as the above rules would suggest, but instead `[disp32]':
  4602.      the displacement field is present and is four bytes long, and no
  4603.      registers are added to the displacement.
  4604.    * If `mod' is 0, `r/m' is 4 (meaning the SIB byte is present) and
  4605.      `base' is 4, the effective address encoded is not `[EBP+index]' as
  4606.      the above rules would suggest, but instead `[disp32+index]': the
  4607.      displacement field is present and is four bytes long, and there is
  4608.      no base register (but the index register is still processed in the
  4609.      normal way).
  4610. File: nasm.info,  Node: Section A.3,  Next: Section A.4,  Prev: Section A.2.3,  Up: Appendix A
  4611. A.3. Key to Instruction Flags
  4612. *****************************
  4613.    Given along with each instruction in this appendix is a set of flags,
  4614. denoting the type of the instruction. The types are as follows:
  4615.    * `8086', `186', `286', `386', `486', `PENT' and `P6' denote the
  4616.      lowest processor type that supports the instruction. Most
  4617.      instructions run on all processors above the given type; those
  4618.      that do not are documented. The Pentium II contains no additional
  4619.      instructions beyond the P6 (Pentium Pro); from the point of view
  4620.      of its instruction set, it can be thought of as a P6 with MMX
  4621.      capability.
  4622.    * `CYRIX' indicates that the instruction is specific to Cyrix
  4623.      processors, for example the extra MMX instructions in the Cyrix
  4624.      extended MMX instruction set.
  4625.    * `FPU' indicates that the instruction is a floating-point one, and
  4626.      will only run on machines with a coprocessor (automatically
  4627.      including 486DX, Pentium and above).
  4628.    * `MMX' indicates that the instruction is an MMX one, and will run on
  4629.      MMX-capable Pentium processors and the Pentium II.
  4630.    * `PRIV' indicates that the instruction is a protected-mode
  4631.      management instruction. Many of these may only be used in
  4632.      protected mode, or only at privilege level zero.
  4633.    * `UNDOC' indicates that the instruction is an undocumented one, and
  4634.      not part of the official Intel Architecture; it may or may not be
  4635.      supported on any given machine.
  4636. File: nasm.info,  Node: Section A.4,  Next: Section A.5,  Prev: Section A.3,  Up: Appendix A
  4637. A.4. `AAA', `AAS', `AAM', `AAD': ASCII Adjustments
  4638. **************************************************
  4639.      AAA                           ; 37                   [8086]
  4640.      AAS                           ; 3F                   [8086]
  4641.      AAD                           ; D5 0A                [8086]
  4642.      AAD imm                       ; D5 ib                [8086]
  4643.      AAM                           ; D4 0A                [8086]
  4644.      AAM imm                       ; D4 ib                [8086]
  4645.    These instructions are used in conjunction with the add, subtract,
  4646. multiply and divide instructions to perform binary-coded decimal
  4647. arithmetic in *unpacked* (one BCD digit per byte - easy to translate to
  4648. and from ASCII, hence the instruction names) form. There are also
  4649. packed BCD instructions `DAA' and `DAS': see *Note Section A.23::.
  4650.    `AAA' should be used after a one-byte `ADD' instruction whose
  4651. destination was the `AL' register: by means of examining the value in
  4652. the low nibble of `AL' and also the auxiliary carry flag `AF', it
  4653. determines whether the addition has overflowed, and adjusts it (and sets
  4654. the carry flag) if so. You can add long BCD strings together by doing
  4655. `ADD'/`AAA' on the low digits, then doing `ADC'/`AAA' on each
  4656. subsequent digit.
  4657.    `AAS' works similarly to `AAA', but is for use after `SUB'
  4658. instructions rather than `ADD'.
  4659.    `AAM' is for use after you have multiplied two decimal digits
  4660. together and left the result in `AL': it divides `AL' by ten and stores
  4661. the quotient in `AH', leaving the remainder in `AL'. The divisor 10 can
  4662. be changed by specifying an operand to the instruction: a particularly
  4663. handy use of this is `AAM 16', causing the two nibbles in `AL' to be
  4664. separated into `AH' and `AL'.
  4665.    `AAD' performs the inverse operation to `AAM': it multiplies `AH' by
  4666. ten, adds it to `AL', and sets `AH' to zero. Again, the multiplier 10
  4667. can be changed.
  4668. File: nasm.info,  Node: Section A.5,  Next: Section A.6,  Prev: Section A.4,  Up: Appendix A
  4669. A.5. `ADC': Add with Carry
  4670. **************************
  4671.      ADC r/m8,reg8                 ; 10 /r                [8086]
  4672.      ADC r/m16,reg16               ; o16 11 /r            [8086]
  4673.      ADC r/m32,reg32               ; o32 11 /r            [386]
  4674.      ADC reg8,r/m8                 ; 12 /r                [8086]
  4675.      ADC reg16,r/m16               ; o16 13 /r            [8086]
  4676.      ADC reg32,r/m32               ; o32 13 /r            [386]
  4677.      ADC r/m8,imm8                 ; 80 /2 ib             [8086]
  4678.      ADC r/m16,imm16               ; o16 81 /2 iw         [8086]
  4679.      ADC r/m32,imm32               ; o32 81 /2 id         [386]
  4680.      ADC r/m16,imm8                ; o16 83 /2 ib         [8086]
  4681.      ADC r/m32,imm8                ; o32 83 /2 ib         [386]
  4682.      ADC AL,imm8                   ; 14 ib                [8086]
  4683.      ADC AX,imm16                  ; o16 15 iw            [8086]
  4684.      ADC EAX,imm32                 ; o32 15 id            [386]
  4685.    `ADC' performs integer addition: it adds its two operands together,
  4686. plus the value of the carry flag, and leaves the result in its
  4687. destination (first) operand. The flags are set according to the result
  4688. of the operation: in particular, the carry flag is affected and can be
  4689. used by a subsequent `ADC' instruction.
  4690.    In the forms with an 8-bit immediate second operand and a longer
  4691. first operand, the second operand is considered to be signed, and is
  4692. sign- extended to the length of the first operand. In these cases, the
  4693. `BYTE' qualifier is necessary to force NASM to generate this form of
  4694. the instruction.
  4695.    To add two numbers without also adding the contents of the carry
  4696. flag, use `ADD' (*Note Section A.6::).
  4697. File: nasm.info,  Node: Section A.6,  Next: Section A.7,  Prev: Section A.5,  Up: Appendix A
  4698. A.6. `ADD': Add Integers
  4699. ************************
  4700.      ADD r/m8,reg8                 ; 00 /r                [8086]
  4701.      ADD r/m16,reg16               ; o16 01 /r            [8086]
  4702.      ADD r/m32,reg32               ; o32 01 /r            [386]
  4703.      ADD reg8,r/m8                 ; 02 /r                [8086]
  4704.      ADD reg16,r/m16               ; o16 03 /r            [8086]
  4705.      ADD reg32,r/m32               ; o32 03 /r            [386]
  4706.      ADD r/m8,imm8                 ; 80 /0 ib             [8086]
  4707.      ADD r/m16,imm16               ; o16 81 /0 iw         [8086]
  4708.      ADD r/m32,imm32               ; o32 81 /0 id         [386]
  4709.      ADD r/m16,imm8                ; o16 83 /0 ib         [8086]
  4710.      ADD r/m32,imm8                ; o32 83 /0 ib         [386]
  4711.      ADD AL,imm8                   ; 04 ib                [8086]
  4712.      ADD AX,imm16                  ; o16 05 iw            [8086]
  4713.      ADD EAX,imm32                 ; o32 05 id            [386]
  4714.    `ADD' performs integer addition: it adds its two operands together,
  4715. and leaves the result in its destination (first) operand. The flags are
  4716. set according to the result of the operation: in particular, the carry
  4717. flag is affected and can be used by a subsequent `ADC' instruction
  4718. (*Note Section A.5::).
  4719.    In the forms with an 8-bit immediate second operand and a longer
  4720. first operand, the second operand is considered to be signed, and is
  4721. sign- extended to the length of the first operand. In these cases, the
  4722. `BYTE' qualifier is necessary to force NASM to generate this form of
  4723. the instruction.
  4724. File: nasm.info,  Node: Section A.7,  Next: Section A.8,  Prev: Section A.6,  Up: Appendix A
  4725. A.7. `AND': Bitwise AND
  4726. ***********************
  4727.      AND r/m8,reg8                 ; 20 /r                [8086]
  4728.      AND r/m16,reg16               ; o16 21 /r            [8086]
  4729.      AND r/m32,reg32               ; o32 21 /r            [386]
  4730.      AND reg8,r/m8                 ; 22 /r                [8086]
  4731.      AND reg16,r/m16               ; o16 23 /r            [8086]
  4732.      AND reg32,r/m32               ; o32 23 /r            [386]
  4733.      AND r/m8,imm8                 ; 80 /4 ib             [8086]
  4734.      AND r/m16,imm16               ; o16 81 /4 iw         [8086]
  4735.      AND r/m32,imm32               ; o32 81 /4 id         [386]
  4736.      AND r/m16,imm8                ; o16 83 /4 ib         [8086]
  4737.      AND r/m32,imm8                ; o32 83 /4 ib         [386]
  4738.      AND AL,imm8                   ; 24 ib                [8086]
  4739.      AND AX,imm16                  ; o16 25 iw            [8086]
  4740.      AND EAX,imm32                 ; o32 25 id            [386]
  4741.    `AND' performs a bitwise AND operation between its two operands (i.e.
  4742. each bit of the result is 1 if and only if the corresponding bits of the
  4743. two inputs were both 1), and stores the result in the destination
  4744. (first) operand.
  4745.    In the forms with an 8-bit immediate second operand and a longer
  4746. first operand, the second operand is considered to be signed, and is
  4747. sign- extended to the length of the first operand. In these cases, the
  4748. `BYTE' qualifier is necessary to force NASM to generate this form of
  4749. the instruction.
  4750.    The MMX instruction `PAND' (see *Note Section A.116::) performs the
  4751. same operation on the 64-bit MMX registers.
  4752. File: nasm.info,  Node: Section A.8,  Next: Section A.9,  Prev: Section A.7,  Up: Appendix A
  4753. A.8. `ARPL': Adjust RPL Field of Selector
  4754. *****************************************
  4755.      ARPL r/m16,reg16              ; 63 /r                [286,PRIV]
  4756.    `ARPL' expects its two word operands to be segment selectors. It
  4757. adjusts the RPL (requested privilege level - stored in the bottom two
  4758. bits of the selector) field of the destination (first) operand to
  4759. ensure that it is no less (i.e. no more privileged than) the RPL field
  4760. of the source operand. The zero flag is set if and only if a change had
  4761. to be made.
  4762. File: nasm.info,  Node: Section A.9,  Next: Section A.10,  Prev: Section A.8,  Up: Appendix A
  4763. A.9. `BOUND': Check Array Index against Bounds
  4764. **********************************************
  4765.      BOUND reg16,mem               ; o16 62 /r            [186]
  4766.      BOUND reg32,mem               ; o32 62 /r            [386]
  4767.    `BOUND' expects its second operand to point to an area of memory
  4768. containing two signed values of the same size as its first operand (i.e.
  4769. two words for the 16-bit form; two doublewords for the 32-bit form). It
  4770. performs two signed comparisons: if the value in the register passed as
  4771. its first operand is less than the first of the in-memory values, or is
  4772. greater than or equal to the second, it throws a BR exception.
  4773. Otherwise, it does nothing.
  4774. File: nasm.info,  Node: Section A.10,  Next: Section A.11,  Prev: Section A.9,  Up: Appendix A
  4775. A.10. `BSF', `BSR': Bit Scan
  4776. ****************************
  4777.      BSF reg16,r/m16               ; o16 0F BC /r         [386]
  4778.      BSF reg32,r/m32               ; o32 0F BC /r         [386]
  4779.      BSR reg16,r/m16               ; o16 0F BD /r         [386]
  4780.      BSR reg32,r/m32               ; o32 0F BD /r         [386]
  4781.    `BSF' searches for a set bit in its source (second) operand, starting
  4782. from the bottom, and if it finds one, stores the index in its
  4783. destination (first) operand. If no set bit is found, the contents of
  4784. the destination operand are undefined.
  4785.    `BSR' performs the same function, but searches from the top instead,
  4786. so it finds the most significant set bit.
  4787.    Bit indices are from 0 (least significant) to 15 or 31 (most
  4788. significant).
  4789. File: nasm.info,  Node: Section A.11,  Next: Section A.12,  Prev: Section A.10,  Up: Appendix A
  4790. A.11. `BSWAP': Byte Swap
  4791. ************************
  4792.      BSWAP reg32                   ; o32 0F C8+r          [486]
  4793.    `BSWAP' swaps the order of the four bytes of a 32-bit register: bits
  4794. 0-7 exchange places with bits 24-31, and bits 8-15 swap with bits 16-23.
  4795. There is no explicit 16-bit equivalent: to byte-swap `AX', `BX', `CX'
  4796. or `DX', `XCHG' can be used.
  4797. File: nasm.info,  Node: Section A.12,  Next: Section A.13,  Prev: Section A.11,  Up: Appendix A
  4798. A.12. `BT', `BTC', `BTR', `BTS': Bit Test
  4799. *****************************************
  4800.      BT r/m16,reg16                ; o16 0F A3 /r         [386]
  4801.      BT r/m32,reg32                ; o32 0F A3 /r         [386]
  4802.      BT r/m16,imm8                 ; o16 0F BA /4 ib      [386]
  4803.      BT r/m32,imm8                 ; o32 0F BA /4 ib      [386]
  4804.      BTC r/m16,reg16               ; o16 0F BB /r         [386]
  4805.      BTC r/m32,reg32               ; o32 0F BB /r         [386]
  4806.      BTC r/m16,imm8                ; o16 0F BA /7 ib      [386]
  4807.      BTC r/m32,imm8                ; o32 0F BA /7 ib      [386]
  4808.      BTR r/m16,reg16               ; o16 0F B3 /r         [386]
  4809.      BTR r/m32,reg32               ; o32 0F B3 /r         [386]
  4810.      BTR r/m16,imm8                ; o16 0F BA /6 ib      [386]
  4811.      BTR r/m32,imm8                ; o32 0F BA /6 ib      [386]
  4812.      BTS r/m16,reg16               ; o16 0F AB /r         [386]
  4813.      BTS r/m32,reg32               ; o32 0F AB /r         [386]
  4814.      BTS r/m16,imm                 ; o16 0F BA /5 ib      [386]
  4815.      BTS r/m32,imm                 ; o32 0F BA /5 ib      [386]
  4816.    These instructions all test one bit of their first operand, whose
  4817. index is given by the second operand, and store the value of that bit
  4818. into the carry flag. Bit indices are from 0 (least significant) to 15
  4819. or 31 (most significant).
  4820.    In addition to storing the original value of the bit into the carry
  4821. flag, `BTR' also resets (clears) the bit in the operand itself. `BTS'
  4822. sets the bit, and `BTC' complements the bit. `BT' does not modify its
  4823. operands.
  4824.    The bit offset should be no greater than the size of the operand.
  4825. File: nasm.info,  Node: Section A.13,  Next: Section A.14,  Prev: Section A.12,  Up: Appendix A
  4826. A.13. `CALL': Call Subroutine
  4827. *****************************
  4828.      CALL imm                      ; E8 rw/rd             [8086]
  4829.      CALL imm:imm16                ; o16 9A iw iw         [8086]
  4830.      CALL imm:imm32                ; o32 9A id iw         [386]
  4831.      CALL FAR mem16                ; o16 FF /3            [8086]
  4832.      CALL FAR mem32                ; o32 FF /3            [386]
  4833.      CALL r/m16                    ; o16 FF /2            [8086]
  4834.      CALL r/m32                    ; o32 FF /2            [386]
  4835.    `CALL' calls a subroutine, by means of pushing the current
  4836. instruction pointer (`IP') and optionally `CS' as well on the stack,
  4837. and then jumping to a given address.
  4838.    `CS' is pushed as well as `IP' if and only if the call is a far
  4839. call, i.e. a destination segment address is specified in the
  4840. instruction.  The forms involving two colon-separated arguments are far
  4841. calls; so are the `CALL FAR mem' forms.
  4842.    You can choose between the two immediate far call forms (`CALL
  4843. imm:imm') by the use of the `WORD' and `DWORD' keywords: `CALL WORD
  4844. 0x1234:0x5678') or `CALL DWORD 0x1234:0x56789abc'.
  4845.    The `CALL FAR mem' forms execute a far call by loading the
  4846. destination address out of memory. The address loaded consists of 16 or
  4847. 32 bits of offset (depending on the operand size), and 16 bits of
  4848. segment. The operand size may be overridden using `CALL WORD FAR mem' or
  4849. `CALL DWORD FAR mem'.
  4850.    The `CALL r/m' forms execute a near call (within the same segment),
  4851. loading the destination address out of memory or out of a register. The
  4852. keyword `NEAR' may be specified, for clarity, in these forms, but is
  4853. not necessary. Again, operand size can be overridden using `CALL WORD
  4854. mem' or `CALL DWORD mem'.
  4855.    As a convenience, NASM does not require you to call a far procedure
  4856. symbol by coding the cumbersome `CALL SEG routine:routine', but instead
  4857. allows the easier synonym `CALL FAR routine'.
  4858.    The `CALL r/m' forms given above are near calls; NASM will accept the
  4859. `NEAR' keyword (e.g. `CALL NEAR [address]'), even though it is not
  4860. strictly necessary.
  4861. File: nasm.info,  Node: Section A.14,  Next: Section A.15,  Prev: Section A.13,  Up: Appendix A
  4862. A.14. `CBW', `CWD', `CDQ', `CWDE': Sign Extensions
  4863. **************************************************
  4864.      CBW                           ; o16 98               [8086]
  4865.      CWD                           ; o16 99               [8086]
  4866.      CDQ                           ; o32 99               [386]
  4867.      CWDE                          ; o32 98               [386]
  4868.    All these instructions sign-extend a short value into a longer one,
  4869. by replicating the top bit of the original value to fill the extended
  4870.    `CBW' extends `AL' into `AX' by repeating the top bit of `AL' in
  4871. every bit of `AH'. `CWD' extends `AX' into `DX:AX' by repeating the top
  4872. bit of `AX' throughout `DX'.  `CWDE' extends `AX' into `EAX', and `CDQ'
  4873. extends `EAX' into `EDX:EAX'.
  4874. File: nasm.info,  Node: Section A.15,  Next: Section A.16,  Prev: Section A.14,  Up: Appendix A
  4875. A.15. `CLC', `CLD', `CLI', `CLTS': Clear Flags
  4876. **********************************************
  4877.      CLC                           ; F8                   [8086]
  4878.      CLD                           ; FC                   [8086]
  4879.      CLI                           ; FA                   [8086]
  4880.      CLTS                          ; 0F 06                [286,PRIV]
  4881.    These instructions clear various flags. `CLC' clears the carry flag;
  4882. `CLD' clears the direction flag; `CLI' clears the interrupt flag (thus
  4883. disabling interrupts); and `CLTS' clears the task-switched (`TS') flag
  4884. in `CR0'.
  4885.    To set the carry, direction, or interrupt flags, use the `STC',
  4886. `STD' and `STI' instructions (*Note Section A.156::). To invert the
  4887. carry flag, use `CMC' (*Note Section A.16::).
  4888. File: nasm.info,  Node: Section A.16,  Next: Section A.17,  Prev: Section A.15,  Up: Appendix A
  4889. A.16. `CMC': Complement Carry Flag
  4890. **********************************
  4891.      CMC                           ; F5                   [8086]
  4892.    `CMC' changes the value of the carry flag: if it was 0, it sets it to
  4893. 1, and vice versa.
  4894. File: nasm.info,  Node: Section A.17,  Next: Section A.18,  Prev: Section A.16,  Up: Appendix A
  4895. A.17. `CMOVcc': Conditional Move
  4896. ********************************
  4897.      CMOVcc reg16,r/m16            ; o16 0F 40+cc /r      [P6]
  4898.      CMOVcc reg32,r/m32            ; o32 0F 40+cc /r      [P6]
  4899.    `CMOV' moves its source (second) operand into its destination (first)
  4900. operand if the given condition code is satisfied; otherwise it does
  4901. nothing.
  4902.    For a list of condition codes, see *Note Section A.2.2::.
  4903.    Although the `CMOV' instructions are flagged `P6' above, they may
  4904. not be supported by all Pentium Pro processors; the `CPUID' instruction
  4905. (*Note Section A.22::) will return a bit which indicates whether
  4906. conditional moves are supported.
  4907. File: nasm.info,  Node: Section A.18,  Next: Section A.19,  Prev: Section A.17,  Up: Appendix A
  4908. A.18. `CMP': Compare Integers
  4909. *****************************
  4910.      CMP r/m8,reg8                 ; 38 /r                [8086]
  4911.      CMP r/m16,reg16               ; o16 39 /r            [8086]
  4912.      CMP r/m32,reg32               ; o32 39 /r            [386]
  4913.      CMP reg8,r/m8                 ; 3A /r                [8086]
  4914.      CMP reg16,r/m16               ; o16 3B /r            [8086]
  4915.      CMP reg32,r/m32               ; o32 3B /r            [386]
  4916.      CMP r/m8,imm8                 ; 80 /0 ib             [8086]
  4917.      CMP r/m16,imm16               ; o16 81 /0 iw         [8086]
  4918.      CMP r/m32,imm32               ; o32 81 /0 id         [386]
  4919.      CMP r/m16,imm8                ; o16 83 /0 ib         [8086]
  4920.      CMP r/m32,imm8                ; o32 83 /0 ib         [386]
  4921.      CMP AL,imm8                   ; 3C ib                [8086]
  4922.      CMP AX,imm16                  ; o16 3D iw            [8086]
  4923.      CMP EAX,imm32                 ; o32 3D id            [386]
  4924.    `CMP' performs a `mental' subtraction of its second operand from its
  4925. first operand, and affects the flags as if the subtraction had taken
  4926. place, but does not store the result of the subtraction anywhere.
  4927.    In the forms with an 8-bit immediate second operand and a longer
  4928. first operand, the second operand is considered to be signed, and is
  4929. sign- extended to the length of the first operand. In these cases, the
  4930. `BYTE' qualifier is necessary to force NASM to generate this form of
  4931. the instruction.
  4932. File: nasm.info,  Node: Section A.19,  Next: Section A.20,  Prev: Section A.18,  Up: Appendix A
  4933. A.19. `CMPSB', `CMPSW', `CMPSD': Compare Strings
  4934. ************************************************
  4935.      CMPSB                         ; A6                   [8086]
  4936.      CMPSW                         ; o16 A7               [8086]
  4937.      CMPSD                         ; o32 A7               [386]
  4938.    `CMPSB' compares the byte at `[DS:SI]' or `[DS:ESI]' with the byte
  4939. at `[ES:DI]' or `[ES:EDI]', and sets the flags accordingly. It then
  4940. increments or decrements (depending on the direction flag: increments
  4941. if the flag is clear, decrements if it is set) `SI' and `DI' (or `ESI'
  4942. and `EDI').
  4943.    The registers used are `SI' and `DI' if the address size is 16 bits,
  4944. and `ESI' and `EDI' if it is 32 bits. If you need to use an address
  4945. size not equal to the current `BITS' setting, you can use an explicit
  4946. `a16' or `a32' prefix.
  4947.    The segment register used to load from `[SI]' or `[ESI]' can be
  4948. overridden by using a segment register name as a prefix (for example,
  4949. `es cmpsb'). The use of `ES' for the load from `[DI]' or `[EDI]' cannot
  4950. be overridden.
  4951.    `CMPSW' and `CMPSD' work in the same way, but they compare a word or
  4952. a doubleword instead of a byte, and increment or decrement the
  4953. addressing registers by 2 or 4 instead of 1.
  4954.    The `REPE' and `REPNE' prefixes (equivalently, `REPZ' and `REPNZ')
  4955. may be used to repeat the instruction up to `CX' (or `ECX' - again, the
  4956. address size chooses which) times until the first unequal or equal byte
  4957. is found.
  4958. File: nasm.info,  Node: Section A.20,  Next: Section A.21,  Prev: Section A.19,  Up: Appendix A
  4959. A.20. `CMPXCHG', `CMPXCHG486': Compare and Exchange
  4960. ***************************************************
  4961.      CMPXCHG r/m8,reg8             ; 0F B0 /r             [PENT]
  4962.      CMPXCHG r/m16,reg16           ; o16 0F B1 /r         [PENT]
  4963.      CMPXCHG r/m32,reg32           ; o32 0F B1 /r         [PENT]
  4964.      CMPXCHG486 r/m8,reg8          ; 0F A6 /r             [486,UNDOC]
  4965.      CMPXCHG486 r/m16,reg16        ; o16 0F A7 /r         [486,UNDOC]
  4966.      CMPXCHG486 r/m32,reg32        ; o32 0F A7 /r         [486,UNDOC]
  4967.    These two instructions perform exactly the same operation; however,
  4968. apparently some (not all) 486 processors support it under a non-standard
  4969. opcode, so NASM provides the undocumented `CMPXCHG486' form to generate
  4970. the non-standard opcode.
  4971.    `CMPXCHG' compares its destination (first) operand to the value in
  4972. `AL', `AX' or `EAX' (depending on the size of the instruction). If they
  4973. are equal, it copies its source (second) operand into the destination
  4974. and sets the zero flag. Otherwise, it clears the zero flag and leaves
  4975. the destination alone.
  4976.    `CMPXCHG' is intended to be used for atomic operations in
  4977. multitasking or multiprocessor environments. To safely update a value
  4978. in shared memory, for example, you might load the value into `EAX',
  4979. load the updated value into `EBX', and then execute the instruction
  4980. `lock cmpxchg [value],ebx'. If `value' has not changed since being
  4981. loaded, it is updated with your desired new value, and the zero flag is
  4982. set to let you know it has worked. (The `LOCK' prefix prevents another
  4983. processor doing anything in the middle of this operation: it guarantees
  4984. atomicity.) However, if another processor has modified the value in
  4985. between your load and your attempted store, the store does not happen,
  4986. and you are notified of the failure by a cleared zero flag, so you can
  4987. go round and try again.
  4988. File: nasm.info,  Node: Section A.21,  Next: Section A.22,  Prev: Section A.20,  Up: Appendix A
  4989. A.21. `CMPXCHG8B': Compare and Exchange Eight Bytes
  4990. ***************************************************
  4991.      CMPXCHG8B mem                 ; 0F C7 /1             [PENT]
  4992.    This is a larger and more unwieldy version of `CMPXCHG': it compares
  4993. the 64-bit (eight-byte) value stored at `[mem]' with the value in
  4994. `EDX:EAX'. If they are equal, it sets the zero flag and stores
  4995. `ECX:EBX' into the memory area. If they are unequal, it clears the zero
  4996. flag and leaves the memory area untouched.
  4997. File: nasm.info,  Node: Section A.22,  Next: Section A.23,  Prev: Section A.21,  Up: Appendix A
  4998. A.22. `CPUID': Get CPU Identification Code
  4999. ******************************************
  5000.      CPUID                         ; 0F A2                [PENT]
  5001.    `CPUID' returns various information about the processor it is being
  5002. executed on. It fills the four registers `EAX', `EBX', `ECX' and `EDX'
  5003. with information, which varies depending on the input contents of `EAX'.
  5004.    `CPUID' also acts as a barrier to serialise instruction execution:
  5005. executing the `CPUID' instruction guarantees that all the effects
  5006. (memory modification, flag modification, register modification) of
  5007. previous instructions have been completed before the next instruction
  5008. gets fetched.
  5009.    The information returned is as follows:
  5010.    * If `EAX' is zero on input, `EAX' on output holds the maximum
  5011.      acceptable input value of `EAX', and `EBX:EDX:ECX' contain the
  5012.      string `"GenuineIntel"' (or not, if you have a clone processor).
  5013.      That is to say, `EBX' contains `"Genu"' (in NASM's own sense of
  5014.      character constants, described in *Note Section 3.4.2::), `EDX'
  5015.      contains `"ineI"' and `ECX' contains `"ntel"'.
  5016.    * If `EAX' is one on input, `EAX' on output contains version
  5017.      information about the processor, and `EDX' contains a set of
  5018.      feature flags, showing the presence and absence of various
  5019.      features. For example, bit 8 is set if the `CMPXCHG8B' instruction
  5020.      (*Note Section A.21::) is supported, bit 15 is set if the
  5021.      conditional move instructions (*Note Section A.17:: and *Note
  5022.      Section A.34::) are supported, and bit 23 is set if MMX
  5023.      instructions are supported.
  5024.    * If `EAX' is two on input, `EAX', `EBX', `ECX' and `EDX' all
  5025.      contain information about caches and TLBs (Translation Lookahead
  5026.      Buffers).
  5027.    For more information on the data returned from `CPUID', see the
  5028. documentation on Intel's web site.
  5029. File: nasm.info,  Node: Section A.23,  Next: Section A.24,  Prev: Section A.22,  Up: Appendix A
  5030. A.23. `DAA', `DAS': Decimal Adjustments
  5031. ***************************************
  5032.      DAA                           ; 27                   [8086]
  5033.      DAS                           ; 2F                   [8086]
  5034.    These instructions are used in conjunction with the add and subtract
  5035. instructions to perform binary-coded decimal arithmetic in *packed*
  5036. (one BCD digit per nibble) form. For the unpacked equivalents, see
  5037. *Note Section A.4::.
  5038.    `DAA' should be used after a one-byte `ADD' instruction whose
  5039. destination was the `AL' register: by means of examining the value in
  5040. the `AL' and also the auxiliary carry flag `AF', it determines whether
  5041. either digit of the addition has overflowed, and adjusts it (and sets
  5042. the carry and auxiliary-carry flags) if so. You can add long BCD
  5043. strings together by doing `ADD'/`DAA' on the low two digits, then doing
  5044. `ADC'/`DAA' on each subsequent pair of digits.
  5045.    `DAS' works similarly to `DAA', but is for use after `SUB'
  5046. instructions rather than `ADD'.
  5047. File: nasm.info,  Node: Section A.24,  Next: Section A.25,  Prev: Section A.23,  Up: Appendix A
  5048. A.24. `DEC': Decrement Integer
  5049. ******************************
  5050.      DEC reg16                     ; o16 48+r             [8086]
  5051.      DEC reg32                     ; o32 48+r             [386]
  5052.      DEC r/m8                      ; FE /1                [8086]
  5053.      DEC r/m16                     ; o16 FF /1            [8086]
  5054.      DEC r/m32                     ; o32 FF /1            [386]
  5055.    `DEC' subtracts 1 from its operand. It does *not* affect the carry
  5056. flag: to affect the carry flag, use `SUB something,1' (see *Note
  5057. Section A.159::). See also `INC' (*Note Section A.79::).
  5058. File: nasm.info,  Node: Section A.25,  Next: Section A.26,  Prev: Section A.24,  Up: Appendix A
  5059. A.25. `DIV': Unsigned Integer Divide
  5060. ************************************
  5061.      DIV r/m8                      ; F6 /6                [8086]
  5062.      DIV r/m16                     ; o16 F7 /6            [8086]
  5063.      DIV r/m32                     ; o32 F7 /6            [386]
  5064.    `DIV' performs unsigned integer division. The explicit operand
  5065. provided is the divisor; the dividend and destination operands are
  5066. implicit, in the following way:
  5067.    * For `DIV r/m8', `AX' is divided by the given operand; the quotient
  5068.      is stored in `AL' and the remainder in `AH'.
  5069.    * For `DIV r/m16', `DX:AX' is divided by the given operand; the
  5070.      quotient is stored in `AX' and the remainder in `DX'.
  5071.    * For `DIV r/m32', `EDX:EAX' is divided by the given operand; the
  5072.      quotient is stored in `EAX' and the remainder in `EDX'.
  5073.    Signed integer division is performed by the `IDIV' instruction: see
  5074. *Note Section A.76::.
  5075. File: nasm.info,  Node: Section A.26,  Next: Section A.27,  Prev: Section A.25,  Up: Appendix A
  5076. A.26. `EMMS': Empty MMX State
  5077. *****************************
  5078.      EMMS                          ; 0F 77                [PENT,MMX]
  5079.    `EMMS' sets the FPU tag word (marking which floating-point registers
  5080. are available) to all ones, meaning all registers are available for the
  5081. FPU to use. It should be used after executing MMX instructions and
  5082. before executing any subsequent floating-point operations.
  5083. File: nasm.info,  Node: Section A.27,  Next: Section A.28,  Prev: Section A.26,  Up: Appendix A
  5084. A.27. `ENTER': Create Stack Frame
  5085. *********************************
  5086.      ENTER imm,imm                 ; C8 iw ib             [186]
  5087.    `ENTER' constructs a stack frame for a high-level language procedure
  5088. call. The first operand (the `iw' in the opcode definition above refers
  5089. to the first operand) gives the amount of stack space to allocate for
  5090. local variables; the second (the `ib' above) gives the nesting level of
  5091. the procedure (for languages like Pascal, with nested procedures).
  5092.    The function of `ENTER', with a nesting level of zero, is equivalent
  5093.                PUSH EBP            ; or PUSH BP         in 16 bits
  5094.                MOV EBP,ESP         ; or MOV BP,SP       in 16 bits
  5095.                SUB ESP,operand1    ; or SUB SP,operand1 in 16 bits
  5096.    This creates a stack frame with the procedure parameters accessible
  5097. upwards from `EBP', and local variables accessible downwards from `EBP'.
  5098.    With a nesting level of one, the stack frame created is 4 (or 2)
  5099. bytes bigger, and the value of the final frame pointer `EBP' is
  5100. accessible in memory at `[EBP-4]'.
  5101.    This allows `ENTER', when called with a nesting level of two, to look
  5102. at the stack frame described by the *previous* value of `EBP', find the
  5103. frame pointer at offset -4 from that, and push it along with its new
  5104. frame pointer, so that when a level-two procedure is called from within
  5105. a level-one procedure, `[EBP-4]' holds the frame pointer of the most
  5106. recent level-one procedure call and `[EBP-8]' holds that of the most
  5107. recent level-two call. And so on, for nesting levels up to 31.
  5108.    Stack frames created by `ENTER' can be destroyed by the `LEAVE'
  5109. instruction: see *Note Section A.94::.
  5110. File: nasm.info,  Node: Section A.28,  Next: Section A.29,  Prev: Section A.27,  Up: Appendix A
  5111. A.28. `F2XM1': Calculate 2**X-1
  5112. *******************************
  5113.      F2XM1                         ; D9 F0                [8086,FPU]
  5114.    `F2XM1' raises 2 to the power of `ST0', subtracts one, and stores
  5115. the result back into `ST0'. The initial contents of `ST0' must be a
  5116. number in the range -1 to +1.
  5117. File: nasm.info,  Node: Section A.29,  Next: Section A.30,  Prev: Section A.28,  Up: Appendix A
  5118. A.29. `FABS': Floating-Point Absolute Value
  5119. *******************************************
  5120.      FABS                          ; D9 E1                [8086,FPU]
  5121.    `FABS' computes the absolute value of `ST0', storing the result back
  5122. in `ST0'.
  5123. File: nasm.info,  Node: Section A.30,  Next: Section A.31,  Prev: Section A.29,  Up: Appendix A
  5124. A.30. `FADD', `FADDP': Floating-Point Addition
  5125. **********************************************
  5126.      FADD mem32                    ; D8 /0                [8086,FPU]
  5127.      FADD mem64                    ; DC /0                [8086,FPU]
  5128.      FADD fpureg                   ; D8 C0+r              [8086,FPU]
  5129.      FADD ST0,fpureg               ; D8 C0+r              [8086,FPU]
  5130.      FADD TO fpureg                ; DC C0+r              [8086,FPU]
  5131.      FADD fpureg,ST0               ; DC C0+r              [8086,FPU]
  5132.      FADDP fpureg                  ; DE C0+r              [8086,FPU]
  5133.      FADDP fpureg,ST0              ; DE C0+r              [8086,FPU]
  5134.    `FADD', given one operand, adds the operand to `ST0' and stores the
  5135. result back in `ST0'. If the operand has the `TO' modifier, the result
  5136. is stored in the register given rather than in `ST0'.
  5137.    `FADDP' performs the same function as `FADD TO', but pops the
  5138. register stack after storing the result.
  5139.    The given two-operand forms are synonyms for the one-operand forms.
  5140. File: nasm.info,  Node: Section A.31,  Next: Section A.32,  Prev: Section A.30,  Up: Appendix A
  5141. A.31. `FBLD', `FBSTP': BCD Floating-Point Load and Store
  5142. ********************************************************
  5143.      FBLD mem80                    ; DF /4                [8086,FPU]
  5144.      FBSTP mem80                   ; DF /6                [8086,FPU]
  5145.    `FBLD' loads an 80-bit (ten-byte) packed binary-coded decimal number
  5146. from the given memory address, converts it to a real, and pushes it on
  5147. the register stack. `FBSTP' stores the value of `ST0', in packed BCD,
  5148. at the given address and then pops the register stack.
  5149. File: nasm.info,  Node: Section A.32,  Next: Section A.33,  Prev: Section A.31,  Up: Appendix A
  5150. A.32. `FCHS': Floating-Point Change Sign
  5151. ****************************************
  5152.      FCHS                          ; D9 E0                [8086,FPU]
  5153.    `FCHS' negates the number in `ST0': negative numbers become
  5154. positive, and vice versa.
  5155. File: nasm.info,  Node: Section A.33,  Next: Section A.34,  Prev: Section A.32,  Up: Appendix A
  5156. A.33. `FCLEX', {FNCLEX}: Clear Floating-Point Exceptions
  5157. ********************************************************
  5158.      FCLEX                         ; 9B DB E2             [8086,FPU]
  5159.      FNCLEX                        ; DB E2                [8086,FPU]
  5160.    `FCLEX' clears any floating-point exceptions which may be pending.
  5161. `FNCLEX' does the same thing but doesn't wait for previous floating-
  5162. point operations (including the *handling* of pending exceptions) to
  5163. finish first.
  5164. File: nasm.info,  Node: Section A.34,  Next: Section A.35,  Prev: Section A.33,  Up: Appendix A
  5165. A.34. `FCMOVcc': Floating-Point Conditional Move
  5166. ************************************************
  5167.      FCMOVB fpureg                 ; DA C0+r              [P6,FPU]
  5168.      FCMOVB ST0,fpureg             ; DA C0+r              [P6,FPU]
  5169.      FCMOVBE fpureg                ; DA D0+r              [P6,FPU]
  5170.      FCMOVBE ST0,fpureg            ; DA D0+r              [P6,FPU]
  5171.      FCMOVE fpureg                 ; DA C8+r              [P6,FPU]
  5172.      FCMOVE ST0,fpureg             ; DA C8+r              [P6,FPU]
  5173.      FCMOVNB fpureg                ; DB C0+r              [P6,FPU]
  5174.      FCMOVNB ST0,fpureg            ; DB C0+r              [P6,FPU]
  5175.      FCMOVNBE fpureg               ; DB D0+r              [P6,FPU]
  5176.      FCMOVNBE ST0,fpureg           ; DB D0+r              [P6,FPU]
  5177.      FCMOVNE fpureg                ; DB C8+r              [P6,FPU]
  5178.      FCMOVNE ST0,fpureg            ; DB C8+r              [P6,FPU]
  5179.      FCMOVNU fpureg                ; DB D8+r              [P6,FPU]
  5180.      FCMOVNU ST0,fpureg            ; DB D8+r              [P6,FPU]
  5181.      FCMOVU fpureg                 ; DA D8+r              [P6,FPU]
  5182.      FCMOVU ST0,fpureg             ; DA D8+r              [P6,FPU]
  5183.    The `FCMOV' instructions perform conditional move operations: each of
  5184. them moves the contents of the given register into `ST0' if its
  5185. condition is satisfied, and does nothing if not.
  5186.    The conditions are not the same as the standard condition codes used
  5187. with conditional jump instructions. The conditions `B', `BE', `NB',
  5188. `NBE', `E' and `NE' are exactly as normal, but none of the other
  5189. standard ones are supported. Instead, the condition `U' and its
  5190. counterpart `NU' are provided; the `U' condition is satisfied if the
  5191. last two floating-point numbers compared were *unordered*, i.e. they
  5192. were not equal but neither one could be said to be greater than the
  5193. other, for example if they were NaNs. (The flag state which signals
  5194. this is the setting of the parity flag: so the `U' condition is
  5195. notionally equivalent to `PE', and `NU' is equivalent to `PO'.)
  5196.    The `FCMOV' conditions test the main processor's status flags, not
  5197. the FPU status flags, so using `FCMOV' directly after `FCOM' will not
  5198. work. Instead, you should either use `FCOMI' which writes directly to
  5199. the main CPU flags word, or use `FSTSW' to extract the FPU flags.
  5200.    Although the `FCMOV' instructions are flagged `P6' above, they may
  5201. not be supported by all Pentium Pro processors; the `CPUID' instruction
  5202. (*Note Section A.22::) will return a bit which indicates whether
  5203. conditional moves are supported.
  5204. File: nasm.info,  Node: Section A.35,  Next: Section A.36,  Prev: Section A.34,  Up: Appendix A
  5205. A.35. `FCOM', `FCOMP', `FCOMPP', `FCOMI', `FCOMIP': Floating-Point Compare
  5206. **************************************************************************
  5207.      FCOM mem32                    ; D8 /2                [8086,FPU]
  5208.      FCOM mem64                    ; DC /2                [8086,FPU]
  5209.      FCOM fpureg                   ; D8 D0+r              [8086,FPU]
  5210.      FCOM ST0,fpureg               ; D8 D0+r              [8086,FPU]
  5211.      FCOMP mem32                   ; D8 /3                [8086,FPU]
  5212.      FCOMP mem64                   ; DC /3                [8086,FPU]
  5213.      FCOMP fpureg                  ; D8 D8+r              [8086,FPU]
  5214.      FCOMP ST0,fpureg              ; D8 D8+r              [8086,FPU]
  5215.      FCOMPP                        ; DE D9                [8086,FPU]
  5216.      FCOMI fpureg                  ; DB F0+r              [P6,FPU]
  5217.      FCOMI ST0,fpureg              ; DB F0+r              [P6,FPU]
  5218.      FCOMIP fpureg                 ; DF F0+r              [P6,FPU]
  5219.      FCOMIP ST0,fpureg             ; DF F0+r              [P6,FPU]
  5220.    `FCOM' compares `ST0' with the given operand, and sets the FPU flags
  5221. accordingly. `ST0' is treated as the left-hand side of the comparison,
  5222. so that the carry flag is set (for a `less-than' result) if `ST0' is
  5223. less than the given operand.
  5224.    `FCOMP' does the same as `FCOM', but pops the register stack
  5225. afterwards. `FCOMPP' compares `ST0' with `ST1' and then pops the
  5226. register stack twice.
  5227.    `FCOMI' and `FCOMIP' work like the corresponding forms of `FCOM' and
  5228. `FCOMP', but write their results directly to the CPU flags register
  5229. rather than the FPU status word, so they can be immediately followed by
  5230. conditional jump or conditional move instructions.
  5231.    The `FCOM' instructions differ from the `FUCOM' instructions (*Note
  5232. Section A.69::) only in the way they handle quiet NaNs: `FUCOM' will
  5233. handle them silently and set the condition code flags to an `unordered'
  5234. result, whereas `FCOM' will generate an exception.
  5235. File: nasm.info,  Node: Section A.36,  Next: Section A.37,  Prev: Section A.35,  Up: Appendix A
  5236. A.36. `FCOS': Cosine
  5237. ********************
  5238.      FCOS                          ; D9 FF                [386,FPU]
  5239.    `FCOS' computes the cosine of `ST0' (in radians), and stores the
  5240. result in `ST0'. See also `FSINCOS' (*Note Section A.61::).
  5241. File: nasm.info,  Node: Section A.37,  Next: Section A.38,  Prev: Section A.36,  Up: Appendix A
  5242. A.37. `FDECSTP': Decrement Floating-Point Stack Pointer
  5243. *******************************************************
  5244.      FDECSTP                       ; D9 F6                [8086,FPU]
  5245.    `FDECSTP' decrements the `top' field in the floating-point status
  5246. word. This has the effect of rotating the FPU register stack by one, as
  5247. if the contents of `ST7' had been pushed on the stack. See also
  5248. `FINCSTP' (*Note Section A.46::).
  5249. File: nasm.info,  Node: Section A.38,  Next: Section A.39,  Prev: Section A.37,  Up: Appendix A
  5250. A.38. `FxDISI', `FxENI': Disable and Enable Floating-Point Interrupts
  5251. *********************************************************************
  5252.      FDISI                         ; 9B DB E1             [8086,FPU]
  5253.      FNDISI                        ; DB E1                [8086,FPU]
  5254.      FENI                          ; 9B DB E0             [8086,FPU]
  5255.      FNENI                         ; DB E0                [8086,FPU]
  5256.    `FDISI' and `FENI' disable and enable floating-point interrupts.
  5257. These instructions are only meaningful on original 8087 processors: the
  5258. 287 and above treat them as no-operation instructions.
  5259.    `FNDISI' and `FNENI' do the same thing as `FDISI' and `FENI'
  5260. respectively, but without waiting for the floating-point processor to
  5261. finish what it was doing first.
  5262. File: nasm.info,  Node: Section A.39,  Next: Section A.40,  Prev: Section A.38,  Up: Appendix A
  5263. A.39. `FDIV', `FDIVP', `FDIVR', `FDIVRP': Floating-Point Division
  5264. *****************************************************************
  5265.      FDIV mem32                    ; D8 /6                [8086,FPU]
  5266.      FDIV mem64                    ; DC /6                [8086,FPU]
  5267.      FDIV fpureg                   ; D8 F0+r              [8086,FPU]
  5268.      FDIV ST0,fpureg               ; D8 F0+r              [8086,FPU]
  5269.      FDIV TO fpureg                ; DC F8+r              [8086,FPU]
  5270.      FDIV fpureg,ST0               ; DC F8+r              [8086,FPU]
  5271.      FDIVR mem32                   ; D8 /0                [8086,FPU]
  5272.      FDIVR mem64                   ; DC /0                [8086,FPU]
  5273.      FDIVR fpureg                  ; D8 F8+r              [8086,FPU]
  5274.      FDIVR ST0,fpureg              ; D8 F8+r              [8086,FPU]
  5275.      FDIVR TO fpureg               ; DC F0+r              [8086,FPU]
  5276.      FDIVR fpureg,ST0              ; DC F0+r              [8086,FPU]
  5277.      FDIVP fpureg                  ; DE F8+r              [8086,FPU]
  5278.      FDIVP fpureg,ST0              ; DE F8+r              [8086,FPU]
  5279.      FDIVRP fpureg                 ; DE F0+r              [8086,FPU]
  5280.      FDIVRP fpureg,ST0             ; DE F0+r              [8086,FPU]
  5281.    `FDIV' divides `ST0' by the given operand and stores the result back
  5282. in `ST0', unless the `TO' qualifier is given, in which case it divides
  5283. the given operand by `ST0' and stores the result in the operand.
  5284.    `FDIVR' does the same thing, but does the division the other way up:
  5285. so if `TO' is not given, it divides the given operand by `ST0' and
  5286. stores the result in `ST0', whereas if `TO' is given it divides `ST0'
  5287. by its operand and stores the result in the operand.
  5288.    `FDIVP' operates like `FDIV TO', but pops the register stack once it
  5289. has finished. `FDIVRP' operates like `FDIVR TO', but pops the register
  5290. stack once it has finished.
  5291. File: nasm.info,  Node: Section A.40,  Next: Section A.41,  Prev: Section A.39,  Up: Appendix A
  5292. A.40. `FFREE': Flag Floating-Point Register as Unused
  5293. *****************************************************
  5294.      FFREE fpureg                  ; DD C0+r              [8086,FPU]
  5295.    `FFREE' marks the given register as being empty.
  5296. File: nasm.info,  Node: Section A.41,  Next: Section A.42,  Prev: Section A.40,  Up: Appendix A
  5297. A.41. `FIADD': Floating-Point/Integer Addition
  5298. **********************************************
  5299.      FIADD mem16                   ; DE /0                [8086,FPU]
  5300.      FIADD mem32                   ; DA /0                [8086,FPU]
  5301.    `FIADD' adds the 16-bit or 32-bit integer stored in the given memory
  5302. location to `ST0', storing the result in `ST0'.
  5303. File: nasm.info,  Node: Section A.42,  Next: Section A.43,  Prev: Section A.41,  Up: Appendix A
  5304. A.42. `FICOM', `FICOMP': Floating-Point/Integer Compare
  5305. *******************************************************
  5306.      FICOM mem16                   ; DE /2                [8086,FPU]
  5307.      FICOM mem32                   ; DA /2                [8086,FPU]
  5308.      FICOMP mem16                  ; DE /3                [8086,FPU]
  5309.      FICOMP mem32                  ; DA /3                [8086,FPU]
  5310.    `FICOM' compares `ST0' with the 16-bit or 32-bit integer stored in
  5311. the given memory location, and sets the FPU flags accordingly.
  5312. `FICOMP' does the same, but pops the register stack afterwards.
  5313. File: nasm.info,  Node: Section A.43,  Next: Section A.44,  Prev: Section A.42,  Up: Appendix A
  5314. A.43. `FIDIV', `FIDIVR': Floating-Point/Integer Division
  5315. ********************************************************
  5316.      FIDIV mem16                   ; DE /6                [8086,FPU]
  5317.      FIDIV mem32                   ; DA /6                [8086,FPU]
  5318.      FIDIVR mem16                  ; DE /0                [8086,FPU]
  5319.      FIDIVR mem32                  ; DA /0                [8086,FPU]
  5320.    `FIDIV' divides `ST0' by the 16-bit or 32-bit integer stored in the
  5321. given memory location, and stores the result in `ST0'.  `FIDIVR' does
  5322. the division the other way up: it divides the integer by `ST0', but
  5323. still stores the result in `ST0'.
  5324. File: nasm.info,  Node: Section A.44,  Next: Section A.45,  Prev: Section A.43,  Up: Appendix A
  5325. A.44. `FILD', `FIST', `FISTP': Floating-Point/Integer Conversion
  5326. ****************************************************************
  5327.      FILD mem16                    ; DF /0                [8086,FPU]
  5328.      FILD mem32                    ; DB /0                [8086,FPU]
  5329.      FILD mem64                    ; DF /5                [8086,FPU]
  5330.      FIST mem16                    ; DF /2                [8086,FPU]
  5331.      FIST mem32                    ; DB /2                [8086,FPU]
  5332.      FISTP mem16                   ; DF /3                [8086,FPU]
  5333.      FISTP mem32                   ; DB /3                [8086,FPU]
  5334.      FISTP mem64                   ; DF /0                [8086,FPU]
  5335.    `FILD' loads an integer out of a memory location, converts it to a
  5336. real, and pushes it on the FPU register stack. `FIST' converts `ST0' to
  5337. an integer and stores that in memory; `FISTP' does the same as `FIST',
  5338. but pops the register stack afterwards.
  5339. File: nasm.info,  Node: Section A.45,  Next: Section A.46,  Prev: Section A.44,  Up: Appendix A
  5340. A.45. `FIMUL': Floating-Point/Integer Multiplication
  5341. ****************************************************
  5342.      FIMUL mem16                   ; DE /1                [8086,FPU]
  5343.      FIMUL mem32                   ; DA /1                [8086,FPU]
  5344.    `FIMUL' multiplies `ST0' by the 16-bit or 32-bit integer stored in
  5345. the given memory location, and stores the result in `ST0'.
  5346. File: nasm.info,  Node: Section A.46,  Next: Section A.47,  Prev: Section A.45,  Up: Appendix A
  5347. A.46. `FINCSTP': Increment Floating-Point Stack Pointer
  5348. *******************************************************
  5349.      FINCSTP                       ; D9 F7                [8086,FPU]
  5350.    `FINCSTP' increments the `top' field in the floating-point status
  5351. word. This has the effect of rotating the FPU register stack by one, as
  5352. if the register stack had been popped; however, unlike the popping of
  5353. the stack performed by many FPU instructions, it does not flag the new
  5354. `ST7' (previously `ST0') as empty. See also `FDECSTP' (*Note Section
  5355. A.37::).
  5356. File: nasm.info,  Node: Section A.47,  Next: Section A.48,  Prev: Section A.46,  Up: Appendix A
  5357. A.47. `FINIT', `FNINIT': Initialise Floating-Point Unit
  5358. *******************************************************
  5359.      FINIT                         ; 9B DB E3             [8086,FPU]
  5360.      FNINIT                        ; DB E3                [8086,FPU]
  5361.    `FINIT' initialises the FPU to its default state. It flags all
  5362. registers as empty, though it does not actually change their values.
  5363. `FNINIT' does the same, without first waiting for pending exceptions to
  5364. clear.
  5365. File: nasm.info,  Node: Section A.48,  Next: Section A.49,  Prev: Section A.47,  Up: Appendix A
  5366. A.48. `FISUB': Floating-Point/Integer Subtraction
  5367. *************************************************
  5368.      FISUB mem16                   ; DE /4                [8086,FPU]
  5369.      FISUB mem32                   ; DA /4                [8086,FPU]
  5370.      FISUBR mem16                  ; DE /5                [8086,FPU]
  5371.      FISUBR mem32                  ; DA /5                [8086,FPU]
  5372.    `FISUB' subtracts the 16-bit or 32-bit integer stored in the given
  5373. memory location from `ST0', and stores the result in `ST0'.  `FISUBR'
  5374. does the subtraction the other way round, i.e. it subtracts `ST0' from
  5375. the given integer, but still stores the result in `ST0'.
  5376. File: nasm.info,  Node: Section A.49,  Next: Section A.50,  Prev: Section A.48,  Up: Appendix A
  5377. A.49. `FLD': Floating-Point Load
  5378. ********************************
  5379.      FLD mem32                     ; D9 /0                [8086,FPU]
  5380.      FLD mem64                     ; DD /0                [8086,FPU]
  5381.      FLD mem80                     ; DB /5                [8086,FPU]
  5382.      FLD fpureg                    ; D9 C0+r              [8086,FPU]
  5383.    `FLD' loads a floating-point value out of the given register or
  5384. memory location, and pushes it on the FPU register stack.
  5385. File: nasm.info,  Node: Section A.50,  Next: Section A.51,  Prev: Section A.49,  Up: Appendix A
  5386. A.50. `FLDxx': Floating-Point Load Constants
  5387. ********************************************
  5388.      FLD1                          ; D9 E8                [8086,FPU]
  5389.      FLDL2E                        ; D9 EA                [8086,FPU]
  5390.      FLDL2T                        ; D9 E9                [8086,FPU]
  5391.      FLDLG2                        ; D9 EC                [8086,FPU]
  5392.      FLDLN2                        ; D9 ED                [8086,FPU]
  5393.      FLDPI                         ; D9 EB                [8086,FPU]
  5394.      FLDZ                          ; D9 EE                [8086,FPU]
  5395.    These instructions push specific standard constants on the FPU
  5396. register stack. `FLD1' pushes the value 1; `FLDL2E' pushes the base-2
  5397. logarithm of e; `FLDL2T' pushes the base-2 log of 10; `FLDLG2' pushes
  5398. the base-10 log of 2; `FLDLN2' pushes the base-e log of 2; `FLDPI'
  5399. pushes pi; and `FLDZ' pushes zero.
  5400. File: nasm.info,  Node: Section A.51,  Next: Section A.52,  Prev: Section A.50,  Up: Appendix A
  5401. A.51. `FLDCW': Load Floating-Point Control Word
  5402. ***********************************************
  5403.      FLDCW mem16                   ; D9 /5                [8086,FPU]
  5404.    `FLDCW' loads a 16-bit value out of memory and stores it into the FPU
  5405. control word (governing things like the rounding mode, the precision,
  5406. and the exception masks). See also `FSTCW' (*Note Section A.64::).
  5407. File: nasm.info,  Node: Section A.52,  Next: Section A.53,  Prev: Section A.51,  Up: Appendix A
  5408. A.52. `FLDENV': Load Floating-Point Environment
  5409. ***********************************************
  5410.      FLDENV mem                    ; D9 /4                [8086,FPU]
  5411.    `FLDENV' loads the FPU operating environment (control word, status
  5412. word, tag word, instruction pointer, data pointer and last opcode) from
  5413. memory. The memory area is 14 or 28 bytes long, depending on the CPU
  5414. mode at the time. See also `FSTENV' (*Note Section A.65::).
  5415. File: nasm.info,  Node: Section A.53,  Next: Section A.54,  Prev: Section A.52,  Up: Appendix A
  5416. A.53. `FMUL', `FMULP': Floating-Point Multiply
  5417. **********************************************
  5418.      FMUL mem32                    ; D8 /1                [8086,FPU]
  5419.      FMUL mem64                    ; DC /1                [8086,FPU]
  5420.      FMUL fpureg                   ; D8 C8+r              [8086,FPU]
  5421.      FMUL ST0,fpureg               ; D8 C8+r              [8086,FPU]
  5422.      FMUL TO fpureg                ; DC C8+r              [8086,FPU]
  5423.      FMUL fpureg,ST0               ; DC C8+r              [8086,FPU]
  5424.      FMULP fpureg                  ; DE C8+r              [8086,FPU]
  5425.      FMULP fpureg,ST0              ; DE C8+r              [8086,FPU]
  5426.    `FMUL' multiplies `ST0' by the given operand, and stores the result
  5427. in `ST0', unless the `TO' qualifier is used in which case it stores the
  5428. result in the operand. `FMULP' performs the same operation as `FMUL
  5429. TO', and then pops the register stack.
  5430. File: nasm.info,  Node: Section A.54,  Next: Section A.55,  Prev: Section A.53,  Up: Appendix A
  5431. A.54. `FNOP': Floating-Point No Operation
  5432. *****************************************
  5433.      FNOP                          ; D9 D0                [8086,FPU]
  5434.    `FNOP' does nothing.
  5435. File: nasm.info,  Node: Section A.55,  Next: Section A.56,  Prev: Section A.54,  Up: Appendix A
  5436. A.55. `FPATAN', `FPTAN': Arctangent and Tangent
  5437. ***********************************************
  5438.      FPATAN                        ; D9 F3                [8086,FPU]
  5439.      FPTAN                         ; D9 F2                [8086,FPU]
  5440.    `FPATAN' computes the arctangent, in radians, of the result of
  5441. dividing `ST1' by `ST0', stores the result in `ST1', and pops the
  5442. register stack. It works like the C `atan2' function, in that changing
  5443. the sign of both `ST0' and `ST1' changes the output value by pi (so it
  5444. performs true rectangular-to-polar coordinate conversion, with `ST1'
  5445. being the Y coordinate and `ST0' being the X coordinate, not merely an
  5446. arctangent).
  5447.    `FPTAN' computes the tangent of the value in `ST0' (in radians), and
  5448. stores the result back into `ST0'.
  5449. File: nasm.info,  Node: Section A.56,  Next: Section A.57,  Prev: Section A.55,  Up: Appendix A
  5450. A.56. `FPREM', `FPREM1': Floating-Point Partial Remainder
  5451. *********************************************************
  5452.      FPREM                         ; D9 F8                [8086,FPU]
  5453.      FPREM1                        ; D9 F5                [386,FPU]
  5454.    These instructions both produce the remainder obtained by dividing
  5455. `ST0' by `ST1'. This is calculated, notionally, by dividing `ST0' by
  5456. `ST1', rounding the result to an integer, multiplying by `ST1' again,
  5457. and computing the value which would need to be added back on to the
  5458. result to get back to the original value in `ST0'.
  5459.    The two instructions differ in the way the notional round-to-integer
  5460. operation is performed. `FPREM' does it by rounding towards zero, so
  5461. that the remainder it returns always has the same sign as the original
  5462. value in `ST0'; `FPREM1' does it by rounding to the nearest integer, so
  5463. that the remainder always has at most half the magnitude of `ST1'.
  5464.    Both instructions calculate *partial* remainders, meaning that they
  5465. may not manage to provide the final result, but might leave intermediate
  5466. results in `ST0' instead. If this happens, they will set the C2 flag in
  5467. the FPU status word; therefore, to calculate a remainder, you should
  5468. repeatedly execute `FPREM' or `FPREM1' until C2 becomes clear.
  5469. File: nasm.info,  Node: Section A.57,  Next: Section A.58,  Prev: Section A.56,  Up: Appendix A
  5470. A.57. `FRNDINT': Floating-Point Round to Integer
  5471. ************************************************
  5472.      FRNDINT                       ; D9 FC                [8086,FPU]
  5473.    `FRNDINT' rounds the contents of `ST0' to an integer, according to
  5474. the current rounding mode set in the FPU control word, and stores the
  5475. result back in `ST0'.
  5476. File: nasm.info,  Node: Section A.58,  Next: Section A.59,  Prev: Section A.57,  Up: Appendix A
  5477. A.58. `FSAVE', `FRSTOR': Save/Restore Floating-Point State
  5478. **********************************************************
  5479.      FSAVE mem                     ; 9B DD /6             [8086,FPU]
  5480.      FNSAVE mem                    ; DD /6                [8086,FPU]
  5481.      FRSTOR mem                    ; DD /4                [8086,FPU]
  5482.    `FSAVE' saves the entire floating-point unit state, including all the
  5483. information saved by `FSTENV' (*Note Section A.65::) plus the contents
  5484. of all the registers, to a 94 or 108 byte area of memory (depending on
  5485. the CPU mode). `FRSTOR' restores the floating-point state from the same
  5486. area of memory.
  5487.    `FNSAVE' does the same as `FSAVE', without first waiting for pending
  5488. floating-point exceptions to clear.
  5489. File: nasm.info,  Node: Section A.59,  Next: Section A.60,  Prev: Section A.58,  Up: Appendix A
  5490. A.59. `FSCALE': Scale Floating-Point Value by Power of Two
  5491. **********************************************************
  5492.      FSCALE                        ; D9 FD                [8086,FPU]
  5493.    `FSCALE' scales a number by a power of two: it rounds `ST1' towards
  5494. zero to obtain an integer, then multiplies `ST0' by two to the power of
  5495. that integer, and stores the result in `ST0'.
  5496. File: nasm.info,  Node: Section A.60,  Next: Section A.61,  Prev: Section A.59,  Up: Appendix A
  5497. A.60. `FSETPM': Set Protected Mode
  5498. **********************************
  5499.      FSETPM                        ; DB E4                [286,FPU]
  5500.    This instruction initalises protected mode on the 287 floating-point
  5501. coprocessor. It is only meaningful on that processor: the 387 and above
  5502. treat the instruction as a no-operation.
  5503. File: nasm.info,  Node: Section A.61,  Next: Section A.62,  Prev: Section A.60,  Up: Appendix A
  5504. A.61. `FSIN', `FSINCOS': Sine and Cosine
  5505. ****************************************
  5506.      FSIN                          ; D9 FE                [386,FPU]
  5507.      FSINCOS                       ; D9 FB                [386,FPU]
  5508.    `FSIN' calculates the sine of `ST0' (in radians) and stores the
  5509. result in `ST0'. `FSINCOS' does the same, but then pushes the cosine of
  5510. the same value on the register stack, so that the sine ends up in `ST1'
  5511. and the cosine in `ST0'. `FSINCOS' is faster than executing `FSIN' and
  5512. `FCOS' (see *Note Section A.36::) in succession.
  5513. File: nasm.info,  Node: Section A.62,  Next: Section A.63,  Prev: Section A.61,  Up: Appendix A
  5514. A.62. `FSQRT': Floating-Point Square Root
  5515. *****************************************
  5516.      FSQRT                         ; D9 FA                [8086,FPU]
  5517.    `FSQRT' calculates the square root of `ST0' and stores the result in
  5518. `ST0'.
  5519. File: nasm.info,  Node: Section A.63,  Next: Section A.64,  Prev: Section A.62,  Up: Appendix A
  5520. A.63. `FST', `FSTP': Floating-Point Store
  5521. *****************************************
  5522.      FST mem32                     ; D9 /2                [8086,FPU]
  5523.      FST mem64                     ; DD /2                [8086,FPU]
  5524.      FST fpureg                    ; DD D0+r              [8086,FPU]
  5525.      FSTP mem32                    ; D9 /3                [8086,FPU]
  5526.      FSTP mem64                    ; DD /3                [8086,FPU]
  5527.      FSTP mem80                    ; DB /0                [8086,FPU]
  5528.      FSTP fpureg                   ; DD D8+r              [8086,FPU]
  5529.    `FST' stores the value in `ST0' into the given memory location or
  5530. other FPU register. `FSTP' does the same, but then pops the register
  5531. stack.
  5532. File: nasm.info,  Node: Section A.64,  Next: Section A.65,  Prev: Section A.63,  Up: Appendix A
  5533. A.64. `FSTCW': Store Floating-Point Control Word
  5534. ************************************************
  5535.      FSTCW mem16                   ; 9B D9 /0             [8086,FPU]
  5536.      FNSTCW mem16                  ; D9 /0                [8086,FPU]
  5537.    `FSTCW' stores the FPU control word (governing things like the
  5538. rounding mode, the precision, and the exception masks) into a 2-byte
  5539. memory area. See also `FLDCW' (*Note Section A.51::).
  5540.    `FNSTCW' does the same thing as `FSTCW', without first waiting for
  5541. pending floating-point exceptions to clear.
  5542. File: nasm.info,  Node: Section A.65,  Next: Section A.66,  Prev: Section A.64,  Up: Appendix A
  5543. A.65. `FSTENV': Store Floating-Point Environment
  5544. ************************************************
  5545.      FSTENV mem                    ; 9B D9 /6             [8086,FPU]
  5546.      FNSTENV mem                   ; D9 /6                [8086,FPU]
  5547.    `FSTENV' stores the FPU operating environment (control word, status
  5548. word, tag word, instruction pointer, data pointer and last opcode) into
  5549. memory. The memory area is 14 or 28 bytes long, depending on the CPU
  5550. mode at the time. See also `FLDENV' (*Note Section A.52::).
  5551.    `FNSTENV' does the same thing as `FSTENV', without first waiting for
  5552. pending floating-point exceptions to clear.
  5553. File: nasm.info,  Node: Section A.66,  Next: Section A.67,  Prev: Section A.65,  Up: Appendix A
  5554. A.66. `FSTSW': Store Floating-Point Status Word
  5555. ***********************************************
  5556.      FSTSW mem16                   ; 9B DD /0             [8086,FPU]
  5557.      FSTSW AX                      ; 9B DF E0             [286,FPU]
  5558.      FNSTSW mem16                  ; DD /0                [8086,FPU]
  5559.      FNSTSW AX                     ; DF E0                [286,FPU]
  5560.    `FSTSW' stores the FPU status word into `AX' or into a 2-byte memory
  5561. area.
  5562.    `FNSTSW' does the same thing as `FSTSW', without first waiting for
  5563. pending floating-point exceptions to clear.
  5564. File: nasm.info,  Node: Section A.67,  Next: Section A.68,  Prev: Section A.66,  Up: Appendix A
  5565. A.67. `FSUB', `FSUBP', `FSUBR', `FSUBRP': Floating-Point Subtract
  5566. *****************************************************************
  5567.      FSUB mem32                    ; D8 /4                [8086,FPU]
  5568.      FSUB mem64                    ; DC /4                [8086,FPU]
  5569.      FSUB fpureg                   ; D8 E0+r              [8086,FPU]
  5570.      FSUB ST0,fpureg               ; D8 E0+r              [8086,FPU]
  5571.      FSUB TO fpureg                ; DC E8+r              [8086,FPU]
  5572.      FSUB fpureg,ST0               ; DC E8+r              [8086,FPU]
  5573.      FSUBR mem32                   ; D8 /5                [8086,FPU]
  5574.      FSUBR mem64                   ; DC /5                [8086,FPU]
  5575.      FSUBR fpureg                  ; D8 E8+r              [8086,FPU]
  5576.      FSUBR ST0,fpureg              ; D8 E8+r              [8086,FPU]
  5577.      FSUBR TO fpureg               ; DC E0+r              [8086,FPU]
  5578.      FSUBR fpureg,ST0              ; DC E0+r              [8086,FPU]
  5579.      FSUBP fpureg                  ; DE E8+r              [8086,FPU]
  5580.      FSUBP fpureg,ST0              ; DE E8+r              [8086,FPU]
  5581.      FSUBRP fpureg                 ; DE E0+r              [8086,FPU]
  5582.      FSUBRP fpureg,ST0             ; DE E0+r              [8086,FPU]
  5583.    `FSUB' subtracts the given operand from `ST0' and stores the result
  5584. back in `ST0', unless the `TO' qualifier is given, in which case it
  5585. subtracts `ST0' from the given operand and stores the result in the
  5586. operand.
  5587.    `FSUBR' does the same thing, but does the subtraction the other way
  5588. up: so if `TO' is not given, it subtracts `ST0' from the given operand
  5589. and stores the result in `ST0', whereas if `TO' is given it subtracts
  5590. its operand from `ST0' and stores the result in the operand.
  5591.    `FSUBP' operates like `FSUB TO', but pops the register stack once it
  5592. has finished. `FSUBRP' operates like `FSUBR TO', but pops the register
  5593. stack once it has finished.
  5594. File: nasm.info,  Node: Section A.68,  Next: Section A.69,  Prev: Section A.67,  Up: Appendix A
  5595. A.68. `FTST': Test `ST0' Against Zero
  5596. *************************************
  5597.      FTST                          ; D9 E4                [8086,FPU]
  5598.    `FTST' compares `ST0' with zero and sets the FPU flags accordingly.
  5599. `ST0' is treated as the left-hand side of the comparison, so that a
  5600. `less-than' result is generated if `ST0' is negative.
  5601. File: nasm.info,  Node: Section A.69,  Next: Section A.70,  Prev: Section A.68,  Up: Appendix A
  5602. A.69. `FUCOMxx': Floating-Point Unordered Compare
  5603. *************************************************
  5604.      FUCOM fpureg                  ; DD E0+r              [386,FPU]
  5605.      FUCOM ST0,fpureg              ; DD E0+r              [386,FPU]
  5606.      FUCOMP fpureg                 ; DD E8+r              [386,FPU]
  5607.      FUCOMP ST0,fpureg             ; DD E8+r              [386,FPU]
  5608.      FUCOMPP                       ; DA E9                [386,FPU]
  5609.      FUCOMI fpureg                 ; DB E8+r              [P6,FPU]
  5610.      FUCOMI ST0,fpureg             ; DB E8+r              [P6,FPU]
  5611.      FUCOMIP fpureg                ; DF E8+r              [P6,FPU]
  5612.      FUCOMIP ST0,fpureg            ; DF E8+r              [P6,FPU]
  5613.    `FUCOM' compares `ST0' with the given operand, and sets the FPU
  5614. flags accordingly. `ST0' is treated as the left-hand side of the
  5615. comparison, so that the carry flag is set (for a `less-than' result) if
  5616. `ST0' is less than the given operand.
  5617.    `FUCOMP' does the same as `FUCOM', but pops the register stack
  5618. afterwards. `FUCOMPP' compares `ST0' with `ST1' and then pops the
  5619. register stack twice.
  5620.    `FUCOMI' and `FUCOMIP' work like the corresponding forms of `FUCOM'
  5621. and `FUCOMP', but write their results directly to the CPU flags
  5622. register rather than the FPU status word, so they can be immediately
  5623. followed by conditional jump or conditional move instructions.
  5624.    The `FUCOM' instructions differ from the `FCOM' instructions (*Note
  5625. Section A.35::) only in the way they handle quiet NaNs: `FUCOM' will
  5626. handle them silently and set the condition code flags to an `unordered'
  5627. result, whereas `FCOM' will generate an exception.
  5628. File: nasm.info,  Node: Section A.70,  Next: Section A.71,  Prev: Section A.69,  Up: Appendix A
  5629. A.70. `FXAM': Examine Class of Value in `ST0'
  5630. *********************************************
  5631.      FXAM                          ; D9 E5                [8086,FPU]
  5632.    `FXAM' sets the FPU flags C3, C2 and C0 depending on the type of
  5633. value stored in `ST0': 000 (respectively) for an unsupported format,
  5634. 001 for a NaN, 010 for a normal finite number, 011 for an infinity, 100
  5635. for a zero, 101 for an empty register, and 110 for a denormal. It also
  5636. sets the C1 flag to the sign of the number.
  5637. File: nasm.info,  Node: Section A.71,  Next: Section A.72,  Prev: Section A.70,  Up: Appendix A
  5638. A.71. `FXCH': Floating-Point Exchange
  5639. *************************************
  5640.      FXCH                          ; D9 C9                [8086,FPU]
  5641.      FXCH fpureg                   ; D9 C8+r              [8086,FPU]
  5642.      FXCH fpureg,ST0               ; D9 C8+r              [8086,FPU]
  5643.      FXCH ST0,fpureg               ; D9 C8+r              [8086,FPU]
  5644.    `FXCH' exchanges `ST0' with a given FPU register. The no-operand
  5645. form exchanges `ST0' with `ST1'.
  5646. File: nasm.info,  Node: Section A.72,  Next: Section A.73,  Prev: Section A.71,  Up: Appendix A
  5647. A.72. `FXTRACT': Extract Exponent and Significand
  5648. *************************************************
  5649.      FXTRACT                       ; D9 F4                [8086,FPU]
  5650.    `FXTRACT' separates the number in `ST0' into its exponent and
  5651. significand (mantissa), stores the exponent back into `ST0', and then
  5652. pushes the significand on the register stack (so that the significand
  5653. ends up in `ST0', and the exponent in `ST1').
  5654. File: nasm.info,  Node: Section A.73,  Next: Section A.74,  Prev: Section A.72,  Up: Appendix A
  5655. A.73. `FYL2X', `FYL2XP1': Compute Y times Log2(X) or Log2(X+1)
  5656. **************************************************************
  5657.      FYL2X                         ; D9 F1                [8086,FPU]
  5658.      FYL2XP1                       ; D9 F9                [8086,FPU]
  5659.    `FYL2X' multiplies `ST1' by the base-2 logarithm of `ST0', stores
  5660. the result in `ST1', and pops the register stack (so that the result
  5661. ends up in `ST0'). `ST0' must be non-zero and positive.
  5662.    `FYL2XP1' works the same way, but replacing the base-2 log of `ST0'
  5663. with that of `ST0' plus one. This time, `ST0' must have magnitude no
  5664. greater than 1 minus half the square root of two.
  5665. File: nasm.info,  Node: Section A.74,  Next: Section A.75,  Prev: Section A.73,  Up: Appendix A
  5666. A.74. `HLT': Halt Processor
  5667. ***************************
  5668.      HLT                           ; F4                   [8086]
  5669.    `HLT' puts the processor into a halted state, where it will perform
  5670. no more operations until restarted by an interrupt or a reset.
  5671. File: nasm.info,  Node: Section A.75,  Next: Section A.76,  Prev: Section A.74,  Up: Appendix A
  5672. A.75. `IBTS': Insert Bit String
  5673. *******************************
  5674.      IBTS r/m16,reg16              ; o16 0F A7 /r         [386,UNDOC]
  5675.      IBTS r/m32,reg32              ; o32 0F A7 /r         [386,UNDOC]
  5676.    No clear documentation seems to be available for this instruction:
  5677. the best I've been able to find reads `Takes a string of bits from the
  5678. second operand and puts them in the first operand'. It is present only
  5679. in early 386 processors, and conflicts with the opcodes for
  5680. `CMPXCHG486'. NASM supports it only for completeness. Its counterpart
  5681. is `XBTS' (see *Note Section A.167::).
  5682. File: nasm.info,  Node: Section A.76,  Next: Section A.77,  Prev: Section A.75,  Up: Appendix A
  5683. A.76. `IDIV': Signed Integer Divide
  5684. ***********************************
  5685.      IDIV r/m8                     ; F6 /7                [8086]
  5686.      IDIV r/m16                    ; o16 F7 /7            [8086]
  5687.      IDIV r/m32                    ; o32 F7 /7            [386]
  5688.    `IDIV' performs signed integer division. The explicit operand
  5689. provided is the divisor; the dividend and destination operands are
  5690. implicit, in the following way:
  5691.    * For `IDIV r/m8', `AX' is divided by the given operand; the
  5692.      quotient is stored in `AL' and the remainder in `AH'.
  5693.    * For `IDIV r/m16', `DX:AX' is divided by the given operand; the
  5694.      quotient is stored in `AX' and the remainder in `DX'.
  5695.    * For `IDIV r/m32', `EDX:EAX' is divided by the given operand; the
  5696.      quotient is stored in `EAX' and the remainder in `EDX'.
  5697.    Unsigned integer division is performed by the `DIV' instruction: see
  5698. *Note Section A.25::.
  5699. File: nasm.info,  Node: Section A.77,  Next: Section A.78,  Prev: Section A.76,  Up: Appendix A
  5700. A.77. `IMUL': Signed Integer Multiply
  5701. *************************************
  5702.      IMUL r/m8                     ; F6 /5                [8086]
  5703.      IMUL r/m16                    ; o16 F7 /5            [8086]
  5704.      IMUL r/m32                    ; o32 F7 /5            [386]
  5705.      IMUL reg16,r/m16              ; o16 0F AF /r         [386]
  5706.      IMUL reg32,r/m32              ; o32 0F AF /r         [386]
  5707.      IMUL reg16,imm8               ; o16 6B /r ib         [286]
  5708.      IMUL reg16,imm16              ; o16 69 /r iw         [286]
  5709.      IMUL reg32,imm8               ; o32 6B /r ib         [386]
  5710.      IMUL reg32,imm32              ; o32 69 /r id         [386]
  5711.      IMUL reg16,r/m16,imm8         ; o16 6B /r ib         [286]
  5712.      IMUL reg16,r/m16,imm16        ; o16 69 /r iw         [286]
  5713.      IMUL reg32,r/m32,imm8         ; o32 6B /r ib         [386]
  5714.      IMUL reg32,r/m32,imm32        ; o32 69 /r id         [386]
  5715.    `IMUL' performs signed integer multiplication. For the single-operand
  5716. form, the other operand and destination are implicit, in the following
  5717.    * For `IMUL r/m8', `AL' is multiplied by the given operand; the
  5718.      product is stored in `AX'.
  5719.    * For `IMUL r/m16', `AX' is multiplied by the given operand; the
  5720.      product is stored in `DX:AX'.
  5721.    * For `IMUL r/m32', `EAX' is multiplied by the given operand; the
  5722.      product is stored in `EDX:EAX'.
  5723.    The two-operand form multiplies its two operands and stores the
  5724. result in the destination (first) operand. The three-operand form
  5725. multiplies its last two operands and stores the result in the first
  5726. operand.
  5727.    The two-operand form is in fact a shorthand for the three-operand
  5728. form, as can be seen by examining the opcode descriptions: in the
  5729. two-operand form, the code `/r' takes both its register and `r/m' parts
  5730. from the same operand (the first one).
  5731.    In the forms with an 8-bit immediate operand and another longer
  5732. source operand, the immediate operand is considered to be signed, and
  5733. is sign- extended to the length of the other source operand. In these
  5734. cases, the `BYTE' qualifier is necessary to force NASM to generate this
  5735. form of the instruction.
  5736.    Unsigned integer multiplication is performed by the `MUL'
  5737. instruction: see *Note Section A.107::.
  5738. File: nasm.info,  Node: Section A.78,  Next: Section A.79,  Prev: Section A.77,  Up: Appendix A
  5739. A.78. `IN': Input from I/O Port
  5740. *******************************
  5741.      IN AL,imm8                    ; E4 ib                [8086]
  5742.      IN AX,imm8                    ; o16 E5 ib            [8086]
  5743.      IN EAX,imm8                   ; o32 E5 ib            [386]
  5744.      IN AL,DX                      ; EC                   [8086]
  5745.      IN AX,DX                      ; o16 ED               [8086]
  5746.      IN EAX,DX                     ; o32 ED               [386]
  5747.    `IN' reads a byte, word or doubleword from the specified I/O port,
  5748. and stores it in the given destination register. The port number may be
  5749. specified as an immediate value if it is between 0 and 255, and
  5750. otherwise must be stored in `DX'. See also `OUT' (*Note Section
  5751. A.111::).
  5752. File: nasm.info,  Node: Section A.79,  Next: Section A.80,  Prev: Section A.78,  Up: Appendix A
  5753. A.79. `INC': Increment Integer
  5754. ******************************
  5755.      INC reg16                     ; o16 40+r             [8086]
  5756.      INC reg32                     ; o32 40+r             [386]
  5757.      INC r/m8                      ; FE /0                [8086]
  5758.      INC r/m16                     ; o16 FF /0            [8086]
  5759.      INC r/m32                     ; o32 FF /0            [386]
  5760.    `INC' adds 1 to its operand. It does *not* affect the carry flag: to
  5761. affect the carry flag, use `ADD something,1' (see *Note Section A.6::).
  5762. See also `DEC' (*Note Section A.24::).
  5763. File: nasm.info,  Node: Section A.80,  Next: Section A.81,  Prev: Section A.79,  Up: Appendix A
  5764. A.80. `INSB', `INSW', `INSD': Input String from I/O Port
  5765. ********************************************************
  5766.      INSB                          ; 6C                   [186]
  5767.      INSW                          ; o16 6D               [186]
  5768.      INSD                          ; o32 6D               [386]
  5769.    `INSB' inputs a byte from the I/O port specified in `DX' and stores
  5770. it at `[ES:DI]' or `[ES:EDI]'. It then increments or decrements
  5771. (depending on the direction flag: increments if the flag is clear,
  5772. decrements if it is set) `DI' or `EDI'.
  5773.    The register used is `DI' if the address size is 16 bits, and `EDI'
  5774. if it is 32 bits. If you need to use an address size not equal to the
  5775. current `BITS' setting, you can use an explicit `a16' or `a32' prefix.
  5776.    Segment override prefixes have no effect for this instruction: the
  5777. use of `ES' for the load from `[DI]' or `[EDI]' cannot be overridden.
  5778.    `INSW' and `INSD' work in the same way, but they input a word or a
  5779. doubleword instead of a byte, and increment or decrement the addressing
  5780. register by 2 or 4 instead of 1.
  5781.    The `REP' prefix may be used to repeat the instruction `CX' (or
  5782. `ECX' - again, the address size chooses which) times.
  5783.    See also `OUTSB', `OUTSW' and `OUTSD' (*Note Section A.112::).
  5784. File: nasm.info,  Node: Section A.81,  Next: Section A.82,  Prev: Section A.80,  Up: Appendix A
  5785. A.81. `INT': Software Interrupt
  5786. *******************************
  5787.      INT imm8                      ; CD ib                [8086]
  5788.    `INT' causes a software interrupt through a specified vector number
  5789. from 0 to 255.
  5790.    The code generated by the `INT' instruction is always two bytes long:
  5791. although there are short forms for some `INT' instructions, NASM does
  5792. not generate them when it sees the `INT' mnemonic. In order to generate
  5793. single-byte breakpoint instructions, use the `INT3' or `INT1'
  5794. instructions (see *Note Section A.82::) instead.
  5795. File: nasm.info,  Node: Section A.82,  Next: Section A.83,  Prev: Section A.81,  Up: Appendix A
  5796. A.82. `INT3', `INT1', `ICEBP', `INT01': Breakpoints
  5797. ***************************************************
  5798.      INT1                          ; F1                   [P6]
  5799.      ICEBP                         ; F1                   [P6]
  5800.      INT01                         ; F1                   [P6]
  5801.      INT3                          ; CC                   [8086]
  5802.    `INT1' and `INT3' are short one-byte forms of the instructions `INT
  5803. 1' and `INT 3' (see *Note Section A.81::). They perform a similar
  5804. function to their longer counterparts, but take up less code space.
  5805. They are used as breakpoints by debuggers.
  5806.    `INT1', and its alternative synonyms `INT01' and `ICEBP', is an
  5807. instruction used by in-circuit emulators (ICEs). It is present, though
  5808. not documented, on some processors down to the 286, but is only
  5809. documented for the Pentium Pro. `INT3' is the instruction normally used
  5810. as a breakpoint by debuggers.
  5811.    `INT3' is not precisely equivalent to `INT 3': the short form, since
  5812. it is designed to be used as a breakpoint, bypasses the normal IOPL
  5813. checks in virtual-8086 mode, and also does not go through interrupt
  5814. redirection.
  5815. File: nasm.info,  Node: Section A.83,  Next: Section A.84,  Prev: Section A.82,  Up: Appendix A
  5816. A.83. `INTO': Interrupt if Overflow
  5817. ***********************************
  5818.      INTO                          ; CE                   [8086]
  5819.    `INTO' performs an `INT 4' software interrupt (see *Note Section
  5820. A.81::) if and only if the overflow flag is set.
  5821. File: nasm.info,  Node: Section A.84,  Next: Section A.85,  Prev: Section A.83,  Up: Appendix A
  5822. A.84. `INVD': Invalidate Internal Caches
  5823. ****************************************
  5824.      INVD                          ; 0F 08                [486]
  5825.    `INVD' invalidates and empties the processor's internal caches, and
  5826. causes the processor to instruct external caches to do the same. It does
  5827. not write the contents of the caches back to memory first: any modified
  5828. data held in the caches will be lost. To write the data back first, use
  5829. `WBINVD' (*Note Section A.164::).
  5830. File: nasm.info,  Node: Section A.85,  Next: Section A.86,  Prev: Section A.84,  Up: Appendix A
  5831. A.85. `INVLPG': Invalidate TLB Entry
  5832. ************************************
  5833.      INVLPG mem                    ; 0F 01 /0             [486]
  5834.    `INVLPG' invalidates the translation lookahead buffer (TLB) entry
  5835. associated with the supplied memory address.
  5836. File: nasm.info,  Node: Section A.86,  Next: Section A.87,  Prev: Section A.85,  Up: Appendix A
  5837. A.86. `IRET', `IRETW', `IRETD': Return from Interrupt
  5838. *****************************************************
  5839.      IRET                          ; CF                   [8086]
  5840.      IRETW                         ; o16 CF               [8086]
  5841.      IRETD                         ; o32 CF               [386]
  5842.    `IRET' returns from an interrupt (hardware or software) by means of
  5843. popping `IP' (or `EIP'), `CS' and the flags off the stack and then
  5844. continuing execution from the new `CS:IP'.
  5845.    `IRETW' pops `IP', `CS' and the flags as 2 bytes each, taking 6
  5846. bytes off the stack in total. `IRETD' pops `EIP' as 4 bytes, pops a
  5847. further 4 bytes of which the top two are discarded and the bottom two
  5848. go into `CS', and pops the flags as 4 bytes as well, taking 12 bytes
  5849. off the stack.
  5850.    `IRET' is a shorthand for either `IRETW' or `IRETD', depending on
  5851. the default `BITS' setting at the time.
  5852. File: nasm.info,  Node: Section A.87,  Next: Section A.88,  Prev: Section A.86,  Up: Appendix A
  5853. A.87. `JCXZ', `JECXZ': Jump if CX/ECX Zero
  5854. ******************************************
  5855.      JCXZ imm                      ; o16 E3 rb            [8086]
  5856.      JECXZ imm                     ; o32 E3 rb            [386]
  5857.    `JCXZ' performs a short jump (with maximum range 128 bytes) if and
  5858. only if the contents of the `CX' register is 0. `JECXZ' does the same
  5859. thing, but with `ECX'.
  5860. File: nasm.info,  Node: Section A.88,  Next: Section A.89,  Prev: Section A.87,  Up: Appendix A
  5861. A.88. `JMP': Jump
  5862. *****************
  5863.      JMP imm                       ; E9 rw/rd             [8086]
  5864.      JMP SHORT imm                 ; EB rb                [8086]
  5865.      JMP imm:imm16                 ; o16 EA iw iw         [8086]
  5866.      JMP imm:imm32                 ; o32 EA id iw         [386]
  5867.      JMP FAR mem                   ; o16 FF /5            [8086]
  5868.      JMP FAR mem                   ; o32 FF /5            [386]
  5869.      JMP r/m16                     ; o16 FF /4            [8086]
  5870.      JMP r/m32                     ; o32 FF /4            [386]
  5871.    `JMP' jumps to a given address. The address may be specified as an
  5872. absolute segment and offset, or as a relative jump within the current
  5873. segment.
  5874.    `JMP SHORT imm' has a maximum range of 128 bytes, since the
  5875. displacement is specified as only 8 bits, but takes up less code space.
  5876. NASM does not choose when to generate `JMP SHORT' for you: you must
  5877. explicitly code `SHORT' every time you want a short jump.
  5878.    You can choose between the two immediate far jump forms (`JMP
  5879. imm:imm') by the use of the `WORD' and `DWORD' keywords: `JMP WORD
  5880. 0x1234:0x5678') or `JMP DWORD 0x1234:0x56789abc'.
  5881.    The `JMP FAR mem' forms execute a far jump by loading the destination
  5882. address out of memory. The address loaded consists of 16 or 32 bits of
  5883. offset (depending on the operand size), and 16 bits of segment. The
  5884. operand size may be overridden using `JMP WORD FAR mem' or `JMP DWORD
  5885. FAR mem'.
  5886.    The `JMP r/m' forms execute a near jump (within the same segment),
  5887. loading the destination address out of memory or out of a register. The
  5888. keyword `NEAR' may be specified, for clarity, in these forms, but is
  5889. not necessary. Again, operand size can be overridden using `JMP WORD
  5890. mem' or `JMP DWORD mem'.
  5891.    As a convenience, NASM does not require you to jump to a far symbol
  5892. by coding the cumbersome `JMP SEG routine:routine', but instead allows
  5893. the easier synonym `JMP FAR routine'.
  5894.    The `CALL r/m' forms given above are near calls; NASM will accept the
  5895. `NEAR' keyword (e.g. `CALL NEAR [address]'), even though it is not
  5896. strictly necessary.
  5897. File: nasm.info,  Node: Section A.89,  Next: Section A.90,  Prev: Section A.88,  Up: Appendix A
  5898. A.89. `Jcc': Conditional Branch
  5899. *******************************
  5900.      Jcc imm                       ; 70+cc rb             [8086]
  5901.      Jcc NEAR imm                  ; 0F 80+cc rw/rd       [386]
  5902.    The conditional jump instructions execute a near (same segment) jump
  5903. if and only if their conditions are satisfied. For example, `JNZ' jumps
  5904. only if the zero flag is not set.
  5905.    The ordinary form of the instructions has only a 128-byte range; the
  5906. `NEAR' form is a 386 extension to the instruction set, and can span the
  5907. full size of a segment. NASM will not override your choice of jump
  5908. instruction: if you want `Jcc NEAR', you have to use the `NEAR' keyword.
  5909.    The `SHORT' keyword is allowed on the first form of the instruction,
  5910. for clarity, but is not necessary.
  5911. File: nasm.info,  Node: Section A.90,  Next: Section A.91,  Prev: Section A.89,  Up: Appendix A
  5912. A.90. `LAHF': Load AH from Flags
  5913. ********************************
  5914.      LAHF                          ; 9F                   [8086]
  5915.    `LAHF' sets the `AH' register according to the contents of the low
  5916. byte of the flags word. See also `SAHF' (*Note Section A.145::).
  5917. File: nasm.info,  Node: Section A.91,  Next: Section A.92,  Prev: Section A.90,  Up: Appendix A
  5918. A.91. `LAR': Load Access Rights
  5919. *******************************
  5920.      LAR reg16,r/m16               ; o16 0F 02 /r         [286,PRIV]
  5921.      LAR reg32,r/m32               ; o32 0F 02 /r         [286,PRIV]
  5922.    `LAR' takes the segment selector specified by its source (second)
  5923. operand, finds the corresponding segment descriptor in the GDT or LDT,
  5924. and loads the access-rights byte of the descriptor into its destination
  5925. (first) operand.
  5926. File: nasm.info,  Node: Section A.92,  Next: Section A.93,  Prev: Section A.91,  Up: Appendix A
  5927. A.92. `LDS', `LES', `LFS', `LGS', `LSS': Load Far Pointer
  5928. *********************************************************
  5929.      LDS reg16,mem                 ; o16 C5 /r            [8086]
  5930.      LDS reg32,mem                 ; o32 C5 /r            [8086]
  5931.      LES reg16,mem                 ; o16 C4 /r            [8086]
  5932.      LES reg32,mem                 ; o32 C4 /r            [8086]
  5933.      LFS reg16,mem                 ; o16 0F B4 /r         [386]
  5934.      LFS reg32,mem                 ; o32 0F B4 /r         [386]
  5935.      LGS reg16,mem                 ; o16 0F B5 /r         [386]
  5936.      LGS reg32,mem                 ; o32 0F B5 /r         [386]
  5937.      LSS reg16,mem                 ; o16 0F B2 /r         [386]
  5938.      LSS reg32,mem                 ; o32 0F B2 /r         [386]
  5939.    These instructions load an entire far pointer (16 or 32 bits of
  5940. offset, plus 16 bits of segment) out of memory in one go. `LDS', for
  5941. example, loads 16 or 32 bits from the given memory address into the
  5942. given register (depending on the size of the register), then loads the
  5943. *next* 16 bits from memory into `DS'. `LES', `LFS', `LGS' and `LSS'
  5944. work in the same way but use the other segment registers.
  5945. File: nasm.info,  Node: Section A.93,  Next: Section A.94,  Prev: Section A.92,  Up: Appendix A
  5946. A.93. `LEA': Load Effective Address
  5947. ***********************************
  5948.      LEA reg16,mem                 ; o16 8D /r            [8086]
  5949.      LEA reg32,mem                 ; o32 8D /r            [8086]
  5950.    `LEA', despite its syntax, does not access memory. It calculates the
  5951. effective address specified by its second operand as if it were going to
  5952. load or store data from it, but instead it stores the calculated address
  5953. into the register specified by its first operand. This can be used to
  5954. perform quite complex calculations (e.g. `LEA EAX,[EBX+ECX*4+100]') in
  5955. one instruction.
  5956.    `LEA', despite being a purely arithmetic instruction which accesses
  5957. no memory, still requires square brackets around its second operand, as
  5958. if it were a memory reference.
  5959. File: nasm.info,  Node: Section A.94,  Next: Section A.95,  Prev: Section A.93,  Up: Appendix A
  5960. A.94. `LEAVE': Destroy Stack Frame
  5961. **********************************
  5962.      LEAVE                         ; C9                   [186]
  5963.    `LEAVE' destroys a stack frame of the form created by the `ENTER'
  5964. instruction (see *Note Section A.27::). It is functionally equivalent to
  5965. `MOV ESP,EBP' followed by `POP EBP' (or `MOV SP,BP' followed by `POP
  5966. BP' in 16-bit mode).
  5967. File: nasm.info,  Node: Section A.95,  Next: Section A.96,  Prev: Section A.94,  Up: Appendix A
  5968. A.95. `LGDT', `LIDT', `LLDT': Load Descriptor Tables
  5969. ****************************************************
  5970.      LGDT mem                      ; 0F 01 /2             [286,PRIV]
  5971.      LIDT mem                      ; 0F 01 /3             [286,PRIV]
  5972.      LLDT r/m16                    ; 0F 00 /2             [286,PRIV]
  5973.    `LGDT' and `LIDT' both take a 6-byte memory area as an operand: they
  5974. load a 32-bit linear address and a 16-bit size limit from that area (in
  5975. the opposite order) into the GDTR (global descriptor table register) or
  5976. IDTR (interrupt descriptor table register). These are the only
  5977. instructions which directly use *linear* addresses, rather than
  5978. segment/offset pairs.
  5979.    `LLDT' takes a segment selector as an operand. The processor looks up
  5980. that selector in the GDT and stores the limit and base address given
  5981. there into the LDTR (local descriptor table register).
  5982.    See also `SGDT', `SIDT' and `SLDT' (*Note Section A.151::).
  5983. File: nasm.info,  Node: Section A.96,  Next: Section A.97,  Prev: Section A.95,  Up: Appendix A
  5984. A.96. `LMSW': Load/Store Machine Status Word
  5985. ********************************************
  5986.      LMSW r/m16                    ; 0F 01 /6             [286,PRIV]
  5987.    `LMSW' loads the bottom four bits of the source operand into the
  5988. bottom four bits of the `CR0' control register (or the Machine Status
  5989. Word, on 286 processors). See also `SMSW' (*Note Section A.155::).
  5990. File: nasm.info,  Node: Section A.97,  Next: Section A.98,  Prev: Section A.96,  Up: Appendix A
  5991. A.97. `LOADALL', `LOADALL286': Load Processor State
  5992. ***************************************************
  5993.      LOADALL                       ; 0F 07                [386,UNDOC]
  5994.      LOADALL286                    ; 0F 05                [286,UNDOC]
  5995.    This instruction, in its two different-opcode forms, is apparently
  5996. supported on most 286 processors, some 386 and possibly some 486. The
  5997. opcode differs between the 286 and the 386.
  5998.    The function of the instruction is to load all information relating
  5999. to the state of the processor out of a block of memory: on the 286,
  6000. this block is located implicitly at absolute address `0x800', and on
  6001. the 386 and 486 it is at `[ES:EDI]'.
  6002. File: nasm.info,  Node: Section A.98,  Next: Section A.99,  Prev: Section A.97,  Up: Appendix A
  6003. A.98. `LODSB', `LODSW', `LODSD': Load from String
  6004. *************************************************
  6005.      LODSB                         ; AC                   [8086]
  6006.      LODSW                         ; o16 AD               [8086]
  6007.      LODSD                         ; o32 AD               [386]
  6008.    `LODSB' loads a byte from `[DS:SI]' or `[DS:ESI]' into `AL'. It then
  6009. increments or decrements (depending on the direction flag: increments
  6010. if the flag is clear, decrements if it is set) `SI' or `ESI'.
  6011.    The register used is `SI' if the address size is 16 bits, and `ESI'
  6012. if it is 32 bits. If you need to use an address size not equal to the
  6013. current `BITS' setting, you can use an explicit `a16' or `a32' prefix.
  6014.    The segment register used to load from `[SI]' or `[ESI]' can be
  6015. overridden by using a segment register name as a prefix (for example,
  6016. `es lodsb').
  6017.    `LODSW' and `LODSD' work in the same way, but they load a word or a
  6018. doubleword instead of a byte, and increment or decrement the addressing
  6019. registers by 2 or 4 instead of 1.
  6020. File: nasm.info,  Node: Section A.99,  Next: Section A.100,  Prev: Section A.98,  Up: Appendix A
  6021. A.99. `LOOP', `LOOPE', `LOOPZ', `LOOPNE', `LOOPNZ': Loop with Counter
  6022. *********************************************************************
  6023.      LOOP imm                      ; E2 rb                [8086]
  6024.      LOOP imm,CX                   ; a16 E2 rb            [8086]
  6025.      LOOP imm,ECX                  ; a32 E2 rb            [386]
  6026.      LOOPE imm                     ; E1 rb                [8086]
  6027.      LOOPE imm,CX                  ; a16 E1 rb            [8086]
  6028.      LOOPE imm,ECX                 ; a32 E1 rb            [386]
  6029.      LOOPZ imm                     ; E1 rb                [8086]
  6030.      LOOPZ imm,CX                  ; a16 E1 rb            [8086]
  6031.      LOOPZ imm,ECX                 ; a32 E1 rb            [386]
  6032.      LOOPNE imm                    ; E0 rb                [8086]
  6033.      LOOPNE imm,CX                 ; a16 E0 rb            [8086]
  6034.      LOOPNE imm,ECX                ; a32 E0 rb            [386]
  6035.      LOOPNZ imm                    ; E0 rb                [8086]
  6036.      LOOPNZ imm,CX                 ; a16 E0 rb            [8086]
  6037.      LOOPNZ imm,ECX                ; a32 E0 rb            [386]
  6038.    `LOOP' decrements its counter register (either `CX' or `ECX' - if
  6039. one is not specified explicitly, the `BITS' setting dictates which is
  6040. used) by one, and if the counter does not become zero as a result of
  6041. this operation, it jumps to the given label. The jump has a range of 128
  6042. bytes.
  6043.    `LOOPE' (or its synonym `LOOPZ') adds the additional condition that
  6044. it only jumps if the counter is nonzero *and* the zero flag is set.
  6045. Similarly, `LOOPNE' (and `LOOPNZ') jumps only if the counter is nonzero
  6046. and the zero flag is clear.
  6047. File: nasm.info,  Node: Section A.100,  Next: Section A.101,  Prev: Section A.99,  Up: Appendix A
  6048. A.100. `LSL': Load Segment Limit
  6049. ********************************
  6050.      LSL reg16,r/m16               ; o16 0F 03 /r         [286,PRIV]
  6051.      LSL reg32,r/m32               ; o32 0F 03 /r         [286,PRIV]
  6052.    `LSL' is given a segment selector in its source (second) operand; it
  6053. computes the segment limit value by loading the segment limit field from
  6054. the associated segment descriptor in the GDT or LDT. (This involves
  6055. shifting left by 12 bits if the segment limit is page-granular, and not
  6056. if it is byte-granular; so you end up with a byte limit in either
  6057. case.) The segment limit obtained is then loaded into the destination
  6058. (first) operand.
  6059. File: nasm.info,  Node: Section A.101,  Next: Section A.102,  Prev: Section A.100,  Up: Appendix A
  6060. A.101. `LTR': Load Task Register
  6061. ********************************
  6062.      LTR r/m16                     ; 0F 00 /3             [286,PRIV]
  6063.    `LTR' looks up the segment base and limit in the GDT or LDT
  6064. descriptor specified by the segment selector given as its operand, and
  6065. loads them into the Task Register.
  6066. File: nasm.info,  Node: Section A.102,  Next: Section A.103,  Prev: Section A.101,  Up: Appendix A
  6067. A.102. `MOV': Move Data
  6068. ***********************
  6069.      MOV r/m8,reg8                 ; 88 /r                [8086]
  6070.      MOV r/m16,reg16               ; o16 89 /r            [8086]
  6071.      MOV r/m32,reg32               ; o32 89 /r            [386]
  6072.      MOV reg8,r/m8                 ; 8A /r                [8086]
  6073.      MOV reg16,r/m16               ; o16 8B /r            [8086]
  6074.      MOV reg32,r/m32               ; o32 8B /r            [386]
  6075.      MOV reg8,imm8                 ; B0+r ib              [8086]
  6076.      MOV reg16,imm16               ; o16 B8+r iw          [8086]
  6077.      MOV reg32,imm32               ; o32 B8+r id          [386]
  6078.      MOV r/m8,imm8                 ; C6 /0 ib             [8086]
  6079.      MOV r/m16,imm16               ; o16 C7 /0 iw         [8086]
  6080.      MOV r/m32,imm32               ; o32 C7 /0 id         [386]
  6081.      MOV AL,memoffs8               ; A0 ow/od             [8086]
  6082.      MOV AX,memoffs16              ; o16 A1 ow/od         [8086]
  6083.      MOV EAX,memoffs32             ; o32 A1 ow/od         [386]
  6084.      MOV memoffs8,AL               ; A2 ow/od             [8086]
  6085.      MOV memoffs16,AX              ; o16 A3 ow/od         [8086]
  6086.      MOV memoffs32,EAX             ; o32 A3 ow/od         [386]
  6087.      MOV r/m16,segreg              ; o16 8C /r            [8086]
  6088.      MOV r/m32,segreg              ; o32 8C /r            [386]
  6089.      MOV segreg,r/m16              ; o16 8E /r            [8086]
  6090.      MOV segreg,r/m32              ; o32 8E /r            [386]
  6091.      MOV reg32,CR0/2/3/4           ; 0F 20 /r             [386]
  6092.      MOV reg32,DR0/1/2/3/6/7       ; 0F 21 /r             [386]
  6093.      MOV reg32,TR3/4/5/6/7         ; 0F 24 /r             [386]
  6094.      MOV CR0/2/3/4,reg32           ; 0F 22 /r             [386]
  6095.      MOV DR0/1/2/3/6/7,reg32       ; 0F 23 /r             [386]
  6096.      MOV TR3/4/5/6/7,reg32         ; 0F 26 /r             [386]
  6097.    `MOV' copies the contents of its source (second) operand into its
  6098. destination (first) operand.
  6099.    In all forms of the `MOV' instruction, the two operands are the same
  6100. size, except for moving between a segment register and an `r/m32'
  6101. operand. These instructions are treated exactly like the corresponding
  6102. 16- bit equivalent (so that, for example, `MOV DS,EAX' functions
  6103. identically to `MOV DS,AX' but saves a prefix when in 32-bit mode),
  6104. except that when a segment register is moved into a 32-bit destination,
  6105. the top two bytes of the result are undefined.
  6106.    `MOV' may not use `CS' as a destination.
  6107.    `CR4' is only a supported register on the Pentium and above.
  6108. File: nasm.info,  Node: Section A.103,  Next: Section A.104,  Prev: Section A.102,  Up: Appendix A
  6109. A.103. `MOVD': Move Doubleword to/from MMX Register
  6110. ***************************************************
  6111.      MOVD mmxreg,r/m32             ; 0F 6E /r             [PENT,MMX]
  6112.      MOVD r/m32,mmxreg             ; 0F 7E /r             [PENT,MMX]
  6113.    `MOVD' copies 32 bits from its source (second) operand into its
  6114. destination (first) operand. When the destination is a 64-bit MMX
  6115. register, the top 32 bits are set to zero.
  6116. File: nasm.info,  Node: Section A.104,  Next: Section A.105,  Prev: Section A.103,  Up: Appendix A
  6117. A.104. `MOVQ': Move Quadword to/from MMX Register
  6118. *************************************************
  6119.      MOVQ mmxreg,r/m64             ; 0F 6F /r             [PENT,MMX]
  6120.      MOVQ r/m64,mmxreg             ; 0F 7F /r             [PENT,MMX]
  6121.    `MOVQ' copies 64 bits from its source (second) operand into its
  6122. destination (first) operand.
  6123. File: nasm.info,  Node: Section A.105,  Next: Section A.106,  Prev: Section A.104,  Up: Appendix A
  6124. A.105. `MOVSB', `MOVSW', `MOVSD': Move String
  6125. *********************************************
  6126.      MOVSB                         ; A4                   [8086]
  6127.      MOVSW                         ; o16 A5               [8086]
  6128.      MOVSD                         ; o32 A5               [386]
  6129.    `MOVSB' copies the byte at `[ES:DI]' or `[ES:EDI]' to `[DS:SI]' or
  6130. `[DS:ESI]'. It then increments or decrements (depending on the
  6131. direction flag: increments if the flag is clear, decrements if it is
  6132. set) `SI' and `DI' (or `ESI' and `EDI').
  6133.    The registers used are `SI' and `DI' if the address size is 16 bits,
  6134. and `ESI' and `EDI' if it is 32 bits. If you need to use an address
  6135. size not equal to the current `BITS' setting, you can use an explicit
  6136. `a16' or `a32' prefix.
  6137.    The segment register used to load from `[SI]' or `[ESI]' can be
  6138. overridden by using a segment register name as a prefix (for example,
  6139. `es movsb'). The use of `ES' for the store to `[DI]' or `[EDI]' cannot
  6140. be overridden.
  6141.    `MOVSW' and `MOVSD' work in the same way, but they copy a word or a
  6142. doubleword instead of a byte, and increment or decrement the addressing
  6143. registers by 2 or 4 instead of 1.
  6144.    The `REP' prefix may be used to repeat the instruction `CX' (or
  6145. `ECX' - again, the address size chooses which) times.
  6146. File: nasm.info,  Node: Section A.106,  Next: Section A.107,  Prev: Section A.105,  Up: Appendix A
  6147. A.106. `MOVSX', `MOVZX': Move Data with Sign or Zero Extend
  6148. ***********************************************************
  6149.      MOVSX reg16,r/m8              ; o16 0F BE /r         [386]
  6150.      MOVSX reg32,r/m8              ; o32 0F BE /r         [386]
  6151.      MOVSX reg32,r/m16             ; o32 0F BF /r         [386]
  6152.      MOVZX reg16,r/m8              ; o16 0F B6 /r         [386]
  6153.      MOVZX reg32,r/m8              ; o32 0F B6 /r         [386]
  6154.      MOVZX reg32,r/m16             ; o32 0F B7 /r         [386]
  6155.    `MOVSX' sign-extends its source (second) operand to the length of its
  6156. destination (first) operand, and copies the result into the destination
  6157. operand. `MOVZX' does the same, but zero-extends rather than sign-
  6158. extending.
  6159. File: nasm.info,  Node: Section A.107,  Next: Section A.108,  Prev: Section A.106,  Up: Appendix A
  6160. A.107. `MUL': Unsigned Integer Multiply
  6161. ***************************************
  6162.      MUL r/m8                      ; F6 /4                [8086]
  6163.      MUL r/m16                     ; o16 F7 /4            [8086]
  6164.      MUL r/m32                     ; o32 F7 /4            [386]
  6165.    `MUL' performs unsigned integer multiplication. The other operand to
  6166. the multiplication, and the destination operand, are implicit, in the
  6167. following way:
  6168.    * For `MUL r/m8', `AL' is multiplied by the given operand; the
  6169.      product is stored in `AX'.
  6170.    * For `MUL r/m16', `AX' is multiplied by the given operand; the
  6171.      product is stored in `DX:AX'.
  6172.    * For `MUL r/m32', `EAX' is multiplied by the given operand; the
  6173.      product is stored in `EDX:EAX'.
  6174.    Signed integer multiplication is performed by the `IMUL' instruction:
  6175. see *Note Section A.77::.
  6176. File: nasm.info,  Node: Section A.108,  Next: Section A.109,  Prev: Section A.107,  Up: Appendix A
  6177. A.108. `NEG', `NOT': Two's and One's Complement
  6178. ***********************************************
  6179.      NEG r/m8                      ; F6 /3                [8086]
  6180.      NEG r/m16                     ; o16 F7 /3            [8086]
  6181.      NEG r/m32                     ; o32 F7 /3            [386]
  6182.      NOT r/m8                      ; F6 /2                [8086]
  6183.      NOT r/m16                     ; o16 F7 /2            [8086]
  6184.      NOT r/m32                     ; o32 F7 /2            [386]
  6185.    `NEG' replaces the contents of its operand by the two's complement
  6186. negation (invert all the bits and then add one) of the original value.
  6187. `NOT', similarly, performs one's complement (inverts all the bits).
  6188. File: nasm.info,  Node: Section A.109,  Next: Section A.110,  Prev: Section A.108,  Up: Appendix A
  6189. A.109. `NOP': No Operation
  6190. **************************
  6191.      NOP                           ; 90                   [8086]
  6192.    `NOP' performs no operation. Its opcode is the same as that generated
  6193. by `XCHG AX,AX' or `XCHG EAX,EAX' (depending on the processor mode; see
  6194. *Note Section A.168::).
  6195. File: nasm.info,  Node: Section A.110,  Next: Section A.111,  Prev: Section A.109,  Up: Appendix A
  6196. A.110. `OR': Bitwise OR
  6197. ***********************
  6198.      OR r/m8,reg8                  ; 08 /r                [8086]
  6199.      OR r/m16,reg16                ; o16 09 /r            [8086]
  6200.      OR r/m32,reg32                ; o32 09 /r            [386]
  6201.      OR reg8,r/m8                  ; 0A /r                [8086]
  6202.      OR reg16,r/m16                ; o16 0B /r            [8086]
  6203.      OR reg32,r/m32                ; o32 0B /r            [386]
  6204.      OR r/m8,imm8                  ; 80 /1 ib             [8086]
  6205.      OR r/m16,imm16                ; o16 81 /1 iw         [8086]
  6206.      OR r/m32,imm32                ; o32 81 /1 id         [386]
  6207.      OR r/m16,imm8                 ; o16 83 /1 ib         [8086]
  6208.      OR r/m32,imm8                 ; o32 83 /1 ib         [386]
  6209.      OR AL,imm8                    ; 0C ib                [8086]
  6210.      OR AX,imm16                   ; o16 0D iw            [8086]
  6211.      OR EAX,imm32                  ; o32 0D id            [386]
  6212.    `OR' performs a bitwise OR operation between its two operands (i.e.
  6213. each bit of the result is 1 if and only if at least one of the
  6214. corresponding bits of the two inputs was 1), and stores the result in
  6215. the destination (first) operand.
  6216.    In the forms with an 8-bit immediate second operand and a longer
  6217. first operand, the second operand is considered to be signed, and is
  6218. sign- extended to the length of the first operand. In these cases, the
  6219. `BYTE' qualifier is necessary to force NASM to generate this form of
  6220. the instruction.
  6221.    The MMX instruction `POR' (see *Note Section A.129::) performs the
  6222. same operation on the 64-bit MMX registers.
  6223. File: nasm.info,  Node: Section A.111,  Next: Section A.112,  Prev: Section A.110,  Up: Appendix A
  6224. A.111. `OUT': Output Data to I/O Port
  6225. *************************************
  6226.      OUT imm8,AL                   ; E6 ib                [8086]
  6227.      OUT imm8,AX                   ; o16 E7 ib            [8086]
  6228.      OUT imm8,EAX                  ; o32 E7 ib            [386]
  6229.      OUT DX,AL                     ; EE                   [8086]
  6230.      OUT DX,AX                     ; o16 EF               [8086]
  6231.      OUT DX,EAX                    ; o32 EF               [386]
  6232.    `IN' writes the contents of the given source register to the
  6233. specified I/O port. The port number may be specified as an immediate
  6234. value if it is between 0 and 255, and otherwise must be stored in `DX'.
  6235. See also `IN' (*Note Section A.78::).
  6236. File: nasm.info,  Node: Section A.112,  Next: Section A.113,  Prev: Section A.111,  Up: Appendix A
  6237. A.112. `OUTSB', `OUTSW', `OUTSD': Output String to I/O Port
  6238. ***********************************************************
  6239.      OUTSB                         ; 6E                   [186]
  6240.      OUTSW                         ; o16 6F               [186]
  6241.      OUTSD                         ; o32 6F               [386]
  6242.    `OUTSB' loads a byte from `[DS:SI]' or `[DS:ESI]' and writes it to
  6243. the I/O port specified in `DX'. It then increments or decrements
  6244. (depending on the direction flag: increments if the flag is clear,
  6245. decrements if it is set) `SI' or `ESI'.
  6246.    The register used is `SI' if the address size is 16 bits, and `ESI'
  6247. if it is 32 bits. If you need to use an address size not equal to the
  6248. current `BITS' setting, you can use an explicit `a16' or `a32' prefix.
  6249.    The segment register used to load from `[SI]' or `[ESI]' can be
  6250. overridden by using a segment register name as a prefix (for example,
  6251. `es outsb').
  6252.    `OUTSW' and `OUTSD' work in the same way, but they output a word or
  6253. a doubleword instead of a byte, and increment or decrement the
  6254. addressing registers by 2 or 4 instead of 1.
  6255.    The `REP' prefix may be used to repeat the instruction `CX' (or
  6256. `ECX' - again, the address size chooses which) times.
  6257. File: nasm.info,  Node: Section A.113,  Next: Section A.114,  Prev: Section A.112,  Up: Appendix A
  6258. A.113. `PACKSSDW', `PACKSSWB', `PACKUSWB': Pack Data
  6259. ****************************************************
  6260.      PACKSSDW mmxreg,r/m64         ; 0F 6B /r             [PENT,MMX]
  6261.      PACKSSWB mmxreg,r/m64         ; 0F 63 /r             [PENT,MMX]
  6262.      PACKUSWB mmxreg,r/m64         ; 0F 67 /r             [PENT,MMX]
  6263.    All these instructions start by forming a notional 128-bit word by
  6264. placing the source (second) operand on the left of the destination
  6265. (first) operand.  `PACKSSDW' then splits this 128-bit word into four
  6266. doublewords, converts each to a word, and loads them side by side into
  6267. the destination register; `PACKSSWB' and `PACKUSWB' both split the
  6268. 128-bit word into eight words, converts each to a byte, and loads
  6269. *those* side by side into the destination register.
  6270.    `PACKSSDW' and `PACKSSWB' perform signed saturation when reducing
  6271. the length of numbers: if the number is too large to fit into the
  6272. reduced space, they replace it by the largest signed number (`7FFFh' or
  6273. `7Fh') that *will* fit, and if it is too small then they replace it by
  6274. the smallest signed number (`8000h' or `80h') that will fit. `PACKUSWB'
  6275. performs unsigned saturation: it treats its input as unsigned, and
  6276. replaces it by the largest unsigned number that will fit.
  6277. File: nasm.info,  Node: Section A.114,  Next: Section A.115,  Prev: Section A.113,  Up: Appendix A
  6278. A.114. `PADDxx': MMX Packed Addition
  6279. ************************************
  6280.      PADDB mmxreg,r/m64            ; 0F FC /r             [PENT,MMX]
  6281.      PADDW mmxreg,r/m64            ; 0F FD /r             [PENT,MMX]
  6282.      PADDD mmxreg,r/m64            ; 0F FE /r             [PENT,MMX]
  6283.      PADDSB mmxreg,r/m64           ; 0F EC /r             [PENT,MMX]
  6284.      PADDSW mmxreg,r/m64           ; 0F ED /r             [PENT,MMX]
  6285.      PADDUSB mmxreg,r/m64          ; 0F DC /r             [PENT,MMX]
  6286.      PADDUSW mmxreg,r/m64          ; 0F DD /r             [PENT,MMX]
  6287.    `PADDxx' all perform packed addition between their two 64-bit
  6288. operands, storing the result in the destination (first) operand. The
  6289. `PADDxB' forms treat the 64-bit operands as vectors of eight bytes, and
  6290. add each byte individually; `PADDxW' treat the operands as vectors of
  6291. four words; and `PADDD' treats its operands as vectors of two
  6292. doublewords.
  6293.    `PADDSB' and `PADDSW' perform signed saturation on the sum of each
  6294. pair of bytes or words: if the result of an addition is too large or
  6295. too small to fit into a signed byte or word result, it is clipped
  6296. (saturated) to the largest or smallest value which *will* fit.
  6297. `PADDUSB' and `PADDUSW' similarly perform unsigned saturation, clipping
  6298. to `0FFh' or `0FFFFh' if the result is larger than that.
  6299. File: nasm.info,  Node: Section A.115,  Next: Section A.116,  Prev: Section A.114,  Up: Appendix A
  6300. A.115. `PADDSIW': MMX Packed Addition to Implicit Destination
  6301. *************************************************************
  6302.      PADDSIW mmxreg,r/m64          ; 0F 51 /r             [CYRIX,MMX]
  6303.    `PADDSIW', specific to the Cyrix extensions to the MMX instruction
  6304. set, performs the same function as `PADDSW', except that the result is
  6305. not placed in the register specified by the first operand, but instead
  6306. in the register whose number differs from the first operand only in the
  6307. last bit. So `PADDSIW MM0,MM2' would put the result in `MM1', but
  6308. `PADDSIW MM1,MM2' would put the result in `MM0'.
  6309. File: nasm.info,  Node: Section A.116,  Next: Section A.117,  Prev: Section A.115,  Up: Appendix A
  6310. A.116. `PAND', `PANDN': MMX Bitwise AND and AND-NOT
  6311. ***************************************************
  6312.      PAND mmxreg,r/m64             ; 0F DB /r             [PENT,MMX]
  6313.      PANDN mmxreg,r/m64            ; 0F DF /r             [PENT,MMX]
  6314.    `PAND' performs a bitwise AND operation between its two operands
  6315. (i.e.  each bit of the result is 1 if and only if the corresponding
  6316. bits of the two inputs were both 1), and stores the result in the
  6317. destination (first) operand.
  6318.    `PANDN' performs the same operation, but performs a one's complement
  6319. operation on the destination (first) operand first.
  6320. File: nasm.info,  Node: Section A.117,  Next: Section A.118,  Prev: Section A.116,  Up: Appendix A
  6321. A.117. `PAVEB': MMX Packed Average
  6322. **********************************
  6323.      PAVEB mmxreg,r/m64            ; 0F 50 /r             [CYRIX,MMX]
  6324.    `PAVEB', specific to the Cyrix MMX extensions, treats its two
  6325. operands as vectors of eight unsigned bytes, and calculates the average
  6326. of the corresponding bytes in the operands. The resulting vector of
  6327. eight averages is stored in the first operand.
  6328. File: nasm.info,  Node: Section A.118,  Next: Section A.119,  Prev: Section A.117,  Up: Appendix A
  6329. A.118. `PCMPxx': MMX Packed Comparison
  6330. **************************************
  6331.      PCMPEQB mmxreg,r/m64          ; 0F 74 /r             [PENT,MMX]
  6332.      PCMPEQW mmxreg,r/m64          ; 0F 75 /r             [PENT,MMX]
  6333.      PCMPEQD mmxreg,r/m64          ; 0F 76 /r             [PENT,MMX]
  6334.      PCMPGTB mmxreg,r/m64          ; 0F 64 /r             [PENT,MMX]
  6335.      PCMPGTW mmxreg,r/m64          ; 0F 65 /r             [PENT,MMX]
  6336.      PCMPGTD mmxreg,r/m64          ; 0F 66 /r             [PENT,MMX]
  6337.    The `PCMPxx' instructions all treat their operands as vectors of
  6338. bytes, words, or doublewords; corresponding elements of the source and
  6339. destination are compared, and the corresponding element of the
  6340. destination (first) operand is set to all zeros or all ones depending
  6341. on the result of the comparison.
  6342.    `PCMPxxB' treats the operands as vectors of eight bytes, `PCMPxxW'
  6343. treats them as vectors of four words, and `PCMPxxD' as two doublewords.
  6344.    `PCMPEQx' sets the corresponding element of the destination operand
  6345. to all ones if the two elements compared are equal; `PCMPGTx' sets the
  6346. destination element to all ones if the element of the first
  6347. (destination) operand is greater (treated as a signed integer) than
  6348. that of the second (source) operand.
  6349. File: nasm.info,  Node: Section A.119,  Next: Section A.120,  Prev: Section A.118,  Up: Appendix A
  6350. A.119. `PDISTIB': MMX Packed Distance and Accumulate with Implied Register
  6351. **************************************************************************
  6352.      PDISTIB mmxreg,mem64          ; 0F 54 /r             [CYRIX,MMX]
  6353.    `PDISTIB', specific to the Cyrix MMX extensions, treats its two input
  6354. operands as vectors of eight unsigned bytes. For each byte position, it
  6355. finds the absolute difference between the bytes in that position in the
  6356. two input operands, and adds that value to the byte in the same
  6357. position in the implied output register. The addition is saturated to
  6358. an unsigned byte in the same way as `PADDUSB'.
  6359.    The implied output register is found in the same way as `PADDSIW'
  6360. (*Note Section A.115::).
  6361.    Note that `PDISTIB' cannot take a register as its second source
  6362. operand.
  6363. File: nasm.info,  Node: Section A.120,  Next: Section A.121,  Prev: Section A.119,  Up: Appendix A
  6364. A.120. `PMACHRIW': MMX Packed Multiply and Accumulate with Rounding
  6365. *******************************************************************
  6366.      PMACHRIW mmxreg,mem64         ; 0F 5E /r             [CYRIX,MMX]
  6367.    `PMACHRIW' acts almost identically to `PMULHRIW' (*Note Section
  6368. A.123::), but instead of *storing* its result in the implied
  6369. destination register, it *adds* its result, as four packed words, to
  6370. the implied destination register. No saturation is done: the addition
  6371. can wrap around.
  6372.    Note that `PMACHRIW' cannot take a register as its second source
  6373. operand.
  6374. File: nasm.info,  Node: Section A.121,  Next: Section A.122,  Prev: Section A.120,  Up: Appendix A
  6375. A.121. `PMADDWD': MMX Packed Multiply and Add
  6376. *********************************************
  6377.      PMADDWD mmxreg,r/m64          ; 0F F5 /r             [PENT,MMX]
  6378.    `PMADDWD' treats its two inputs as vectors of four signed words. It
  6379. multiplies corresponding elements of the two operands, giving four
  6380. signed doubleword results. The top two of these are added and placed in
  6381. the top 32 bits of the destination (first) operand; the bottom two are
  6382. added and placed in the bottom 32 bits.
  6383. File: nasm.info,  Node: Section A.122,  Next: Section A.123,  Prev: Section A.121,  Up: Appendix A
  6384. A.122. `PMAGW': MMX Packed Magnitude
  6385. ************************************
  6386.      PMAGW mmxreg,r/m64            ; 0F 52 /r             [CYRIX,MMX]
  6387.    `PMAGW', specific to the Cyrix MMX extensions, treats both its
  6388. operands as vectors of four signed words. It compares the absolute
  6389. values of the words in corresponding positions, and sets each word of
  6390. the destination (first) operand to whichever of the two words in that
  6391. position had the larger absolute value.
  6392. File: nasm.info,  Node: Section A.123,  Next: Section A.124,  Prev: Section A.122,  Up: Appendix A
  6393. A.123. `PMULHRW', `PMULHRIW': MMX Packed Multiply High with Rounding
  6394. ********************************************************************
  6395.      PMULHRW mmxreg,r/m64          ; 0F 59 /r             [CYRIX,MMX]
  6396.      PMULHRIW mmxreg,r/m64         ; 0F 5D /r             [CYRIX,MMX]
  6397.    These instructions, specific to the Cyrix MMX extensions, treat their
  6398. operands as vectors of four signed words. Words in corresponding
  6399. positions are multiplied, to give a 32-bit value in which bits 30 and
  6400. 31 are guaranteed equal. Bits 30 to 15 of this value (bit mask
  6401. `0x7FFF8000') are taken and stored in the corresponding position of the
  6402. destination operand, after first rounding the low bit (equivalent to
  6403. adding `0x4000' before extracting bits 30 to 15).
  6404.    For `PMULHRW', the destination operand is the first operand; for
  6405. `PMULHRIW' the destination operand is implied by the first operand in
  6406. the manner of `PADDSIW' (*Note Section A.115::).
  6407. File: nasm.info,  Node: Section A.124,  Next: Section A.125,  Prev: Section A.123,  Up: Appendix A
  6408. A.124. `PMULHW', `PMULLW': MMX Packed Multiply
  6409. **********************************************
  6410.      PMULHW mmxreg,r/m64           ; 0F E5 /r             [PENT,MMX]
  6411.      PMULLW mmxreg,r/m64           ; 0F D5 /r             [PENT,MMX]
  6412.    `PMULxW' treats its two inputs as vectors of four signed words. It
  6413. multiplies corresponding elements of the two operands, giving four
  6414. signed doubleword results.
  6415.    `PMULHW' then stores the top 16 bits of each doubleword in the
  6416. destination (first) operand; `PMULLW' stores the bottom 16 bits of each
  6417. doubleword in the destination operand.
  6418. File: nasm.info,  Node: Section A.125,  Next: Section A.126,  Prev: Section A.124,  Up: Appendix A
  6419. A.125. `PMVccZB': MMX Packed Conditional Move
  6420. *********************************************
  6421.      PMVZB mmxreg,mem64            ; 0F 58 /r             [CYRIX,MMX]
  6422.      PMVNZB mmxreg,mem64           ; 0F 5A /r             [CYRIX,MMX]
  6423.      PMVLZB mmxreg,mem64           ; 0F 5B /r             [CYRIX,MMX]
  6424.      PMVGEZB mmxreg,mem64          ; 0F 5C /r             [CYRIX,MMX]
  6425.    These instructions, specific to the Cyrix MMX extensions, perform
  6426. parallel conditional moves. The two input operands are treated as
  6427. vectors of eight bytes. Each byte of the destination (first) operand is
  6428. either written from the corresponding byte of the source (second)
  6429. operand, or left alone, depending on the value of the byte in the
  6430. *implied* operand (specified in the same way as `PADDSIW', in *Note
  6431. Section A.115::).
  6432.    `PMVZB' performs each move if the corresponding byte in the implied
  6433. operand is zero. `PMVNZB' moves if the byte is non-zero. `PMVLZB' moves
  6434. if the byte is less than zero, and `PMVGEZB' moves if the byte is
  6435. greater than or equal to zero.
  6436.    Note that these instructions cannot take a register as their second
  6437. source operand.
  6438. File: nasm.info,  Node: Section A.126,  Next: Section A.127,  Prev: Section A.125,  Up: Appendix A
  6439. A.126. `POP': Pop Data from Stack
  6440. *********************************
  6441.      POP reg16                     ; o16 58+r             [8086]
  6442.      POP reg32                     ; o32 58+r             [386]
  6443.      POP r/m16                     ; o16 8F /0            [8086]
  6444.      POP r/m32                     ; o32 8F /0            [386]
  6445.      POP CS                        ; 0F                   [8086,UNDOC]
  6446.      POP DS                        ; 1F                   [8086]
  6447.      POP ES                        ; 07                   [8086]
  6448.      POP SS                        ; 17                   [8086]
  6449.      POP FS                        ; 0F A1                [386]
  6450.      POP GS                        ; 0F A9                [386]
  6451.    `POP' loads a value from the stack (from `[SS:SP]' or `[SS:ESP]')
  6452. and then increments the stack pointer.
  6453.    The address-size attribute of the instruction determines whether `SP'
  6454. or `ESP' is used as the stack pointer: to deliberately override the
  6455. default given by the `BITS' setting, you can use an `a16' or `a32'
  6456. prefix.
  6457.    The operand-size attribute of the instruction determines whether the
  6458. stack pointer is incremented by 2 or 4: this means that segment
  6459. register pops in `BITS 32' mode will pop 4 bytes off the stack and
  6460. discard the upper two of them. If you need to override that, you can
  6461. use an `o16' or `o32' prefix.
  6462.    The above opcode listings give two forms for general-purpose
  6463. register pop instructions: for example, `POP BX' has the two forms `5B'
  6464. and `8F C3'. NASM will always generate the shorter form when given `POP
  6465. BX'. NDISASM will disassemble both.
  6466.    `POP CS' is not a documented instruction, and is not supported on any
  6467. processor above the 8086 (since they use `0Fh' as an opcode prefix for
  6468. instruction set extensions). However, at least some 8086 processors do
  6469. support it, and so NASM generates it for completeness.
  6470. File: nasm.info,  Node: Section A.127,  Next: Section A.128,  Prev: Section A.126,  Up: Appendix A
  6471. A.127. `POPAx': Pop All General-Purpose Registers
  6472. *************************************************
  6473.      POPA                          ; 61                   [186]
  6474.      POPAW                         ; o16 61               [186]
  6475.      POPAD                         ; o32 61               [386]
  6476.    `POPAW' pops a word from the stack into each of, successively, `DI',
  6477. `SI', `BP', nothing (it discards a word from the stack which was a
  6478. placeholder for `SP'), `BX', `DX', `CX' and `AX'. It is intended to
  6479. reverse the operation of `PUSHAW' (see *Note Section A.135::), but it
  6480. ignores the value for `SP' that was pushed on the stack by `PUSHAW'.
  6481.    `POPAD' pops twice as much data, and places the results in `EDI',
  6482. `ESI', `EBP', nothing (placeholder for `ESP'), `EBX', `EDX', `ECX' and
  6483. `EAX'. It reverses the operation of `PUSHAD'.
  6484.    `POPA' is an alias mnemonic for either `POPAW' or `POPAD', depending
  6485. on the current `BITS' setting.
  6486.    Note that the registers are popped in reverse order of their numeric
  6487. values in opcodes (see *Note Section A.2.1::).
  6488. File: nasm.info,  Node: Section A.128,  Next: Section A.129,  Prev: Section A.127,  Up: Appendix A
  6489. A.128. `POPFx': Pop Flags Register
  6490. **********************************
  6491.      POPF                          ; 9D                   [186]
  6492.      POPFW                         ; o16 9D               [186]
  6493.      POPFD                         ; o32 9D               [386]
  6494.    `POPFW' pops a word from the stack and stores it in the bottom 16
  6495. bits of the flags register (or the whole flags register, on processors
  6496. below a 386). `POPFD' pops a doubleword and stores it in the entire
  6497. flags register.
  6498.    `POPF' is an alias mnemonic for either `POPFW' or `POPFD', depending
  6499. on the current `BITS' setting.
  6500.    See also `PUSHF' (*Note Section A.136::).
  6501. File: nasm.info,  Node: Section A.129,  Next: Section A.130,  Prev: Section A.128,  Up: Appendix A
  6502. A.129. `POR': MMX Bitwise OR
  6503. ****************************
  6504.      POR mmxreg,r/m64              ; 0F EB /r             [PENT,MMX]
  6505.    `POR' performs a bitwise OR operation between its two operands (i.e.
  6506. each bit of the result is 1 if and only if at least one of the
  6507. corresponding bits of the two inputs was 1), and stores the result in
  6508. the destination (first) operand.
  6509. File: nasm.info,  Node: Section A.130,  Next: Section A.131,  Prev: Section A.129,  Up: Appendix A
  6510. A.130. `PSLLx', `PSRLx', `PSRAx': MMX Bit Shifts
  6511. ************************************************
  6512.      PSLLW mmxreg,r/m64            ; 0F F1 /r             [PENT,MMX]
  6513.      PSLLW mmxreg,imm8             ; 0F 71 /6 ib          [PENT,MMX]
  6514.      PSLLD mmxreg,r/m64            ; 0F F2 /r             [PENT,MMX]
  6515.      PSLLD mmxreg,imm8             ; 0F 72 /6 ib          [PENT,MMX]
  6516.      PSLLQ mmxreg,r/m64            ; 0F F3 /r             [PENT,MMX]
  6517.      PSLLQ mmxreg,imm8             ; 0F 73 /6 ib          [PENT,MMX]
  6518.      PSRAW mmxreg,r/m64            ; 0F E1 /r             [PENT,MMX]
  6519.      PSRAW mmxreg,imm8             ; 0F 71 /4 ib          [PENT,MMX]
  6520.      PSRAD mmxreg,r/m64            ; 0F E2 /r             [PENT,MMX]
  6521.      PSRAD mmxreg,imm8             ; 0F 72 /4 ib          [PENT,MMX]
  6522.      PSRLW mmxreg,r/m64            ; 0F D1 /r             [PENT,MMX]
  6523.      PSRLW mmxreg,imm8             ; 0F 71 /2 ib          [PENT,MMX]
  6524.      PSRLD mmxreg,r/m64            ; 0F D2 /r             [PENT,MMX]
  6525.      PSRLD mmxreg,imm8             ; 0F 72 /2 ib          [PENT,MMX]
  6526.      PSRLQ mmxreg,r/m64            ; 0F D3 /r             [PENT,MMX]
  6527.      PSRLQ mmxreg,imm8             ; 0F 73 /2 ib          [PENT,MMX]
  6528.    `PSxxQ' perform simple bit shifts on the 64-bit MMX registers: the
  6529. destination (first) operand is shifted left or right by the number of
  6530. bits given in the source (second) operand, and the vacated bits are
  6531. filled in with zeros (for a logical shift) or copies of the original
  6532. sign bit (for an arithmetic right shift).
  6533.    `PSxxW' and `PSxxD' perform packed bit shifts: the destination
  6534. operand is treated as a vector of four words or two doublewords, and
  6535. each element is shifted individually, so bits shifted out of one
  6536. element do not interfere with empty bits coming into the next.
  6537.    `PSLLx' and `PSRLx' perform logical shifts: the vacated bits at one
  6538. end of the shifted number are filled with zeros. `PSRAx' performs an
  6539. arithmetic right shift: the vacated bits at the top of the shifted
  6540. number are filled with copies of the original top (sign) bit.
  6541. File: nasm.info,  Node: Section A.131,  Next: Section A.132,  Prev: Section A.130,  Up: Appendix A
  6542. A.131. `PSUBxx': MMX Packed Subtraction
  6543. ***************************************
  6544.      PSUBB mmxreg,r/m64            ; 0F F8 /r             [PENT,MMX]
  6545.      PSUBW mmxreg,r/m64            ; 0F F9 /r             [PENT,MMX]
  6546.      PSUBD mmxreg,r/m64            ; 0F FA /r             [PENT,MMX]
  6547.      PSUBSB mmxreg,r/m64           ; 0F E8 /r             [PENT,MMX]
  6548.      PSUBSW mmxreg,r/m64           ; 0F E9 /r             [PENT,MMX]
  6549.      PSUBUSB mmxreg,r/m64          ; 0F D8 /r             [PENT,MMX]
  6550.      PSUBUSW mmxreg,r/m64          ; 0F D9 /r             [PENT,MMX]
  6551.    `PSUBxx' all perform packed subtraction between their two 64-bit
  6552. operands, storing the result in the destination (first) operand. The
  6553. `PSUBxB' forms treat the 64-bit operands as vectors of eight bytes, and
  6554. subtract each byte individually; `PSUBxW' treat the operands as vectors
  6555. of four words; and `PSUBD' treats its operands as vectors of two
  6556. doublewords.
  6557.    In all cases, the elements of the operand on the right are
  6558. subtracted from the corresponding elements of the operand on the left,
  6559. not the other way round.
  6560.    `PSUBSB' and `PSUBSW' perform signed saturation on the sum of each
  6561. pair of bytes or words: if the result of a subtraction is too large or
  6562. too small to fit into a signed byte or word result, it is clipped
  6563. (saturated) to the largest or smallest value which *will* fit.
  6564. `PSUBUSB' and `PSUBUSW' similarly perform unsigned saturation, clipping
  6565. to `0FFh' or `0FFFFh' if the result is larger than that.
  6566. File: nasm.info,  Node: Section A.132,  Next: Section A.133,  Prev: Section A.131,  Up: Appendix A
  6567. A.132. `PSUBSIW': MMX Packed Subtract with Saturation to Implied Destination
  6568. ****************************************************************************
  6569.      PSUBSIW mmxreg,r/m64          ; 0F 55 /r             [CYRIX,MMX]
  6570.    `PSUBSIW', specific to the Cyrix extensions to the MMX instruction
  6571. set, performs the same function as `PSUBSW', except that the result is
  6572. not placed in the register specified by the first operand, but instead
  6573. in the implied destination register, specified as for `PADDSIW' (*Note
  6574. Section A.115::).
  6575. File: nasm.info,  Node: Section A.133,  Next: Section A.134,  Prev: Section A.132,  Up: Appendix A
  6576. A.133. `PUNPCKxxx': Unpack Data
  6577. *******************************
  6578.      PUNPCKHBW mmxreg,r/m64        ; 0F 68 /r             [PENT,MMX]
  6579.      PUNPCKHWD mmxreg,r/m64        ; 0F 69 /r             [PENT,MMX]
  6580.      PUNPCKHDQ mmxreg,r/m64        ; 0F 6A /r             [PENT,MMX]
  6581.      PUNPCKLBW mmxreg,r/m64        ; 0F 60 /r             [PENT,MMX]
  6582.      PUNPCKLWD mmxreg,r/m64        ; 0F 61 /r             [PENT,MMX]
  6583.      PUNPCKLDQ mmxreg,r/m64        ; 0F 62 /r             [PENT,MMX]
  6584.    `PUNPCKxx' all treat their operands as vectors, and produce a new
  6585. vector generated by interleaving elements from the two inputs. The
  6586. `PUNPCKHxx' instructions start by throwing away the bottom half of each
  6587. input operand, and the `PUNPCKLxx' instructions throw away the top half.
  6588.    The remaining elements, totalling 64 bits, are then interleaved into
  6589. the destination, alternating elements from the second (source) operand
  6590. and the first (destination) operand: so the leftmost element in the
  6591. result always comes from the second operand, and the rightmost from the
  6592. destination.
  6593.    `PUNPCKxBW' works a byte at a time, `PUNPCKxWD' a word at a time,
  6594. and `PUNPCKxDQ' a doubleword at a time.
  6595.    So, for example, if the first operand held `0x7A6A5A4A3A2A1A0A' and
  6596. the second held `0x7B6B5B4B3B2B1B0B', then:
  6597.    * `PUNPCKHBW' would return `0x7B7A6B6A5B5A4B4A'.
  6598.    * `PUNPCKHWD' would return `0x7B6B7A6A5B4B5A4A'.
  6599.    * `PUNPCKHDQ' would return `0x7B6B5B4B7A6A5A4A'.
  6600.    * `PUNPCKLBW' would return `0x3B3A2B2A1B1A0B0A'.
  6601.    * `PUNPCKLWD' would return `0x3B2B3A2A1B0B1A0A'.
  6602.    * `PUNPCKLDQ' would return `0x3B2B1B0B3A2A1A0A'.
  6603. File: nasm.info,  Node: Section A.134,  Next: Section A.135,  Prev: Section A.133,  Up: Appendix A
  6604. A.134. `PUSH': Push Data on Stack
  6605. *********************************
  6606.      PUSH reg16                    ; o16 50+r             [8086]
  6607.      PUSH reg32                    ; o32 50+r             [386]
  6608.      PUSH r/m16                    ; o16 FF /6            [8086]
  6609.      PUSH r/m32                    ; o32 FF /6            [386]
  6610.      PUSH CS                       ; 0E                   [8086]
  6611.      PUSH DS                       ; 1E                   [8086]
  6612.      PUSH ES                       ; 06                   [8086]
  6613.      PUSH SS                       ; 16                   [8086]
  6614.      PUSH FS                       ; 0F A0                [386]
  6615.      PUSH GS                       ; 0F A8                [386]
  6616.      PUSH imm8                     ; 6A ib                [286]
  6617.      PUSH imm16                    ; o16 68 iw            [286]
  6618.      PUSH imm32                    ; o32 68 id            [386]
  6619.    `PUSH' decrements the stack pointer (`SP' or `ESP') by 2 or 4, and
  6620. then stores the given value at `[SS:SP]' or `[SS:ESP]'.
  6621.    The address-size attribute of the instruction determines whether `SP'
  6622. or `ESP' is used as the stack pointer: to deliberately override the
  6623. default given by the `BITS' setting, you can use an `a16' or `a32'
  6624. prefix.
  6625.    The operand-size attribute of the instruction determines whether the
  6626. stack pointer is decremented by 2 or 4: this means that segment
  6627. register pushes in `BITS 32' mode will push 4 bytes on the stack, of
  6628. which the upper two are undefined. If you need to override that, you
  6629. can use an `o16' or `o32' prefix.
  6630.    The above opcode listings give two forms for general-purpose
  6631. register push instructions: for example, `PUSH BX' has the two forms
  6632. `53' and `FF F3'. NASM will always generate the shorter form when given
  6633. `PUSH BX'. NDISASM will disassemble both.
  6634.    Unlike the undocumented and barely supported `POP CS', `PUSH CS' is
  6635. a perfectly valid and sensible instruction, supported on all processors.
  6636.    The instruction `PUSH SP' may be used to distinguish an 8086 from
  6637. later processors: on an 8086, the value of `SP' stored is the value it
  6638. has *after* the push instruction, whereas on later processors it is the
  6639. value *before* the push instruction.
  6640. File: nasm.info,  Node: Section A.135,  Next: Section A.136,  Prev: Section A.134,  Up: Appendix A
  6641. A.135. `PUSHAx': Push All General-Purpose Registers
  6642. ***************************************************
  6643.      PUSHA                         ; 60                   [186]
  6644.      PUSHAD                        ; o32 60               [386]
  6645.      PUSHAW                        ; o16 60               [186]
  6646.    `PUSHAW' pushes, in succession, `AX', `CX', `DX', `BX', `SP', `BP',
  6647. `SI' and `DI' on the stack, decrementing the stack pointer by a total
  6648. of 16.
  6649.    `PUSHAD' pushes, in succession, `EAX', `ECX', `EDX', `EBX', `ESP',
  6650. `EBP', `ESI' and `EDI' on the stack, decrementing the stack pointer by
  6651. a total of 32.
  6652.    In both cases, the value of `SP' or `ESP' pushed is its *original*
  6653. value, as it had before the instruction was executed.
  6654.    `PUSHA' is an alias mnemonic for either `PUSHAW' or `PUSHAD',
  6655. depending on the current `BITS' setting.
  6656.    Note that the registers are pushed in order of their numeric values
  6657. in opcodes (see *Note Section A.2.1::).
  6658.    See also `POPA' (*Note Section A.127::).
  6659. File: nasm.info,  Node: Section A.136,  Next: Section A.137,  Prev: Section A.135,  Up: Appendix A
  6660. A.136. `PUSHFx': Push Flags Register
  6661. ************************************
  6662.      PUSHF                         ; 9C                   [186]
  6663.      PUSHFD                        ; o32 9C               [386]
  6664.      PUSHFW                        ; o16 9C               [186]
  6665.    `PUSHFW' pops a word from the stack and stores it in the bottom 16
  6666. bits of the flags register (or the whole flags register, on processors
  6667. below a 386). `PUSHFD' pops a doubleword and stores it in the entire
  6668. flags register.
  6669.    `PUSHF' is an alias mnemonic for either `PUSHFW' or `PUSHFD',
  6670. depending on the current `BITS' setting.
  6671.    See also `POPF' (*Note Section A.128::).
  6672. File: nasm.info,  Node: Section A.137,  Next: Section A.138,  Prev: Section A.136,  Up: Appendix A
  6673. A.137. `PXOR': MMX Bitwise XOR
  6674. ******************************
  6675.      PXOR mmxreg,r/m64             ; 0F EF /r             [PENT,MMX]
  6676.    `PXOR' performs a bitwise XOR operation between its two operands
  6677. (i.e.  each bit of the result is 1 if and only if exactly one of the
  6678. corresponding bits of the two inputs was 1), and stores the result in
  6679. the destination (first) operand.
  6680. File: nasm.info,  Node: Section A.138,  Next: Section A.139,  Prev: Section A.137,  Up: Appendix A
  6681. A.138. `RCL', `RCR': Bitwise Rotate through Carry Bit
  6682. *****************************************************
  6683.      RCL r/m8,1                    ; D0 /2                [8086]
  6684.      RCL r/m8,CL                   ; D2 /2                [8086]
  6685.      RCL r/m8,imm8                 ; C0 /2 ib             [286]
  6686.      RCL r/m16,1                   ; o16 D1 /2            [8086]
  6687.      RCL r/m16,CL                  ; o16 D3 /2            [8086]
  6688.      RCL r/m16,imm8                ; o16 C1 /2 ib         [286]
  6689.      RCL r/m32,1                   ; o32 D1 /2            [386]
  6690.      RCL r/m32,CL                  ; o32 D3 /2            [386]
  6691.      RCL r/m32,imm8                ; o32 C1 /2 ib         [386]
  6692.      RCR r/m8,1                    ; D0 /3                [8086]
  6693.      RCR r/m8,CL                   ; D2 /3                [8086]
  6694.      RCR r/m8,imm8                 ; C0 /3 ib             [286]
  6695.      RCR r/m16,1                   ; o16 D1 /3            [8086]
  6696.      RCR r/m16,CL                  ; o16 D3 /3            [8086]
  6697.      RCR r/m16,imm8                ; o16 C1 /3 ib         [286]
  6698.      RCR r/m32,1                   ; o32 D1 /3            [386]
  6699.      RCR r/m32,CL                  ; o32 D3 /3            [386]
  6700.      RCR r/m32,imm8                ; o32 C1 /3 ib         [386]
  6701.    `RCL' and `RCR' perform a 9-bit, 17-bit or 33-bit bitwise rotation
  6702. operation, involving the given source/destination (first) operand and
  6703. the carry bit. Thus, for example, in the operation `RCR AL,1', a 9-bit
  6704. rotation is performed in which `AL' is shifted left by 1, the top bit
  6705. of `AL' moves into the carry flag, and the original value of the carry
  6706. flag is placed in the low bit of `AL'.
  6707.    The number of bits to rotate by is given by the second operand. Only
  6708. the bottom five bits of the rotation count are considered by processors
  6709. above the 8086.
  6710.    You can force the longer (286 and upwards, beginning with a `C1'
  6711. byte) form of `RCL foo,1' by using a `BYTE' prefix: `RCL foo,BYTE 1'.
  6712. Similarly with `RCR'.
  6713. File: nasm.info,  Node: Section A.139,  Next: Section A.140,  Prev: Section A.138,  Up: Appendix A
  6714. A.139. `RDMSR': Read Model-Specific Registers
  6715. *********************************************
  6716.      RDMSR                         ; 0F 32                [PENT]
  6717.    `RDMSR' reads the processor Model-Specific Register (MSR) whose index
  6718. is stored in `ECX', and stores the result in `EDX:EAX'. See also
  6719. `WRMSR' (*Note Section A.165::).
  6720. File: nasm.info,  Node: Section A.140,  Next: Section A.141,  Prev: Section A.139,  Up: Appendix A
  6721. A.140. `RDPMC': Read Performance-Monitoring Counters
  6722. ****************************************************
  6723.      RDPMC                         ; 0F 33                [P6]
  6724.    `RDPMC' reads the processor performance-monitoring counter whose
  6725. index is stored in `ECX', and stores the result in `EDX:EAX'.
  6726. File: nasm.info,  Node: Section A.141,  Next: Section A.142,  Prev: Section A.140,  Up: Appendix A
  6727. A.141. `RDTSC': Read Time-Stamp Counter
  6728. ***************************************
  6729.      RDTSC                         ; 0F 31                [PENT]
  6730.    `RDTSC' reads the processor's time-stamp counter into `EDX:EAX'.
  6731. File: nasm.info,  Node: Section A.142,  Next: Section A.143,  Prev: Section A.141,  Up: Appendix A
  6732. A.142. `RET', `RETF', `RETN': Return from Procedure Call
  6733. ********************************************************
  6734.      RET                           ; C3                   [8086]
  6735.      RET imm16                     ; C2 iw                [8086]
  6736.      RETF                          ; CB                   [8086]
  6737.      RETF imm16                    ; CA iw                [8086]
  6738.      RETN                          ; C3                   [8086]
  6739.      RETN imm16                    ; C2 iw                [8086]
  6740.    `RET', and its exact synonym `RETN', pop `IP' or `EIP' from the
  6741. stack and transfer control to the new address. Optionally, if a numeric
  6742. second operand is provided, they increment the stack pointer by a
  6743. further `imm16' bytes after popping the return address.
  6744.    `RETF' executes a far return: after popping `IP'/`EIP', it then pops
  6745. `CS', and *then* increments the stack pointer by the optional argument
  6746. if present.
  6747. File: nasm.info,  Node: Section A.143,  Next: Section A.144,  Prev: Section A.142,  Up: Appendix A
  6748. A.143. `ROL', `ROR': Bitwise Rotate
  6749. ***********************************
  6750.      ROL r/m8,1                    ; D0 /0                [8086]
  6751.      ROL r/m8,CL                   ; D2 /0                [8086]
  6752.      ROL r/m8,imm8                 ; C0 /0 ib             [286]
  6753.      ROL r/m16,1                   ; o16 D1 /0            [8086]
  6754.      ROL r/m16,CL                  ; o16 D3 /0            [8086]
  6755.      ROL r/m16,imm8                ; o16 C1 /0 ib         [286]
  6756.      ROL r/m32,1                   ; o32 D1 /0            [386]
  6757.      ROL r/m32,CL                  ; o32 D3 /0            [386]
  6758.      ROL r/m32,imm8                ; o32 C1 /0 ib         [386]
  6759.      ROR r/m8,1                    ; D0 /1                [8086]
  6760.      ROR r/m8,CL                   ; D2 /1                [8086]
  6761.      ROR r/m8,imm8                 ; C0 /1 ib             [286]
  6762.      ROR r/m16,1                   ; o16 D1 /1            [8086]
  6763.      ROR r/m16,CL                  ; o16 D3 /1            [8086]
  6764.      ROR r/m16,imm8                ; o16 C1 /1 ib         [286]
  6765.      ROR r/m32,1                   ; o32 D1 /1            [386]
  6766.      ROR r/m32,CL                  ; o32 D3 /1            [386]
  6767.      ROR r/m32,imm8                ; o32 C1 /1 ib         [386]
  6768.    `ROL' and `ROR' perform a bitwise rotation operation on the given
  6769. source/destination (first) operand. Thus, for example, in the operation
  6770. `ROR AL,1', an 8-bit rotation is performed in which `AL' is shifted
  6771. left by 1 and the original top bit of `AL' moves round into the low bit.
  6772.    The number of bits to rotate by is given by the second operand. Only
  6773. the bottom 3, 4 or 5 bits (depending on the source operand size) of the
  6774. rotation count are considered by processors above the 8086.
  6775.    You can force the longer (286 and upwards, beginning with a `C1'
  6776. byte) form of `ROL foo,1' by using a `BYTE' prefix: `ROL foo,BYTE 1'.
  6777. Similarly with `ROR'.
  6778. File: nasm.info,  Node: Section A.144,  Next: Section A.145,  Prev: Section A.143,  Up: Appendix A
  6779. A.144. `RSM': Resume from System-Management Mode
  6780. ************************************************
  6781.      RSM                           ; 0F AA                [PENT]
  6782.    `RSM' returns the processor to its normal operating mode when it was
  6783. in System-Management Mode.
  6784. File: nasm.info,  Node: Section A.145,  Next: Section A.146,  Prev: Section A.144,  Up: Appendix A
  6785. A.145. `SAHF': Store AH to Flags
  6786. ********************************
  6787.      SAHF                          ; 9E                   [8086]
  6788.    `SAHF' sets the low byte of the flags word according to the contents
  6789. of the `AH' register. See also `LAHF' (*Note Section A.90::).
  6790. File: nasm.info,  Node: Section A.146,  Next: Section A.147,  Prev: Section A.145,  Up: Appendix A
  6791. A.146. `SAL', `SAR': Bitwise Arithmetic Shifts
  6792. **********************************************
  6793.      SAL r/m8,1                    ; D0 /4                [8086]
  6794.      SAL r/m8,CL                   ; D2 /4                [8086]
  6795.      SAL r/m8,imm8                 ; C0 /4 ib             [286]
  6796.      SAL r/m16,1                   ; o16 D1 /4            [8086]
  6797.      SAL r/m16,CL                  ; o16 D3 /4            [8086]
  6798.      SAL r/m16,imm8                ; o16 C1 /4 ib         [286]
  6799.      SAL r/m32,1                   ; o32 D1 /4            [386]
  6800.      SAL r/m32,CL                  ; o32 D3 /4            [386]
  6801.      SAL r/m32,imm8                ; o32 C1 /4 ib         [386]
  6802.      SAR r/m8,1                    ; D0 /0                [8086]
  6803.      SAR r/m8,CL                   ; D2 /0                [8086]
  6804.      SAR r/m8,imm8                 ; C0 /0 ib             [286]
  6805.      SAR r/m16,1                   ; o16 D1 /0            [8086]
  6806.      SAR r/m16,CL                  ; o16 D3 /0            [8086]
  6807.      SAR r/m16,imm8                ; o16 C1 /0 ib         [286]
  6808.      SAR r/m32,1                   ; o32 D1 /0            [386]
  6809.      SAR r/m32,CL                  ; o32 D3 /0            [386]
  6810.      SAR r/m32,imm8                ; o32 C1 /0 ib         [386]
  6811.    `SAL' and `SAR' perform an arithmetic shift operation on the given
  6812. source/destination (first) operand. The vacated bits are filled with
  6813. zero for `SAL', and with copies of the original high bit of the source
  6814. operand for `SAR'.
  6815.    `SAL' is a synonym for `SHL' (see *Note Section A.152::). NASM will
  6816. assemble either one to the same code, but NDISASM will always
  6817. disassemble that code as `SHL'.
  6818.    The number of bits to shift by is given by the second operand. Only
  6819. the bottom 3, 4 or 5 bits (depending on the source operand size) of the
  6820. shift count are considered by processors above the 8086.
  6821.    You can force the longer (286 and upwards, beginning with a `C1'
  6822. byte) form of `SAL foo,1' by using a `BYTE' prefix: `SAL foo,BYTE 1'.
  6823. Similarly with `SAR'.
  6824. File: nasm.info,  Node: Section A.147,  Next: Section A.148,  Prev: Section A.146,  Up: Appendix A
  6825. A.147. `SALC': Set AL from Carry Flag
  6826. *************************************
  6827.      SALC                          ; D6                   [8086,UNDOC]
  6828.    `SALC' is an early undocumented instruction similar in concept to
  6829. `SETcc' (*Note Section A.150::). Its function is to set `AL' to zero if
  6830. the carry flag is clear, or to `0xFF' if it is set.
  6831. File: nasm.info,  Node: Section A.148,  Next: Section A.149,  Prev: Section A.147,  Up: Appendix A
  6832. A.148. `SBB': Subtract with Borrow
  6833. **********************************
  6834.      SBB r/m8,reg8                 ; 18 /r                [8086]
  6835.      SBB r/m16,reg16               ; o16 19 /r            [8086]
  6836.      SBB r/m32,reg32               ; o32 19 /r            [386]
  6837.      SBB reg8,r/m8                 ; 1A /r                [8086]
  6838.      SBB reg16,r/m16               ; o16 1B /r            [8086]
  6839.      SBB reg32,r/m32               ; o32 1B /r            [386]
  6840.      SBB r/m8,imm8                 ; 80 /3 ib             [8086]
  6841.      SBB r/m16,imm16               ; o16 81 /3 iw         [8086]
  6842.      SBB r/m32,imm32               ; o32 81 /3 id         [386]
  6843.      SBB r/m16,imm8                ; o16 83 /3 ib         [8086]
  6844.      SBB r/m32,imm8                ; o32 83 /3 ib         [8086]
  6845.      SBB AL,imm8                   ; 1C ib                [8086]
  6846.      SBB AX,imm16                  ; o16 1D iw            [8086]
  6847.      SBB EAX,imm32                 ; o32 1D id            [386]
  6848.    `SBB' performs integer subtraction: it subtracts its second operand,
  6849. plus the value of the carry flag, from its first, and leaves the result
  6850. in its destination (first) operand. The flags are set according to the
  6851. result of the operation: in particular, the carry flag is affected and
  6852. can be used by a subsequent `SBB' instruction.
  6853.    In the forms with an 8-bit immediate second operand and a longer
  6854. first operand, the second operand is considered to be signed, and is
  6855. sign- extended to the length of the first operand. In these cases, the
  6856. `BYTE' qualifier is necessary to force NASM to generate this form of
  6857. the instruction.
  6858.    To subtract one number from another without also subtracting the
  6859. contents of the carry flag, use `SUB' (*Note Section A.159::).
  6860. File: nasm.info,  Node: Section A.149,  Next: Section A.150,  Prev: Section A.148,  Up: Appendix A
  6861. A.149. `SCASB', `SCASW', `SCASD': Scan String
  6862. *********************************************
  6863.      SCASB                         ; AE                   [8086]
  6864.      SCASW                         ; o16 AF               [8086]
  6865.      SCASD                         ; o32 AF               [386]
  6866.    `SCASB' compares the byte in `AL' with the byte at `[ES:DI]' or
  6867. `[ES:EDI]', and sets the flags accordingly. It then increments or
  6868. decrements (depending on the direction flag: increments if the flag is
  6869. clear, decrements if it is set) `DI' (or `EDI').
  6870.    The register used is `DI' if the address size is 16 bits, and `EDI'
  6871. if it is 32 bits. If you need to use an address size not equal to the
  6872. current `BITS' setting, you can use an explicit `a16' or `a32' prefix.
  6873.    Segment override prefixes have no effect for this instruction: the
  6874. use of `ES' for the load from `[DI]' or `[EDI]' cannot be overridden.
  6875.    `SCASW' and `SCASD' work in the same way, but they compare a word to
  6876. `AX' or a doubleword to `EAX' instead of a byte to `AL', and increment
  6877. or decrement the addressing registers by 2 or 4 instead of 1.
  6878.    The `REPE' and `REPNE' prefixes (equivalently, `REPZ' and `REPNZ')
  6879. may be used to repeat the instruction up to `CX' (or `ECX' - again, the
  6880. address size chooses which) times until the first unequal or equal byte
  6881. is found.
  6882. File: nasm.info,  Node: Section A.150,  Next: Section A.151,  Prev: Section A.149,  Up: Appendix A
  6883. A.150. `SETcc': Set Register from Condition
  6884. *******************************************
  6885.      SETcc r/m8                    ; 0F 90+cc /2          [386]
  6886.    `SETcc' sets the given 8-bit operand to zero if its condition is not
  6887. satisfied, and to 1 if it is.
  6888. File: nasm.info,  Node: Section A.151,  Next: Section A.152,  Prev: Section A.150,  Up: Appendix A
  6889. A.151. `SGDT', `SIDT', `SLDT': Store Descriptor Table Pointers
  6890. **************************************************************
  6891.      SGDT mem                      ; 0F 01 /0             [286,PRIV]
  6892.      SIDT mem                      ; 0F 01 /1             [286,PRIV]
  6893.      SLDT r/m16                    ; 0F 00 /0             [286,PRIV]
  6894.    `SGDT' and `SIDT' both take a 6-byte memory area as an operand: they
  6895. store the contents of the GDTR (global descriptor table register) or
  6896. IDTR (interrupt descriptor table register) into that area as a 32-bit
  6897. linear address and a 16-bit size limit from that area (in that order).
  6898. These are the only instructions which directly use *linear* addresses,
  6899. rather than segment/offset pairs.
  6900.    `SLDT' stores the segment selector corresponding to the LDT (local
  6901. descriptor table) into the given operand.
  6902.    See also `LGDT', `LIDT' and `LLDT' (*Note Section A.95::).
  6903. File: nasm.info,  Node: Section A.152,  Next: Section A.153,  Prev: Section A.151,  Up: Appendix A
  6904. A.152. `SHL', `SHR': Bitwise Logical Shifts
  6905. *******************************************
  6906.      SHL r/m8,1                    ; D0 /4                [8086]
  6907.      SHL r/m8,CL                   ; D2 /4                [8086]
  6908.      SHL r/m8,imm8                 ; C0 /4 ib             [286]
  6909.      SHL r/m16,1                   ; o16 D1 /4            [8086]
  6910.      SHL r/m16,CL                  ; o16 D3 /4            [8086]
  6911.      SHL r/m16,imm8                ; o16 C1 /4 ib         [286]
  6912.      SHL r/m32,1                   ; o32 D1 /4            [386]
  6913.      SHL r/m32,CL                  ; o32 D3 /4            [386]
  6914.      SHL r/m32,imm8                ; o32 C1 /4 ib         [386]
  6915.      SHR r/m8,1                    ; D0 /5                [8086]
  6916.      SHR r/m8,CL                   ; D2 /5                [8086]
  6917.      SHR r/m8,imm8                 ; C0 /5 ib             [286]
  6918.      SHR r/m16,1                   ; o16 D1 /5            [8086]
  6919.      SHR r/m16,CL                  ; o16 D3 /5            [8086]
  6920.      SHR r/m16,imm8                ; o16 C1 /5 ib         [286]
  6921.      SHR r/m32,1                   ; o32 D1 /5            [386]
  6922.      SHR r/m32,CL                  ; o32 D3 /5            [386]
  6923.      SHR r/m32,imm8                ; o32 C1 /5 ib         [386]
  6924.    `SHL' and `SHR' perform a logical shift operation on the given
  6925. source/destination (first) operand. The vacated bits are filled with
  6926. zero.
  6927.    A synonym for `SHL' is `SAL' (see *Note Section A.146::). NASM will
  6928. assemble either one to the same code, but NDISASM will always
  6929. disassemble that code as `SHL'.
  6930.    The number of bits to shift by is given by the second operand. Only
  6931. the bottom 3, 4 or 5 bits (depending on the source operand size) of the
  6932. shift count are considered by processors above the 8086.
  6933.    You can force the longer (286 and upwards, beginning with a `C1'
  6934. byte) form of `SHL foo,1' by using a `BYTE' prefix: `SHL foo,BYTE 1'.
  6935. Similarly with `SHR'.
  6936. File: nasm.info,  Node: Section A.153,  Next: Section A.154,  Prev: Section A.152,  Up: Appendix A
  6937. A.153. `SHLD', `SHRD': Bitwise Double-Precision Shifts
  6938. ******************************************************
  6939.      SHLD r/m16,reg16,imm8         ; o16 0F A4 /r ib      [386]
  6940.      SHLD r/m16,reg32,imm8         ; o32 0F A4 /r ib      [386]
  6941.      SHLD r/m16,reg16,CL           ; o16 0F A5 /r         [386]
  6942.      SHLD r/m16,reg32,CL           ; o32 0F A5 /r         [386]
  6943.      SHRD r/m16,reg16,imm8         ; o16 0F AC /r ib      [386]
  6944.      SHRD r/m32,reg32,imm8         ; o32 0F AC /r ib      [386]
  6945.      SHRD r/m16,reg16,CL           ; o16 0F AD /r         [386]
  6946.      SHRD r/m32,reg32,CL           ; o32 0F AD /r         [386]
  6947.    `SHLD' performs a double-precision left shift. It notionally places
  6948. its second operand to the right of its first, then shifts the entire bit
  6949. string thus generated to the left by a number of bits specified in the
  6950. third operand. It then updates only the *first* operand according to
  6951. the result of this. The second operand is not modified.
  6952.    `SHRD' performs the corresponding right shift: it notionally places
  6953. the second operand to the *left* of the first, shifts the whole bit
  6954. string right, and updates only the first operand.
  6955.    For example, if `EAX' holds `0x01234567' and `EBX' holds
  6956. `0x89ABCDEF', then the instruction `SHLD EAX,EBX,4' would update `EAX'
  6957. to hold `0x12345678'. Under the same conditions, `SHRD EAX,EBX,4' would
  6958. update `EAX' to hold `0xF0123456'.
  6959.    The number of bits to shift by is given by the third operand. Only
  6960. the bottom 5 bits of the shift count are considered.
  6961. File: nasm.info,  Node: Section A.154,  Next: Section A.155,  Prev: Section A.153,  Up: Appendix A
  6962. A.154. `SMI': System Management Interrupt
  6963. *****************************************
  6964.      SMI                           ; F1                   [386,UNDOC]
  6965.    This is an opcode apparently supported by some AMD processors (which
  6966. is why it can generate the same opcode as `INT1'), and places the
  6967. machine into system-management mode, a special debugging mode.
  6968. File: nasm.info,  Node: Section A.155,  Next: Section A.156,  Prev: Section A.154,  Up: Appendix A
  6969. A.155. `SMSW': Store Machine Status Word
  6970. ****************************************
  6971.      SMSW r/m16                    ; 0F 01 /4             [286,PRIV]
  6972.    `SMSW' stores the bottom half of the `CR0' control register (or the
  6973. Machine Status Word, on 286 processors) into the destination operand.
  6974. See also `LMSW' (*Note Section A.96::).
  6975. File: nasm.info,  Node: Section A.156,  Next: Section A.157,  Prev: Section A.155,  Up: Appendix A
  6976. A.156. `STC', `STD', `STI': Set Flags
  6977. *************************************
  6978.      STC                           ; F9                   [8086]
  6979.      STD                           ; FD                   [8086]
  6980.      STI                           ; FB                   [8086]
  6981.    These instructions set various flags. `STC' sets the carry flag;
  6982. `STD' sets the direction flag; and `STI' sets the interrupt flag (thus
  6983. enabling interrupts).
  6984.    To clear the carry, direction, or interrupt flags, use the `CLC',
  6985. `CLD' and `CLI' instructions (*Note Section A.15::). To invert the
  6986. carry flag, use `CMC' (*Note Section A.16::).
  6987. File: nasm.info,  Node: Section A.157,  Next: Section A.158,  Prev: Section A.156,  Up: Appendix A
  6988. A.157. `STOSB', `STOSW', `STOSD': Store Byte to String
  6989. ******************************************************
  6990.      STOSB                         ; AA                   [8086]
  6991.      STOSW                         ; o16 AB               [8086]
  6992.      STOSD                         ; o32 AB               [386]
  6993.    `STOSB' stores the byte in `AL' at `[ES:DI]' or `[ES:EDI]', and sets
  6994. the flags accordingly. It then increments or decrements (depending on
  6995. the direction flag: increments if the flag is clear, decrements if it
  6996. is set) `DI' (or `EDI').
  6997.    The register used is `DI' if the address size is 16 bits, and `EDI'
  6998. if it is 32 bits. If you need to use an address size not equal to the
  6999. current `BITS' setting, you can use an explicit `a16' or `a32' prefix.
  7000.    Segment override prefixes have no effect for this instruction: the
  7001. use of `ES' for the store to `[DI]' or `[EDI]' cannot be overridden.
  7002.    `STOSW' and `STOSD' work in the same way, but they store the word in
  7003. `AX' or the doubleword in `EAX' instead of the byte in `AL', and
  7004. increment or decrement the addressing registers by 2 or 4 instead of 1.
  7005.    The `REP' prefix may be used to repeat the instruction `CX' (or
  7006. `ECX' - again, the address size chooses which) times.
  7007. File: nasm.info,  Node: Section A.158,  Next: Section A.159,  Prev: Section A.157,  Up: Appendix A
  7008. A.158. `STR': Store Task Register
  7009. *********************************
  7010.      STR r/m16                     ; 0F 00 /1             [286,PRIV]
  7011.    `STR' stores the segment selector corresponding to the contents of
  7012. the Task Register into its operand.
  7013. File: nasm.info,  Node: Section A.159,  Next: Section A.160,  Prev: Section A.158,  Up: Appendix A
  7014. A.159. `SUB': Subtract Integers
  7015. *******************************
  7016.      SUB r/m8,reg8                 ; 28 /r                [8086]
  7017.      SUB r/m16,reg16               ; o16 29 /r            [8086]
  7018.      SUB r/m32,reg32               ; o32 29 /r            [386]
  7019.      SUB reg8,r/m8                 ; 2A /r                [8086]
  7020.      SUB reg16,r/m16               ; o16 2B /r            [8086]
  7021.      SUB reg32,r/m32               ; o32 2B /r            [386]
  7022.      SUB r/m8,imm8                 ; 80 /5 ib             [8086]
  7023.      SUB r/m16,imm16               ; o16 81 /5 iw         [8086]
  7024.      SUB r/m32,imm32               ; o32 81 /5 id         [386]
  7025.      SUB r/m16,imm8                ; o16 83 /5 ib         [8086]
  7026.      SUB r/m32,imm8                ; o32 83 /5 ib         [386]
  7027.      SUB AL,imm8                   ; 2C ib                [8086]
  7028.      SUB AX,imm16                  ; o16 2D iw            [8086]
  7029.      SUB EAX,imm32                 ; o32 2D id            [386]
  7030.    `SUB' performs integer subtraction: it subtracts its second operand
  7031. from its first, and leaves the result in its destination (first)
  7032. operand.  The flags are set according to the result of the operation:
  7033. in particular, the carry flag is affected and can be used by a
  7034. subsequent `SBB' instruction (*Note Section A.148::).
  7035.    In the forms with an 8-bit immediate second operand and a longer
  7036. first operand, the second operand is considered to be signed, and is
  7037. sign- extended to the length of the first operand. In these cases, the
  7038. `BYTE' qualifier is necessary to force NASM to generate this form of
  7039. the instruction.
  7040. File: nasm.info,  Node: Section A.160,  Next: Section A.161,  Prev: Section A.159,  Up: Appendix A
  7041. A.160. `TEST': Test Bits (notional bitwise AND)
  7042. ***********************************************
  7043.      TEST r/m8,reg8                ; 84 /r                [8086]
  7044.      TEST r/m16,reg16              ; o16 85 /r            [8086]
  7045.      TEST r/m32,reg32              ; o32 85 /r            [386]
  7046.      TEST r/m8,imm8                ; F6 /7 ib             [8086]
  7047.      TEST r/m16,imm16              ; o16 F7 /7 iw         [8086]
  7048.      TEST r/m32,imm32              ; o32 F7 /7 id         [386]
  7049.      TEST AL,imm8                  ; A8 ib                [8086]
  7050.      TEST AX,imm16                 ; o16 A9 iw            [8086]
  7051.      TEST EAX,imm32                ; o32 A9 id            [386]
  7052.    `TEST' performs a `mental' bitwise AND of its two operands, and
  7053. affects the flags as if the operation had taken place, but does not
  7054. store the result of the operation anywhere.
  7055. File: nasm.info,  Node: Section A.161,  Next: Section A.162,  Prev: Section A.160,  Up: Appendix A
  7056. A.161. `UMOV': User Move Data
  7057. *****************************
  7058.      UMOV r/m8,reg8                ; 0F 10 /r             [386,UNDOC]
  7059.      UMOV r/m16,reg16              ; o16 0F 11 /r         [386,UNDOC]
  7060.      UMOV r/m32,reg32              ; o32 0F 11 /r         [386,UNDOC]
  7061.      UMOV reg8,r/m8                ; 0F 12 /r             [386,UNDOC]
  7062.      UMOV reg16,r/m16              ; o16 0F 13 /r         [386,UNDOC]
  7063.      UMOV reg32,r/m32              ; o32 0F 13 /r         [386,UNDOC]
  7064.    This undocumented instruction is used by in-circuit emulators to
  7065. access user memory (as opposed to host memory). It is used just like an
  7066. ordinary memory/register or register/register `MOV' instruction, but
  7067. accesses user space.
  7068. File: nasm.info,  Node: Section A.162,  Next: Section A.163,  Prev: Section A.161,  Up: Appendix A
  7069. A.162. `VERR', `VERW': Verify Segment Readability/Writability
  7070. *************************************************************
  7071.      VERR r/m16                    ; 0F 00 /4             [286,PRIV]
  7072.      VERW r/m16                    ; 0F 00 /5             [286,PRIV]
  7073.    `VERR' sets the zero flag if the segment specified by the selector in
  7074. its operand can be read from at the current privilege level. `VERW'
  7075. sets the zero flag if the segment can be written.
  7076. File: nasm.info,  Node: Section A.163,  Next: Section A.164,  Prev: Section A.162,  Up: Appendix A
  7077. A.163. `WAIT': Wait for Floating-Point Processor
  7078. ************************************************
  7079.      WAIT                          ; 9B                   [8086]
  7080.    `WAIT', on 8086 systems with a separate 8087 FPU, waits for the FPU
  7081. to have finished any operation it is engaged in before continuing main
  7082. processor operations, so that (for example) an FPU store to main memory
  7083. can be guaranteed to have completed before the CPU tries to read the
  7084. result back out.
  7085.    On higher processors, `WAIT' is unnecessary for this purpose, and it
  7086. has the alternative purpose of ensuring that any pending unmasked FPU
  7087. exceptions have happened before execution continues.
  7088. File: nasm.info,  Node: Section A.164,  Next: Section A.165,  Prev: Section A.163,  Up: Appendix A
  7089. A.164. `WBINVD': Write Back and Invalidate Cache
  7090. ************************************************
  7091.      WBINVD                        ; 0F 09                [486]
  7092.    `WBINVD' invalidates and empties the processor's internal caches, and
  7093. causes the processor to instruct external caches to do the same. It
  7094. writes the contents of the caches back to memory first, so no data is
  7095. lost. To flush the caches quickly without bothering to write the data
  7096. back first, use `INVD' (*Note Section A.84::).
  7097. File: nasm.info,  Node: Section A.165,  Next: Section A.166,  Prev: Section A.164,  Up: Appendix A
  7098. A.165. `WRMSR': Write Model-Specific Registers
  7099. **********************************************
  7100.      WRMSR                         ; 0F 30                [PENT]
  7101.    `WRMSR' writes the value in `EDX:EAX' to the processor Model-
  7102. Specific Register (MSR) whose index is stored in `ECX'. See also
  7103. `RDMSR' (*Note Section A.139::).
  7104. File: nasm.info,  Node: Section A.166,  Next: Section A.167,  Prev: Section A.165,  Up: Appendix A
  7105. A.166. `XADD': Exchange and Add
  7106. *******************************
  7107.      XADD r/m8,reg8                ; 0F C0 /r             [486]
  7108.      XADD r/m16,reg16              ; o16 0F C1 /r         [486]
  7109.      XADD r/m32,reg32              ; o32 0F C1 /r         [486]
  7110.    `XADD' exchanges the values in its two operands, and then adds them
  7111. together and writes the result into the destination (first) operand.
  7112. This instruction can be used with a `LOCK' prefix for multi-processor
  7113. synchronisation purposes.
  7114. File: nasm.info,  Node: Section A.167,  Next: Section A.168,  Prev: Section A.166,  Up: Appendix A
  7115. A.167. `XBTS': Extract Bit String
  7116. *********************************
  7117.      XBTS reg16,r/m16              ; o16 0F A6 /r         [386,UNDOC]
  7118.      XBTS reg32,r/m32              ; o32 0F A6 /r         [386,UNDOC]
  7119.    No clear documentation seems to be available for this instruction:
  7120. the best I've been able to find reads `Takes a string of bits from the
  7121. first operand and puts them in the second operand'. It is present only
  7122. in early 386 processors, and conflicts with the opcodes for
  7123. `CMPXCHG486'. NASM supports it only for completeness. Its counterpart
  7124. is `IBTS' (see *Note Section A.75::).
  7125. File: nasm.info,  Node: Section A.168,  Next: Section A.169,  Prev: Section A.167,  Up: Appendix A
  7126. A.168. `XCHG': Exchange
  7127. ***********************
  7128.      XCHG reg8,r/m8                ; 86 /r                [8086]
  7129.      XCHG reg16,r/m8               ; o16 87 /r            [8086]
  7130.      XCHG reg32,r/m32              ; o32 87 /r            [386]
  7131.      XCHG r/m8,reg8                ; 86 /r                [8086]
  7132.      XCHG r/m16,reg16              ; o16 87 /r            [8086]
  7133.      XCHG r/m32,reg32              ; o32 87 /r            [386]
  7134.      XCHG AX,reg16                 ; o16 90+r             [8086]
  7135.      XCHG EAX,reg32                ; o32 90+r             [386]
  7136.      XCHG reg16,AX                 ; o16 90+r             [8086]
  7137.      XCHG reg32,EAX                ; o32 90+r             [386]
  7138.    `XCHG' exchanges the values in its two operands. It can be used with
  7139. a `LOCK' prefix for purposes of multi-processor synchronisation.
  7140.    `XCHG AX,AX' or `XCHG EAX,EAX' (depending on the `BITS' setting)
  7141. generates the opcode `90h', and so is a synonym for `NOP' (*Note
  7142. Section A.109::).
  7143. File: nasm.info,  Node: Section A.169,  Next: Section A.170,  Prev: Section A.168,  Up: Appendix A
  7144. A.169. `XLATB': Translate Byte in Lookup Table
  7145. **********************************************
  7146.      XLATB                         ; D7                   [8086]
  7147.    `XLATB' adds the value in `AL', treated as an unsigned byte, to `BX'
  7148. or `EBX', and loads the byte from the resulting address (in the segment
  7149. specified by `DS') back into `AL'.
  7150.    The base register used is `BX' if the address size is 16 bits, and
  7151. `EBX' if it is 32 bits. If you need to use an address size not equal to
  7152. the current `BITS' setting, you can use an explicit `a16' or `a32'
  7153. prefix.
  7154.    The segment register used to load from `[BX+AL]' or `[EBX+AL]' can
  7155. be overridden by using a segment register name as a prefix (for
  7156. example, `es xlatb').
  7157. File: nasm.info,  Node: Section A.170,  Prev: Section A.169,  Up: Appendix A
  7158. A.170. `XOR': Bitwise Exclusive OR
  7159. **********************************
  7160.      XOR r/m8,reg8                 ; 30 /r                [8086]
  7161.      XOR r/m16,reg16               ; o16 31 /r            [8086]
  7162.      XOR r/m32,reg32               ; o32 31 /r            [386]
  7163.      XOR reg8,r/m8                 ; 32 /r                [8086]
  7164.      XOR reg16,r/m16               ; o16 33 /r            [8086]
  7165.      XOR reg32,r/m32               ; o32 33 /r            [386]
  7166.      XOR r/m8,imm8                 ; 80 /6 ib             [8086]
  7167.      XOR r/m16,imm16               ; o16 81 /6 iw         [8086]
  7168.      XOR r/m32,imm32               ; o32 81 /6 id         [386]
  7169.      XOR r/m16,imm8                ; o16 83 /6 ib         [8086]
  7170.      XOR r/m32,imm8                ; o32 83 /6 ib         [386]
  7171.      XOR AL,imm8                   ; 34 ib                [8086]
  7172.      XOR AX,imm16                  ; o16 35 iw            [8086]
  7173.      XOR EAX,imm32                 ; o32 35 id            [386]
  7174.    `XOR' performs a bitwise XOR operation between its two operands (i.e.
  7175. each bit of the result is 1 if and only if exactly one of the
  7176. corresponding bits of the two inputs was 1), and stores the result in
  7177. the destination (first) operand.
  7178.    In the forms with an 8-bit immediate second operand and a longer
  7179. first operand, the second operand is considered to be signed, and is
  7180. sign- extended to the length of the first operand. In these cases, the
  7181. `BYTE' qualifier is necessary to force NASM to generate this form of
  7182. the instruction.
  7183.    The MMX instruction `PXOR' (see *Note Section A.137::) performs the
  7184. same operation on the 64-bit MMX registers.
  7185. File: nasm.info,  Node: Index,  Up: Top
  7186. Index
  7187. *****
  7188. * Menu:
  7189. * `!=' operator                            (1): Section 4.3.3.
  7190. * `$' Here token                           (1): Section 3.5.
  7191. * `$$' token                               (1): Section 3.5.
  7192. * `$$' token                               (2): Section 6.5.2.
  7193. * `%' operator                             (1): Section 3.5.6.
  7194. * `%$' and `%$$' prefixes                  (1): Section 4.6.2.
  7195. * `%%' operator                            (1): Section 3.5.6.
  7196. * `%%' operator                            (2): Section 4.2.2.
  7197. * `%+1' and `%-1' syntax                   (1): Section 4.2.8.
  7198. * `%0' parameter count                     (1): Section 4.2.4.
  7199. * `%0' parameter count                     (2): Section 4.2.5.
  7200. * `&' operator                             (1): Section 3.5.3.
  7201. * `&&' operator                            (1): Section 4.3.3.
  7202. * `*' operator                             (1): Section 3.5.6.
  7203. * `+' modifier                             (1): Section 4.2.3.
  7204. * `+' operator, binary                     (1): Section 3.5.5.
  7205. * `+' operator, unary                      (1): Section 3.5.7.
  7206. * `-' operator, binary                     (1): Section 3.5.5.
  7207. * `-' operator, unary                      (1): Section 3.5.7.
  7208. * `..@' symbol prefix                      (1): Section 3.8.
  7209. * `..@' symbol prefix                      (2): Section 4.2.2.
  7210. * `/' operator                             (1): Section 3.5.6.
  7211. * `//' operator                            (1): Section 3.5.6.
  7212. * `<' operator                             (1): Section 4.3.3.
  7213. * `<<' operator                            (1): Section 3.5.4.
  7214. * `<=' operator                            (1): Section 4.3.3.
  7215. * `<>' operator                            (1): Section 4.3.3.
  7216. * `=' operator                             (1): Section 4.3.3.
  7217. * `==' operator                            (1): Section 4.3.3.
  7218. * `>' operator                             (1): Section 4.3.3.
  7219. * `>=' operator                            (1): Section 4.3.3.
  7220. * `>>' operator                            (1): Section 3.5.4.
  7221. * `?' MASM syntax                          (1): Section 3.2.2.
  7222. * `^' operator                             (1): Section 3.5.2.
  7223. * `^^' operator                            (1): Section 4.3.3.
  7224. * `|' operator                             (1): Section 3.5.1.
  7225. * `||' operator                            (1): Section 4.3.3.
  7226. * `~' operator                             (1): Section 3.5.7.
  7227. * `-a' option                              (1): Section 2.1.9.
  7228. * `a16'                                    (1): Section 9.3.
  7229. * `a16'                                    (2): Section A.19.
  7230. * `a16'                                    (3): Section A.80.
  7231. * `a16'                                    (4): Section A.98.
  7232. * `a16'                                    (5): Section A.105.
  7233. * `a16'                                    (6): Section A.112.
  7234. * `a16'                                    (7): Section A.126.
  7235. * `a16'                                    (8): Section A.134.
  7236. * `a16'                                    (9): Section A.149.
  7237. * `a16'                                    (A): Section A.157.
  7238. * `a16'                                    (B): Section A.169.
  7239. * `a32'                                    (1): Section 9.3.
  7240. * `a32'                                    (2): Section A.19.
  7241. * `a32'                                    (3): Section A.80.
  7242. * `a32'                                    (4): Section A.98.
  7243. * `a32'                                    (5): Section A.105.
  7244. * `a32'                                    (6): Section A.112.
  7245. * `a32'                                    (7): Section A.126.
  7246. * `a32'                                    (8): Section A.134.
  7247. * `a32'                                    (9): Section A.149.
  7248. * `a32'                                    (A): Section A.157.
  7249. * `a32'                                    (B): Section A.169.
  7250. * `a86'                                    (1): Section 1.1.1.
  7251. * `a86'                                    (2): Section 2.2.
  7252. * `a86'                                    (3): Section 2.2.2.
  7253. * `a86'                                    (4): Section 2.2.6.
  7254. * `AAA'                                    (1): Section A.4.
  7255. * `AAD'                                    (1): Section A.4.
  7256. * `AAM'                                    (1): Section A.4.
  7257. * `AAS'                                    (1): Section A.4.
  7258. * `ABSOLUTE'                               (1): Section 5.3.
  7259. * `ABSOLUTE'                               (2): Section 6.2.1.
  7260. * `ADC'                                    (1): Section A.5.
  7261. * `ADD'                                    (1): Section A.6.
  7262. * addition                                 (1): Section 3.5.5.
  7263. * addressing, mixed-size                   (1): Section 9.2.
  7264. * address-size prefixes                    (1): Section 3.1.
  7265. * algebra                                  (1): Section 3.3.
  7266. * `ALIGN'                                  (1): Section 4.7.5.
  7267. * `ALIGN'                                  (2): Section 6.1.2.
  7268. * `ALIGN'                                  (3): Section 6.2.1.
  7269. * `ALIGNB'                                 (1): Section 4.7.5.
  7270. * alignment, in `bin' sections             (1): Section 6.1.2.
  7271. * alignment, in `elf' sections             (1): Section 6.5.1.
  7272. * alignment, in `obj' sections             (1): Section 6.2.1.
  7273. * alignment, in `win32' sections           (1): Section 6.3.1.
  7274. * alignment, of `elf' common variables     (1): Section 6.5.4.
  7275. * `alloc'                                  (1): Section 6.5.1.
  7276. * `alt.lang.asm'                           (1): Section 1.1.1.
  7277. * `alt.lang.asm'                           (2): Section 1.2.
  7278. * ambiguity                                (1): Section 2.2.3.
  7279. * `AND'                                    (1): Section A.7.
  7280. * `a.out', BSD version                     (1): Section 6.7.
  7281. * `a.out', Linux version                   (1): Section 6.6.
  7282. * `aout'                                   (1): Section 2.1.1.
  7283. * `aout'                                   (2): Section 6.6.
  7284. * `aoutb'                                  (1): Section 6.7.
  7285. * `aoutb'                                  (2): Section 8.2.
  7286. * `arg'                                    (1): Section 7.4.5.
  7287. * `arg'                                    (2): Section 8.1.4.
  7288. * `ARPL'                                   (1): Section A.8.
  7289. * `as86'                                   (1): Section 1.1.1.
  7290. * `as86'                                   (2): Section 2.1.1.
  7291. * `as86'                                   (3): Section 6.8.
  7292. * assembler directives                     (1): Chapter 5.
  7293. * assembly passes                          (1): Section 3.7.
  7294. * assembly-time options                    (1): Section 2.1.7.
  7295. * `%assign'                                (1): Section 4.1.2.
  7296. * `ASSUME'                                 (1): Section 2.2.4.
  7297. * `AT'                                     (1): Section 4.7.4.
  7298. * Autoconf                                 (1): Section 1.3.2.
  7299. * `autoexec.bat'                           (1): Section 1.3.1.
  7300. * `bin'                                    (1): Section 2.1.1.
  7301. * `bin'                                    (2): Section 2.1.2.
  7302. * `bin'                                    (3): Section 6.1.
  7303. * binary                                   (1): Section 3.4.1.
  7304. * binary files                             (1): Section 3.2.3.
  7305. * 16-bit mode, versus 32-bit mode          (1): Section 5.1.
  7306. * bit shift                                (1): Section 3.5.4.
  7307. * `BITS'                                   (1): Section 5.1.
  7308. * `BITS'                                   (2): Section 6.1.
  7309. * bitwise AND                              (1): Section 3.5.3.
  7310. * bitwise OR                               (1): Section 3.5.1.
  7311. * bitwise XOR                              (1): Section 3.5.2.
  7312. * block IFs                                (1): Section 4.6.5.
  7313. * boot loader                              (1): Section 6.1.
  7314. * boot sector                              (1): Section 10.1.3.
  7315. * Borland, Pascal                          (1): Section 7.5.
  7316. * Borland, Win32 compilers                 (1): Section 6.2.
  7317. * `BOUND'                                  (1): Section A.9.
  7318. * braces, after `%' sign                   (1): Section 4.2.7.
  7319. * braces, around macro parameters          (1): Section 4.2.
  7320. * BSD                                      (1): Section 8.2.
  7321. * `BSF'                                    (1): Section A.10.
  7322. * `BSR'                                    (1): Section A.10.
  7323. * `.bss'                                   (1): Section 6.1.
  7324. * `.bss'                                   (2): Section 6.5.1.
  7325. * `.bss'                                   (3): Section 6.6.
  7326. * `.bss'                                   (4): Section 6.7.
  7327. * `.bss'                                   (5): Section 6.8.
  7328. * `.bss'                                   (6): Section 6.9.
  7329. * `BSWAP'                                  (1): Section A.11.
  7330. * `BT'                                     (1): Section A.12.
  7331. * `BTC'                                    (1): Section A.12.
  7332. * `BTR'                                    (1): Section A.12.
  7333. * `BTS'                                    (1): Section A.12.
  7334. * bugs                                     (1): Section 10.2.
  7335. * `BYTE'                                   (1): Section 10.1.1.
  7336. * C calling convention                     (1): Section 7.4.3.
  7337. * C calling convention                     (2): Section 8.1.2.
  7338. * C symbol names                           (1): Section 7.4.1.
  7339. * `CALL'                                   (1): Section A.13.
  7340. * `CALL FAR'                               (1): Section 3.6.
  7341. * case sensitivity                         (1): Section 2.2.1.
  7342. * case sensitivity                         (2): Section 4.1.1.
  7343. * case sensitivity                         (3): Section 4.1.2.
  7344. * case sensitivity                         (4): Section 4.2.
  7345. * case sensitivity                         (5): Section 4.3.4.
  7346. * case sensitivity                         (6): Section 6.2.3.
  7347. * `CBW'                                    (1): Section A.14.
  7348. * `CDQ'                                    (1): Section A.14.
  7349. * changing sections                        (1): Section 5.2.
  7350. * character constant                       (1): Section 3.2.1.
  7351. * character constant                       (2): Section 3.4.2.
  7352. * circular references                      (1): Section 4.1.1.
  7353. * `CLASS'                                  (1): Section 6.2.1.
  7354. * `CLC'                                    (1): Section A.15.
  7355. * `CLD'                                    (1): Section A.15.
  7356. * `%clear'                                 (1): Section 4.7.
  7357. * `CLI'                                    (1): Section A.15.
  7358. * `CLTS'                                   (1): Section A.15.
  7359. * `c16.mac'                                (1): Section 7.4.5.
  7360. * `c16.mac'                                (2): Section 7.5.3.
  7361. * `c32.mac'                                (1): Section 8.1.4.
  7362. * `CMC'                                    (1): Section A.16.
  7363. * `CMOVcc'                                 (1): Section A.17.
  7364. * `CMP'                                    (1): Section A.18.
  7365. * `CMPSB'                                  (1): Section A.19.
  7366. * `CMPSD'                                  (1): Section A.19.
  7367. * `CMPSW'                                  (1): Section A.19.
  7368. * `CMPXCHG'                                (1): Section A.20.
  7369. * `CMPXCHG486'                             (1): Section A.20.
  7370. * `CMPXCHG8B'                              (1): Section A.21.
  7371. * `coff'                                   (1): Section 2.1.1.
  7372. * `coff'                                   (2): Section 6.4.
  7373. * colon                                    (1): Section 3.1.
  7374. * `.COM'                                   (1): Section 6.1.
  7375. * `.COM'                                   (2): Section 7.2.
  7376. * command-line                             (1): Section 2.1.
  7377. * command-line                             (2): Chapter 6.
  7378. * commas in macro parameters               (1): Section 4.2.3.
  7379. * `COMMON'                                 (1): Section 5.6.
  7380. * `COMMON'                                 (2): Section 6.2.1.
  7381. * `COMMON', `elf' extensions to            (1): Section 6.5.4.
  7382. * `COMMON', `obj' extensions to            (1): Section 6.2.8.
  7383. * Common Object File Format                (1): Section 6.4.
  7384. * common variables                         (1): Section 5.6.
  7385. * common variables, alignment in `elf'     (1): Section 6.5.4.
  7386. * common variables, element size           (1): Section 6.2.8.
  7387. * `comp.archives.msdos.announce'           (1): Section 1.2.
  7388. * `comp.lang.asm.x86'                      (1): Section 1.1.1.
  7389. * `comp.lang.asm.x86'                      (2): Section 1.2.
  7390. * `comp.os.linux.announce'                 (1): Section 1.2.
  7391. * `comp.os.msdos.programmer'               (1): Section 7.3.
  7392. * concatenating macro parameters           (1): Section 4.2.7.
  7393. * condition codes                          (1): Section A.2.2.
  7394. * condition codes as macro parameters      (1): Section 4.2.8.
  7395. * conditional assembly                     (1): Section 4.3.
  7396. * conditional jump                         (1): Section A.89.
  7397. * conditional jumps                        (1): Section 10.1.2.
  7398. * conditional-return macro                 (1): Section 4.2.8.
  7399. * `configure'                              (1): Section 1.3.2.
  7400. * constants                                (1): Section 3.4.
  7401. * context stack                            (1): Section 4.6.
  7402. * context stack                            (2): Section 4.6.5.
  7403. * context-local labels                     (1): Section 4.6.2.
  7404. * context-local single-line macros         (1): Section 4.6.3.
  7405. * control registers                        (1): Section A.2.1.
  7406. * counting macro parameters                (1): Section 4.2.5.
  7407. * `CPUID'                                  (1): Section 3.4.2.
  7408. * `CPUID'                                  (2): Section A.22.
  7409. * creating contexts                        (1): Section 4.6.1.
  7410. * critical expression                      (1): Section 3.2.2.
  7411. * critical expression                      (2): Section 3.2.4.
  7412. * critical expression                      (3): Section 3.7.
  7413. * critical expression                      (4): Section 4.1.2.
  7414. * critical expression                      (5): Section 5.3.
  7415. * `CWD'                                    (1): Section A.14.
  7416. * `CWDE'                                   (1): Section A.14.
  7417. * `-d' option                              (1): Section 2.1.7.
  7418. * `DAA'                                    (1): Section A.23.
  7419. * `DAS'                                    (1): Section A.23.
  7420. * `.data'                                  (1): Section 6.1.
  7421. * `.data'                                  (2): Section 6.5.1.
  7422. * `.data'                                  (3): Section 6.6.
  7423. * `.data'                                  (4): Section 6.7.
  7424. * `.data'                                  (5): Section 6.8.
  7425. * `.data'                                  (6): Section 6.9.
  7426. * `_DATA'                                  (1): Section 7.4.2.
  7427. * `data'                                   (1): Section 6.5.3.
  7428. * data structure                           (1): Section 7.4.4.
  7429. * data structure                           (2): Section 8.1.3.
  7430. * `DB'                                     (1): Section 3.2.
  7431. * `DB'                                     (2): Section 3.2.1.
  7432. * `DB'                                     (3): Section 3.4.3.
  7433. * `dbg'                                    (1): Section 6.10.
  7434. * `DD'                                     (1): Section 3.2.
  7435. * `DD'                                     (2): Section 3.2.1.
  7436. * `DD'                                     (3): Section 3.4.3.
  7437. * `DD'                                     (4): Section 3.4.4.
  7438. * debug registers                          (1): Section A.2.1.
  7439. * `DEC'                                    (1): Section A.24.
  7440. * declaring structures                     (1): Section 4.7.3.
  7441. * default macro parameters                 (1): Section 4.2.4.
  7442. * default name                             (1): Chapter 6.
  7443. * default-`WRT' mechanism                  (1): Section 6.2.7.
  7444. * `%define'                                (1): Section 2.1.7.
  7445. * `%define'                                (2): Section 4.1.1.
  7446. * defining sections                        (1): Section 5.2.
  7447. * design goals                             (1): Section 2.2.2.
  7448. * DevPac                                   (1): Section 3.2.3.
  7449. * DevPac                                   (2): Section 3.8.
  7450. * disabling listing expansion              (1): Section 4.2.9.
  7451. * `DIV'                                    (1): Section A.25.
  7452. * division                                 (1): Section 3.5.6.
  7453. * DJGPP                                    (1): Section 6.4.
  7454. * DJGPP                                    (2): Chapter 8.
  7455. * `djlink'                                 (1): Section 7.1.1.
  7456. * DLL symbols, exporting                   (1): Section 6.2.5.
  7457. * DLL symbols, importing                   (1): Section 6.2.4.
  7458. * DOS                                      (1): Section 1.3.1.
  7459. * DOS                                      (2): Section 2.1.4.
  7460. * DOS archive                              (1): Section 1.3.1.
  7461. * DOS source archive                       (1): Section 1.3.1.
  7462. * `DQ'                                     (1): Section 3.2.
  7463. * `DQ'                                     (2): Section 3.2.1.
  7464. * `DQ'                                     (3): Section 3.4.3.
  7465. * `DQ'                                     (4): Section 3.4.4.
  7466. * `.drectve'                               (1): Section 6.3.1.
  7467. * `DT'                                     (1): Section 3.2.
  7468. * `DT'                                     (2): Section 3.2.1.
  7469. * `DT'                                     (3): Section 3.4.3.
  7470. * `DT'                                     (4): Section 3.4.4.
  7471. * `DUP'                                    (1): Section 2.2.7.
  7472. * `DUP'                                    (2): Section 3.2.5.
  7473. * `DW'                                     (1): Section 3.2.
  7474. * `DW'                                     (2): Section 3.2.1.
  7475. * `DW'                                     (3): Section 3.4.3.
  7476. * `DWORD'                                  (1): Section 3.1.
  7477. * `-e' option                              (1): Section 2.1.8.
  7478. * effective addresses                      (1): Section 3.1.
  7479. * effective addresses                      (2): Section 3.3.
  7480. * effective addresses                      (3): Section 3.7.
  7481. * effective addresses                      (4): Section A.2.3.
  7482. * element size, in common variables        (1): Section 6.2.8.
  7483. * `elf'                                    (1): Section 2.1.1.
  7484. * `elf'                                    (2): Section 6.5.
  7485. * `elf' shared libraries                   (1): Section 6.5.2.
  7486. * `%elif'                                  (1): Section 4.3.
  7487. * `%elif'                                  (2): Section 4.3.3.
  7488. * `%elifctx'                               (1): Section 4.3.2.
  7489. * `%elifdef'                               (1): Section 4.3.1.
  7490. * `%elifid'                                (1): Section 4.3.5.
  7491. * `%elifidn'                               (1): Section 4.3.4.
  7492. * `%elifidni'                              (1): Section 4.3.4.
  7493. * `%elifnctx'                              (1): Section 4.3.2.
  7494. * `%elifndef'                              (1): Section 4.3.1.
  7495. * `%elifnid'                               (1): Section 4.3.5.
  7496. * `%elifnidn'                              (1): Section 4.3.4.
  7497. * `%elifnidni'                             (1): Section 4.3.4.
  7498. * `%elifnnum'                              (1): Section 4.3.5.
  7499. * `%elifnstr'                              (1): Section 4.3.5.
  7500. * `%elifnum'                               (1): Section 4.3.5.
  7501. * `%elifstr'                               (1): Section 4.3.5.
  7502. * `%else'                                  (1): Section 4.3.
  7503. * e-mail                                   (1): Section 1.2.
  7504. * `EMMS'                                   (1): Section A.26.
  7505. * `endproc'                                (1): Section 7.4.5.
  7506. * `endproc'                                (2): Section 8.1.4.
  7507. * `%endrep'                                (1): Section 4.4.
  7508. * `ENDSTRUC'                               (1): Section 4.7.3.
  7509. * `ENDSTRUC'                               (2): Section 5.3.
  7510. * `ENTER'                                  (1): Section A.27.
  7511. * environment                              (1): Section 2.1.11.
  7512. * `EQU'                                    (1): Section 3.2.
  7513. * `EQU'                                    (2): Section 3.2.4.
  7514. * `EQU'                                    (3): Section 3.7.
  7515. * `%error'                                 (1): Section 4.3.6.
  7516. * error messages                           (1): Section 2.1.4.
  7517. * `EVEN'                                   (1): Section 4.7.5.
  7518. * `.EXE'                                   (1): Section 6.2.
  7519. * `.EXE'                                   (2): Section 7.1.
  7520. * `EXE_begin'                              (1): Section 7.1.2.
  7521. * `EXE2BIN'                                (1): Section 7.2.2.
  7522. * `exebin.mac'                             (1): Section 7.1.2.
  7523. * `exec'                                   (1): Section 6.5.1.
  7524. * executable and linkable format           (1): Section 6.5.
  7525. * `EXE_end'                                (1): Section 7.1.2.
  7526. * `EXE_stack'                              (1): Section 7.1.2.
  7527. * `%exitrep'                               (1): Section 4.4.
  7528. * `EXPORT'                                 (1): Section 6.2.5.
  7529. * exporting symbols                        (1): Section 5.5.
  7530. * expressions                              (1): Section 2.1.8.
  7531. * expressions                              (2): Section 3.5.
  7532. * extension                                (1): Section 2.1.1.
  7533. * extension                                (2): Chapter 6.
  7534. * `EXTERN'                                 (1): Section 5.4.
  7535. * extern, obj extensions to                (1): Section 6.2.7.
  7536. * `-f' option                              (1): Section 2.1.2.
  7537. * `-f' option                              (2): Chapter 6.
  7538. * `FABS'                                   (1): Section A.29.
  7539. * `FADD'                                   (1): Section A.30.
  7540. * `FADDP'                                  (1): Section A.30.
  7541. * far call                                 (1): Section 2.2.5.
  7542. * far call                                 (2): Section A.13.
  7543. * far common variables                     (1): Section 6.2.8.
  7544. * far jump                                 (1): Section A.88.
  7545. * far pointer                              (1): Section 3.6.
  7546. * `FARCODE'                                (1): Section 7.4.5.
  7547. * `FARCODE'                                (2): Section 7.5.3.
  7548. * `FBLD'                                   (1): Section A.31.
  7549. * `FBSTP'                                  (1): Section A.31.
  7550. * `FCHS'                                   (1): Section A.32.
  7551. * `FCLEX'                                  (1): Section A.33.
  7552. * `FCMOVcc'                                (1): Section A.34.
  7553. * `FCOM'                                   (1): Section A.35.
  7554. * `FCOMI'                                  (1): Section A.35.
  7555. * `FCOMIP'                                 (1): Section A.35.
  7556. * `FCOMP'                                  (1): Section A.35.
  7557. * `FCOMPP'                                 (1): Section A.35.
  7558. * `FCOS'                                   (1): Section A.36.
  7559. * `FDECSTP'                                (1): Section A.37.
  7560. * `FDIV'                                   (1): Section A.39.
  7561. * `FDIVP'                                  (1): Section A.39.
  7562. * `FDIVR'                                  (1): Section A.39.
  7563. * `FDIVRP'                                 (1): Section A.39.
  7564. * `FFREE'                                  (1): Section A.40.
  7565. * `FIADD'                                  (1): Section A.41.
  7566. * `FICOM'                                  (1): Section A.42.
  7567. * `FICOMP'                                 (1): Section A.42.
  7568. * `FIDIV'                                  (1): Section A.43.
  7569. * `FIDIVR'                                 (1): Section A.43.
  7570. * `FILD'                                   (1): Section A.44.
  7571. * `__FILE__'                               (1): Section 4.7.2.
  7572. * `FIMUL'                                  (1): Section A.45.
  7573. * `FINCSTP'                                (1): Section A.46.
  7574. * `FINIT'                                  (1): Section A.47.
  7575. * `FIST'                                   (1): Section A.44.
  7576. * `FISTP'                                  (1): Section A.44.
  7577. * `FISUB'                                  (1): Section A.48.
  7578. * `FLAT'                                   (1): Section 6.2.1.
  7579. * flat memory model                        (1): Chapter 8.
  7580. * flat-form binary                         (1): Section 6.1.
  7581. * `FLD'                                    (1): Section A.49.
  7582. * `FLDCW'                                  (1): Section A.51.
  7583. * `FLDENV'                                 (1): Section A.52.
  7584. * `FLDxx'                                  (1): Section A.50.
  7585. * floating-point                           (1): Section 2.2.6.
  7586. * floating-point                           (2): Section 3.1.
  7587. * floating-point                           (3): Section 3.2.1.
  7588. * floating-point                           (4): Section 3.4.4.
  7589. * floating-point, constants                (1): Section 3.4.4.
  7590. * floating-point, registers                (1): Section A.2.1.
  7591. * `FMUL'                                   (1): Section A.53.
  7592. * `FMULP'                                  (1): Section A.53.
  7593. * `FNINIT'                                 (1): Section A.47.
  7594. * `FNOP'                                   (1): Section A.54.
  7595. * format-specific directives               (1): Chapter 5.
  7596. * forward references                       (1): Section 3.7.
  7597. * `FPATAN'                                 (1): Section A.55.
  7598. * `FPREM'                                  (1): Section A.56.
  7599. * `FPREM1'                                 (1): Section A.56.
  7600. * `FPTAN'                                  (1): Section A.55.
  7601. * frame pointer                            (1): Section 7.4.3.
  7602. * frame pointer                            (2): Section 7.5.1.
  7603. * frame pointer                            (3): Section 8.1.2.
  7604. * FreeBSD                                  (1): Section 6.7.
  7605. * FreeBSD                                  (2): Section 8.2.
  7606. * FreeLink                                 (1): Section 7.1.1.
  7607. * `FRNDINT'                                (1): Section A.57.
  7608. * `FRSTOR'                                 (1): Section A.58.
  7609. * `FSAVE'                                  (1): Section A.58.
  7610. * `FSCALE'                                 (1): Section A.59.
  7611. * `FSETPM'                                 (1): Section A.60.
  7612. * `FSIN'                                   (1): Section A.61.
  7613. * `FSINCOS'                                (1): Section A.61.
  7614. * `FSQRT'                                  (1): Section A.62.
  7615. * `FST'                                    (1): Section A.63.
  7616. * `FSTCW'                                  (1): Section A.64.
  7617. * `FSTENV'                                 (1): Section A.65.
  7618. * `FSTP'                                   (1): Section A.63.
  7619. * `FSTSW'                                  (1): Section A.66.
  7620. * `FSUB'                                   (1): Section A.67.
  7621. * `FSUBP'                                  (1): Section A.67.
  7622. * `FSUBR'                                  (1): Section A.67.
  7623. * `FSUBRP'                                 (1): Section A.67.
  7624. * `ftp.coast.net'                          (1): Section 1.2.
  7625. * `ftp.simtel.net'                         (1): Section 1.2.
  7626. * `ftp.simtel.net'                         (2): Section 7.1.1.
  7627. * `FTST'                                   (1): Section A.68.
  7628. * `FUCOMxx'                                (1): Section A.69.
  7629. * `function'                               (1): Section 6.5.3.
  7630. * functions, C calling convention          (1): Section 7.4.3.
  7631. * functions, C calling convention          (2): Section 8.1.2.
  7632. * functions, Pascal calling convention     (1): Section 7.5.1.
  7633. * `FXAM'                                   (1): Section A.70.
  7634. * `FXCH'                                   (1): Section A.71.
  7635. * `FxDISI'                                 (1): Section A.38.
  7636. * `FxENI'                                  (1): Section A.38.
  7637. * `F2XM1'                                  (1): Section A.28.
  7638. * `FXTRACT'                                (1): Section A.72.
  7639. * `FYL2X'                                  (1): Section A.73.
  7640. * `FYL2XP1'                                (1): Section A.73.
  7641. * `gas'                                    (1): Section 1.1.1.
  7642. * `gcc'                                    (1): Section 1.1.1.
  7643. * general purpose register                 (1): Section A.1.
  7644. * `GLOBAL'                                 (1): Section 5.5.
  7645. * `GLOBAL', `aoutb' extensions to          (1): Section 6.5.3.
  7646. * `GLOBAL', `elf' extensions to            (1): Section 6.5.3.
  7647. * global offset table                      (1): Section 8.2.
  7648. * `_GLOBAL_OFFSET_TABLE_'                  (1): Section 6.5.2.
  7649. * `..got'                                  (1): Section 6.5.2.
  7650. * `GOT' relocations                        (1): Section 8.2.3.
  7651. * GOT                                      (1): Section 6.5.2.
  7652. * GOT                                      (2): Section 8.2.
  7653. * `..gotoff'                               (1): Section 6.5.2.
  7654. * `GOTOFF' relocations                     (1): Section 8.2.2.
  7655. * `..gotpc'                                (1): Section 6.5.2.
  7656. * `GOTPC' relocations                      (1): Section 8.2.1.
  7657. * graphics                                 (1): Section 3.2.3.
  7658. * greedy macro parameters                  (1): Section 4.2.3.
  7659. * `GROUP'                                  (1): Section 6.2.2.
  7660. * groups                                   (1): Section 3.6.
  7661. * hex                                      (1): Section 3.4.1.
  7662. * `HLT'                                    (1): Section A.74.
  7663. * hybrid syntaxes                          (1): Section 2.2.2.
  7664. * `-i' option                              (1): Section 2.1.5.
  7665. * `%iassign'                               (1): Section 4.1.2.
  7666. * `IBTS'                                   (1): Section A.75.
  7667. * `ICEBP'                                  (1): Section A.82.
  7668. * `%idefine'                               (1): Section 4.1.1.
  7669. * `IDIV'                                   (1): Section A.76.
  7670. * `IEND'                                   (1): Section 4.7.4.
  7671. * `%if'                                    (1): Section 4.3.
  7672. * `%if'                                    (2): Section 4.3.3.
  7673. * `%ifctx'                                 (1): Section 4.3.2.
  7674. * `%ifctx'                                 (2): Section 4.6.5.
  7675. * `%ifdef'                                 (1): Section 4.3.1.
  7676. * `%ifid'                                  (1): Section 4.3.5.
  7677. * `%ifidn'                                 (1): Section 4.3.4.
  7678. * `%ifidni'                                (1): Section 4.3.4.
  7679. * `%ifnctx'                                (1): Section 4.3.2.
  7680. * `%ifndef'                                (1): Section 4.3.1.
  7681. * `%ifnid'                                 (1): Section 4.3.5.
  7682. * `%ifnidn'                                (1): Section 4.3.4.
  7683. * `%ifnidni'                               (1): Section 4.3.4.
  7684. * `%ifnnum'                                (1): Section 4.3.5.
  7685. * `%ifnstr'                                (1): Section 4.3.5.
  7686. * `%ifnum'                                 (1): Section 4.3.5.
  7687. * `%ifstr'                                 (1): Section 4.3.5.
  7688. * `%imacro'                                (1): Section 4.2.
  7689. * immediate operand                        (1): Section A.1.
  7690. * `IMPORT'                                 (1): Section 6.2.4.
  7691. * import library                           (1): Section 6.2.4.
  7692. * importing symbols                        (1): Section 5.4.
  7693. * `IMUL'                                   (1): Section A.77.
  7694. * `IN'                                     (1): Section A.78.
  7695. * `INC'                                    (1): Section A.79.
  7696. * `INCBIN'                                 (1): Section 3.2.
  7697. * `INCBIN'                                 (2): Section 3.2.3.
  7698. * `INCBIN'                                 (3): Section 3.4.3.
  7699. * `%include'                               (1): Section 2.1.5.
  7700. * `%include'                               (2): Section 2.1.6.
  7701. * `%include'                               (3): Section 4.5.
  7702. * include search path                      (1): Section 2.1.5.
  7703. * including other files                    (1): Section 4.5.
  7704. * inefficient code                         (1): Section 10.1.1.
  7705. * infinite loop                            (1): Section 3.5.
  7706. * informational section                    (1): Section 6.3.1.
  7707. * `INSB'                                   (1): Section A.80.
  7708. * `INSD'                                   (1): Section A.80.
  7709. * `INSTALL'                                (1): Section 1.3.2.
  7710. * installing                               (1): Section 1.3.1.
  7711. * instances of structures                  (1): Section 4.7.4.
  7712. * `INSW'                                   (1): Section A.80.
  7713. * `INT'                                    (1): Section A.81.
  7714. * `INT01'                                  (1): Section A.82.
  7715. * `INT1'                                   (1): Section A.82.
  7716. * `INT3'                                   (1): Section A.82.
  7717. * integer overflow                         (1): Section 3.5.
  7718. * intel number formats                     (1): Section 3.4.4.
  7719. * `INTO'                                   (1): Section A.83.
  7720. * `INVD'                                   (1): Section A.84.
  7721. * `INVLPG'                                 (1): Section A.85.
  7722. * `IRET'                                   (1): Section A.86.
  7723. * `IRETD'                                  (1): Section A.86.
  7724. * `IRETW'                                  (1): Section A.86.
  7725. * `ISTRUC'                                 (1): Section 4.7.4.
  7726. * iterating over macro parameters          (1): Section 4.2.6.
  7727. * `Jcc'                                    (1): Section A.89.
  7728. * `Jcc NEAR'                               (1): Section 10.1.2.
  7729. * `JCXZ'                                   (1): Section A.87.
  7730. * `JECXZ'                                  (1): Section A.87.
  7731. * `JMP'                                    (1): Section A.88.
  7732. * `JMP DWORD'                              (1): Section 9.1.
  7733. * jumps, mixed-size                        (1): Section 9.1.
  7734. * `-l' option                              (1): Section 2.1.3.
  7735. * label prefix                             (1): Section 3.8.
  7736. * `LAHF'                                   (1): Section A.90.
  7737. * `LAR'                                    (1): Section A.91.
  7738. * `ld86'                                   (1): Section 6.8.
  7739. * `LDS'                                    (1): Section A.92.
  7740. * `LEA'                                    (1): Section A.93.
  7741. * `LEAVE'                                  (1): Section A.94.
  7742. * `LES'                                    (1): Section A.92.
  7743. * `LFS'                                    (1): Section A.92.
  7744. * `LGDT'                                   (1): Section A.95.
  7745. * `LGS'                                    (1): Section A.92.
  7746. * `LIBRARY'                                (1): Section 6.9.1.
  7747. * licence                                  (1): Section 1.1.2.
  7748. * `LIDT'                                   (1): Section A.95.
  7749. * `__LINE__'                               (1): Section 4.7.2.
  7750. * linker, free                             (1): Section 7.1.1.
  7751. * Linux ELF                                (1): Section 6.5.
  7752. * listing file                             (1): Section 2.1.3.
  7753. * little-endian                            (1): Section 3.4.2.
  7754. * `LLDT'                                   (1): Section A.95.
  7755. * `LMSW'                                   (1): Section A.96.
  7756. * `LOADALL'                                (1): Section A.97.
  7757. * `LOADALL286'                             (1): Section A.97.
  7758. * local labels                             (1): Section 3.8.
  7759. * `LODSB'                                  (1): Section A.98.
  7760. * `LODSD'                                  (1): Section A.98.
  7761. * `LODSW'                                  (1): Section A.98.
  7762. * logical AND                              (1): Section 4.3.3.
  7763. * logical OR                               (1): Section 4.3.3.
  7764. * logical XOR                              (1): Section 4.3.3.
  7765. * `LOOP'                                   (1): Section A.99.
  7766. * `LOOPE'                                  (1): Section A.99.
  7767. * `LOOPNE'                                 (1): Section A.99.
  7768. * `LOOPNZ'                                 (1): Section A.99.
  7769. * `LOOPZ'                                  (1): Section A.99.
  7770. * `LSL'                                    (1): Section A.100.
  7771. * `LSS'                                    (1): Section A.92.
  7772. * `LTR'                                    (1): Section A.101.
  7773. * `%macro'                                 (1): Section 4.2.
  7774. * macro library                            (1): Section 2.1.5.
  7775. * macro processor                          (1): Chapter 4.
  7776. * macro-local labels                       (1): Section 4.2.2.
  7777. * `macro-params'                           (1): Section 2.1.10.
  7778. * macros                                   (1): Section 3.2.5.
  7779. * `make'                                   (1): Section 1.3.2.
  7780. * makefiles                                (1): Section 1.3.1.
  7781. * makefiles                                (2): Section 1.3.2.
  7782. * `Makefile.unx'                           (1): Section 1.3.2.
  7783. * man pages                                (1): Section 1.3.2.
  7784. * MASM                                     (1): Section 1.1.1.
  7785. * MASM                                     (2): Section 2.2.
  7786. * MASM                                     (3): Section 3.2.5.
  7787. * MASM                                     (4): Section 6.2.
  7788. * memory models                            (1): Section 2.2.5.
  7789. * memory models                            (2): Section 7.4.2.
  7790. * memory operand                           (1): Section 3.1.
  7791. * memory references                        (1): Section 2.2.2.
  7792. * memory references                        (2): Section 3.3.
  7793. * memory references                        (3): Section A.1.
  7794. * Microsoft OMF                            (1): Section 6.2.
  7795. * `misc' subdirectory                      (1): Section 7.1.2.
  7796. * `misc' subdirectory                      (2): Section 7.4.5.
  7797. * `misc' subdirectory                      (3): Section 8.1.4.
  7798. * mixed-language program                   (1): Section 7.4.
  7799. * mixed-size addressing                    (1): Section 9.2.
  7800. * mixed-size instruction                   (1): Section 9.1.
  7801. * MMX registers                            (1): Section A.2.1.
  7802. * ModR/M byte                              (1): Section A.2.
  7803. * ModR/M byte                              (2): Section A.2.3.
  7804. * modulo operators                         (1): Section 3.5.6.
  7805. * `MOV'                                    (1): Section A.102.
  7806. * `MOVD'                                   (1): Section A.103.
  7807. * `MOVQ'                                   (1): Section A.104.
  7808. * `MOVSB'                                  (1): Section A.105.
  7809. * `MOVSD'                                  (1): Section A.105.
  7810. * `MOVSW'                                  (1): Section A.105.
  7811. * `MOVSX'                                  (1): Section A.106.
  7812. * `MOVZX'                                  (1): Section A.106.
  7813. * MS-DOS                                   (1): Section 6.1.
  7814. * MS-DOS device drivers                    (1): Section 7.3.
  7815. * `MUL'                                    (1): Section A.107.
  7816. * multi-line macros                        (1): Section 2.1.10.
  7817. * multi-line macros                        (2): Section 4.2.
  7818. * multiplication                           (1): Section 3.5.6.
  7819. * `multipush' macro                        (1): Section 4.2.6.
  7820. * `nasm.1'                                 (1): Section 1.3.2.
  7821. * NASM version                             (1): Section 4.7.1.
  7822. * `__NASMDEFSEG'                           (1): Section 6.2.
  7823. * `nasm.exe'                               (1): Section 1.3.1.
  7824. * `nasm -h'                                (1): Section 2.1.2.
  7825. * `__NASM_MAJOR__'                         (1): Section 4.7.1.
  7826. * `__NASM_MINOR__'                         (1): Section 4.7.1.
  7827. * `nasm.out'                               (1): Section 2.1.1.
  7828. * `nasmw.exe'                              (1): Section 1.3.1.
  7829. * `nasmXXXs.zip'                           (1): Section 1.3.1.
  7830. * `nasm-X.XX.tar.gz'                       (1): Section 1.3.2.
  7831. * `nasmXXX.zip'                            (1): Section 1.3.1.
  7832. * `ndisasm.1'                              (1): Section 1.3.2.
  7833. * `ndisasm.exe'                            (1): Section 1.3.1.
  7834. * `ndisasmw.exe'                           (1): Section 1.3.1.
  7835. * near call                                (1): Section 2.2.5.
  7836. * near call                                (2): Section A.13.
  7837. * near common variables                    (1): Section 6.2.8.
  7838. * near jump                                (1): Section A.88.
  7839. * `NEG'                                    (1): Section A.108.
  7840. * NetBSD                                   (1): Section 6.7.
  7841. * NetBSD                                   (2): Section 8.2.
  7842. * new releases                             (1): Section 1.2.
  7843. * `noalloc'                                (1): Section 6.5.1.
  7844. * `nobits'                                 (1): Section 6.5.1.
  7845. * `noexec'                                 (1): Section 6.5.1.
  7846. * `.nolist'                                (1): Section 4.2.9.
  7847. * `NOP'                                    (1): Section A.109.
  7848. * `NOT'                                    (1): Section A.108.
  7849. * `nowait'                                 (1): Section 2.2.6.
  7850. * `nowrite'                                (1): Section 6.5.1.
  7851. * `number-overflow'                        (1): Section 2.1.10.
  7852. * numeric constants                        (1): Section 3.2.1.
  7853. * numeric constants                        (2): Section 3.4.1.
  7854. * `-o' option                              (1): Section 2.1.1.
  7855. * `o16'                                    (1): Section 9.3.
  7856. * `o16'                                    (2): Section A.126.
  7857. * `o16'                                    (3): Section A.134.
  7858. * `o32'                                    (1): Section 9.3.
  7859. * `o32'                                    (2): Section A.126.
  7860. * `o32'                                    (3): Section A.134.
  7861. * `.OBJ'                                   (1): Section 7.1.
  7862. * `obj'                                    (1): Section 2.1.1.
  7863. * `obj'                                    (2): Section 6.2.
  7864. * `object'                                 (1): Section 6.5.3.
  7865. * octal                                    (1): Section 3.4.1.
  7866. * `OF_DBG'                                 (1): Section 6.10.
  7867. * `OF_DEFAULT'                             (1): Section 2.1.2.
  7868. * `OFFSET'                                 (1): Section 2.2.2.
  7869. * OMF                                      (1): Section 6.2.
  7870. * omitted parameters                       (1): Section 4.2.4.
  7871. * one's complement                         (1): Section 3.5.7.
  7872. * OpenBSD                                  (1): Section 6.7.
  7873. * OpenBSD                                  (2): Section 8.2.
  7874. * operands                                 (1): Section 3.1.
  7875. * operand-size prefixes                    (1): Section 3.1.
  7876. * operating system, writing                (1): Section 9.1.
  7877. * operating system                         (1): Section 6.1.
  7878. * operators                                (1): Section 3.5.
  7879. * `OR'                                     (1): Section A.110.
  7880. * `ORG'                                    (1): Section 6.1.1.
  7881. * `ORG'                                    (2): Section 7.2.1.
  7882. * `ORG'                                    (3): Section 7.2.2.
  7883. * `ORG'                                    (4): Section 10.1.3.
  7884. * `orphan-labels'                          (1): Section 2.1.10.
  7885. * `orphan-labels'                          (2): Section 3.1.
  7886. * OS/2                                     (1): Section 6.2.
  7887. * OS/2                                     (2): Section 6.2.1.
  7888. * `OUT'                                    (1): Section A.111.
  7889. * out of range, jumps                      (1): Section 10.1.2.
  7890. * output file format                       (1): Section 2.1.2.
  7891. * output formats                           (1): Chapter 6.
  7892. * `OUTSB'                                  (1): Section A.112.
  7893. * `OUTSD'                                  (1): Section A.112.
  7894. * `OUTSW'                                  (1): Section A.112.
  7895. * overlapping segments                     (1): Section 3.6.
  7896. * `OVERLAY'                                (1): Section 6.2.1.
  7897. * overloading multi-line macros            (1): Section 4.2.1.
  7898. * overloading, single-line macros          (1): Section 4.1.1.
  7899. * `-p' option                              (1): Section 2.1.6.
  7900. * `-p' option                              (2): Section 4.5.
  7901. * `PACKSSDW'                               (1): Section A.113.
  7902. * `PACKSSWB'                               (1): Section A.113.
  7903. * `PACKUSWB'                               (1): Section A.113.
  7904. * `PADDSIW'                                (1): Section A.115.
  7905. * `PADDxx'                                 (1): Section A.114.
  7906. * `PAND'                                   (1): Section A.116.
  7907. * `PANDN'                                  (1): Section A.116.
  7908. * paradox                                  (1): Section 3.7.
  7909. * `PASCAL'                                 (1): Section 7.5.3.
  7910. * Pascal calling convention                (1): Section 7.5.1.
  7911. * passes, assembly                         (1): Section 3.7.
  7912. * `PATH'                                   (1): Section 1.3.1.
  7913. * `PAVEB'                                  (1): Section A.117.
  7914. * `PCMPxx'                                 (1): Section A.118.
  7915. * `PDISTIB'                                (1): Section A.119.
  7916. * period                                   (1): Section 3.8.
  7917. * Perl                                     (1): Section 1.3.1.
  7918. * perverse                                 (1): Section 2.1.5.
  7919. * PharLap                                  (1): Section 6.2.1.
  7920. * PIC                                      (1): Section 6.5.2.
  7921. * PIC                                      (2): Section 6.7.
  7922. * PIC                                      (3): Section 8.2.
  7923. * `..plt'                                  (1): Section 6.5.2.
  7924. * `PLT' relocations                        (1): Section 6.5.2.
  7925. * `PLT' relocations                        (2): Section 8.2.4.
  7926. * `PLT' relocations                        (3): Section 8.2.5.
  7927. * plt relocations                          (1): Section 8.2.5.
  7928. * `PMACHRIW'                               (1): Section A.120.
  7929. * `PMADDWD'                                (1): Section A.121.
  7930. * `PMAGW'                                  (1): Section A.122.
  7931. * `PMULHRIW'                               (1): Section A.123.
  7932. * `PMULHRW'                                (1): Section A.123.
  7933. * `PMULHW'                                 (1): Section A.124.
  7934. * `PMULLW'                                 (1): Section A.124.
  7935. * `PMVccZB'                                (1): Section A.125.
  7936. * `%pop'                                   (1): Section 4.6.
  7937. * `%pop'                                   (2): Section 4.6.1.
  7938. * `POP'                                    (1): Section A.126.
  7939. * `POPAx'                                  (1): Section A.127.
  7940. * `POPFx'                                  (1): Section A.128.
  7941. * `POR'                                    (1): Section A.129.
  7942. * position-independent code                (1): Section 6.5.2.
  7943. * position-independent code                (2): Section 6.7.
  7944. * position-independent code                (3): Section 8.2.
  7945. * precedence                               (1): Section 3.5.
  7946. * pre-defining macros                      (1): Section 2.1.7.
  7947. * pre-defining macros                      (2): Section 4.1.1.
  7948. * preferred                                (1): Section 3.6.
  7949. * $prefix                                  (1): Section 3.1.
  7950. * $prefix                                  (2): Section 3.4.1.
  7951. * pre-including files                      (1): Section 2.1.6.
  7952. * preprocess-only mode                     (1): Section 2.1.8.
  7953. * preprocessor                             (1): Section 2.1.8.
  7954. * preprocessor                             (2): Section 2.1.9.
  7955. * preprocessor                             (3): Section 3.2.4.
  7956. * preprocessor                             (4): Section 3.5.6.
  7957. * preprocessor                             (5): Chapter 4.
  7958. * preprocessor expressions                 (1): Section 2.1.8.
  7959. * preprocessor loops                       (1): Section 4.4.
  7960. * preprocessor variables                   (1): Section 4.1.2.
  7961. * primitive directives                     (1): Chapter 5.
  7962. * `PRIVATE'                                (1): Section 6.2.1.
  7963. * `proc'                                   (1): Section 7.4.5.
  7964. * `proc'                                   (2): Section 8.1.4.
  7965. * procedure linkage table                  (1): Section 6.5.2.
  7966. * procedure linkage table                  (2): Section 8.2.4.
  7967. * procedure linkage table                  (3): Section 8.2.5.
  7968. * processor mode                           (1): Section 5.1.
  7969. * `progbits'                               (1): Section 6.5.1.
  7970. * program entry point                      (1): Section 6.2.6.
  7971. * program entry point                      (2): Section 7.1.1.
  7972. * program origin                           (1): Section 6.1.1.
  7973. * pseudo-instructions                      (1): Section 3.2.
  7974. * `PSLLx'                                  (1): Section A.130.
  7975. * `PSRAx'                                  (1): Section A.130.
  7976. * `PSRLx'                                  (1): Section A.130.
  7977. * `PSUBSIW'                                (1): Section A.132.
  7978. * `PSUBxx'                                 (1): Section A.131.
  7979. * `PUBLIC'                                 (1): Section 5.5.
  7980. * `PUBLIC'                                 (2): Section 6.2.1.
  7981. * `PUNPCKxxx'                              (1): Section A.133.
  7982. * pure binary                              (1): Section 6.1.
  7983. * `%push'                                  (1): Section 4.6.
  7984. * `%push'                                  (2): Section 4.6.1.
  7985. * `PUSH'                                   (1): Section A.134.
  7986. * `PUSHAx'                                 (1): Section A.135.
  7987. * `PUSHFx'                                 (1): Section A.136.
  7988. * `PXOR'                                   (1): Section A.137.
  7989. * QBasic                                   (1): Section 1.3.1.
  7990. * quick start                              (1): Section 2.2.
  7991. * `QWORD'                                  (1): Section 3.1.
  7992. * `RCL'                                    (1): Section A.138.
  7993. * `RCR'                                    (1): Section A.138.
  7994. * `rdf'                                    (1): Section 2.1.1.
  7995. * `rdf'                                    (2): Section 6.9.
  7996. * `RDMSR'                                  (1): Section A.139.
  7997. * `rdoff' subdirectory                     (1): Section 1.3.2.
  7998. * `rdoff' subdirectory                     (2): Section 6.9.
  7999. * `RDPMC'                                  (1): Section A.140.
  8000. * `RDTSC'                                  (1): Section A.141.
  8001. * redirecting errors                       (1): Section 2.1.4.
  8002. * register push                            (1): Section A.134.
  8003. * relational operators                     (1): Section 4.3.3.
  8004. * Relocatable Dynamic Object File Format   (1): Section 6.9.
  8005. * relocations, PIC-specific                (1): Section 6.5.2.
  8006. * removing contexts                        (1): Section 4.6.1.
  8007. * renaming contexts                        (1): Section 4.6.4.
  8008. * `%rep'                                   (1): Section 3.2.5.
  8009. * `%rep'                                   (2): Section 4.4.
  8010. * repeating                                (1): Section 3.2.5.
  8011. * repeating                                (2): Section 4.4.
  8012. * `%repl'                                  (1): Section 4.6.4.
  8013. * reporting bugs                           (1): Section 10.2.
  8014. * `RESB'                                   (1): Section 2.2.7.
  8015. * `RESB'                                   (2): Section 3.2.
  8016. * `RESB'                                   (3): Section 3.2.2.
  8017. * `RESB'                                   (4): Section 3.7.
  8018. * `RESD'                                   (1): Section 3.2.
  8019. * `RESD'                                   (2): Section 3.2.2.
  8020. * `RESQ'                                   (1): Section 3.2.
  8021. * `RESQ'                                   (2): Section 3.2.2.
  8022. * `REST'                                   (1): Section 3.2.
  8023. * `REST'                                   (2): Section 3.2.2.
  8024. * restricted memory references             (1): Section A.1.
  8025. * `RESW'                                   (1): Section 3.2.
  8026. * `RESW'                                   (2): Section 3.2.2.
  8027. * `RET'                                    (1): Section A.142.
  8028. * `RETF'                                   (1): Section A.142.
  8029. * `RETN'                                   (1): Section A.142.
  8030. * `ROL'                                    (1): Section A.143.
  8031. * `ROR'                                    (1): Section A.143.
  8032. * `%rotate'                                (1): Section 4.2.6.
  8033. * rotating macro parameters                (1): Section 4.2.6.
  8034. * `RSM'                                    (1): Section A.144.
  8035. * `-s' option                              (1): Section 2.1.4.
  8036. * `SAHF'                                   (1): Section A.145.
  8037. * `SAL'                                    (1): Section A.146.
  8038. * `SALC'                                   (1): Section A.147.
  8039. * `SAR'                                    (1): Section A.146.
  8040. * `SBB'                                    (1): Section A.148.
  8041. * `SCASB'                                  (1): Section A.149.
  8042. * `SCASD'                                  (1): Section A.149.
  8043. * `SCASW'                                  (1): Section A.149.
  8044. * searching for include files              (1): Section 4.5.
  8045. * `__SECT__'                               (1): Section 5.2.1.
  8046. * `__SECT__'                               (2): Section 5.3.
  8047. * `SECTION'                                (1): Section 5.2.
  8048. * `SECTION', `elf' extensions to           (1): Section 6.5.1.
  8049. * `SECTION', `win32' extensions to         (1): Section 6.3.1.
  8050. * section alignment, in `bin'              (1): Section 6.1.2.
  8051. * section alignment, in `elf'              (1): Section 6.5.1.
  8052. * section alignment, in `obj'              (1): Section 6.2.1.
  8053. * section alignment, in `win32'            (1): Section 6.3.1.
  8054. * section, bin extensions to               (1): Section 6.1.2.
  8055. * `SEG'                                    (1): Section 3.5.7.
  8056. * `SEG'                                    (2): Section 3.6.
  8057. * `SEG'                                    (3): Section 6.2.
  8058. * `SEGMENT'                                (1): Section 5.2.
  8059. * `SEGMENT', `elf' extensions to           (1): Section 6.2.1.
  8060. * segment address                          (1): Section 3.5.7.
  8061. * segment address                          (2): Section 3.6.
  8062. * segment alignment, in `bin'              (1): Section 6.1.2.
  8063. * segment alignment, in `obj'              (1): Section 6.2.1.
  8064. * segment names, Borland Pascal            (1): Section 7.5.2.
  8065. * segment override                         (1): Section 2.2.4.
  8066. * segment override                         (2): Section 3.1.
  8067. * segment registers                        (1): Section A.2.1.
  8068. * segments                                 (1): Section 3.6.
  8069. * segments, groups of                      (1): Section 6.2.2.
  8070. * separator character                      (1): Section 2.1.11.
  8071. * `SETcc'                                  (1): Section A.150.
  8072. * `SGDT'                                   (1): Section A.151.
  8073. * shared libraries                         (1): Section 6.7.
  8074. * shared libraries                         (2): Section 8.2.
  8075. * shared library                           (1): Section 6.5.3.
  8076. * shift command                            (1): Section 4.2.6.
  8077. * `SHL'                                    (1): Section A.152.
  8078. * `SHLD'                                   (1): Section A.153.
  8079. * `SHR'                                    (1): Section A.152.
  8080. * `SHRD'                                   (1): Section A.153.
  8081. * SIB byte                                 (1): Section A.2.
  8082. * SIB byte                                 (2): Section A.2.3.
  8083. * `SIDT'                                   (1): Section A.151.
  8084. * signed division                          (1): Section 3.5.6.
  8085. * signed modulo                            (1): Section 3.5.6.
  8086. * single-line macros                       (1): Section 4.1.
  8087. * size, of symbols                         (1): Section 6.5.3.
  8088. * `SLDT'                                   (1): Section A.151.
  8089. * `SMI'                                    (1): Section A.154.
  8090. * `SMSW'                                   (1): Section A.155.
  8091. * `-soname'                                (1): Section 8.2.6.
  8092. * sound                                    (1): Section 3.2.3.
  8093. * source code                              (1): Section 1.3.1.
  8094. * source-listing file                      (1): Section 2.1.3.
  8095. * square brackets                          (1): Section 2.2.2.
  8096. * square brackets                          (2): Section 3.3.
  8097. * `STACK'                                  (1): Section 6.2.1.
  8098. * standard macros                          (1): Section 4.7.
  8099. * standardised section names               (1): Section 5.2.
  8100. * standardised section names               (2): Section 6.1.
  8101. * standardised section names               (3): Section 6.3.1.
  8102. * standardised section names               (4): Section 6.5.1.
  8103. * standardised section names               (5): Section 6.6.
  8104. * standardised section names               (6): Section 6.7.
  8105. * standardised section names               (7): Section 6.8.
  8106. * standardised section names               (8): Section 6.9.
  8107. * `..start'                                (1): Section 6.2.6.
  8108. * `..start'                                (2): Section 7.1.1.
  8109. * `STC'                                    (1): Section A.156.
  8110. * `STD'                                    (1): Section A.156.
  8111. * `stderr'                                 (1): Section 2.1.4.
  8112. * `stdout'                                 (1): Section 2.1.4.
  8113. * `STI'                                    (1): Section A.156.
  8114. * `STOSB'                                  (1): Section A.157.
  8115. * `STOSD'                                  (1): Section A.157.
  8116. * `STOSW'                                  (1): Section A.157.
  8117. * `STR'                                    (1): Section A.158.
  8118. * string constant                          (1): Section 3.2.1.
  8119. * `STRUC'                                  (1): Section 4.7.3.
  8120. * `STRUC'                                  (2): Section 5.3.
  8121. * `STRUC'                                  (3): Section 7.4.4.
  8122. * `STRUC'                                  (4): Section 8.1.3.
  8123. * stub preprocessor                        (1): Section 2.1.9.
  8124. * `SUB'                                    (1): Section A.159.
  8125. * subtraction                              (1): Section 3.5.5.
  8126. * `sunsite.unc.edu'                        (1): Section 1.2.
  8127. * suppressible warning                     (1): Section 2.1.10.
  8128. * suppressing preprocessing                (1): Section 2.1.9.
  8129. * switching between sections               (1): Section 5.2.
  8130. * `..sym'                                  (1): Section 6.5.2.
  8131. * symbol sizes, specifying                 (1): Section 6.5.3.
  8132. * symbol types, specifying                 (1): Section 6.5.3.
  8133. * symbols, exporting from DLLs             (1): Section 6.2.5.
  8134. * symbols, importing from DLLs             (1): Section 6.2.4.
  8135. * `.SYS'                                   (1): Section 6.1.
  8136. * `.SYS'                                   (2): Section 7.3.
  8137. * TASM                                     (1): Section 1.1.1.
  8138. * TASM                                     (2): Section 2.2.
  8139. * TASM                                     (3): Section 6.2.
  8140. * `TBYTE'                                  (1): Section 2.2.7.
  8141. * `TEST'                                   (1): Section A.160.
  8142. * `test' subdirectory                      (1): Section 7.1.1.
  8143. * test registers                           (1): Section A.2.1.
  8144. * testing arbitrary numeric expressions    (1): Section 4.3.3.
  8145. * testing exact text identity              (1): Section 4.3.4.
  8146. * testing single-line macro existence      (1): Section 4.3.1.
  8147. * testing the context stack                (1): Section 4.3.2.
  8148. * testing token types                      (1): Section 4.3.5.
  8149. * `.text'                                  (1): Section 6.1.
  8150. * `.text'                                  (2): Section 6.5.1.
  8151. * `.text'                                  (3): Section 6.6.
  8152. * `.text'                                  (4): Section 6.7.
  8153. * `.text'                                  (5): Section 6.8.
  8154. * `.text'                                  (6): Section 6.9.
  8155. * `_TEXT'                                  (1): Section 7.4.2.
  8156. * `TIMES'                                  (1): Section 3.2.
  8157. * `TIMES'                                  (2): Section 3.2.5.
  8158. * `TIMES'                                  (3): Section 3.7.
  8159. * `TIMES'                                  (4): Section 10.1.3.
  8160. * `TIMES'                                  (5): Section 10.1.4.
  8161. * TLINK                                    (1): Section 7.2.2.
  8162. * trailing colon                           (1): Section 3.1.
  8163. * two-pass assembler                       (1): Section 3.7.
  8164. * `TWORD'                                  (1): Section 2.2.7.
  8165. * `TWORD'                                  (2): Section 3.1.
  8166. * type, of symbols                         (1): Section 6.5.3.
  8167. * `UMOV'                                   (1): Section A.161.
  8168. * unary operators                          (1): Section 3.5.7.
  8169. * underscore, in C symbols                 (1): Section 7.4.1.
  8170. * uninitialised                            (1): Section 3.2.
  8171. * uninitialised                            (2): Section 3.2.2.
  8172. * uninitialised storage                    (1): Section 2.2.7.
  8173. * Unix                                     (1): Section 1.3.2.
  8174. * Unix source archive                      (1): Section 1.3.2.
  8175. * unrolled loops                           (1): Section 3.2.5.
  8176. * unsigned division                        (1): Section 3.5.6.
  8177. * unsigned modulo                          (1): Section 3.5.6.
  8178. * `UPPERCASE'                              (1): Section 2.2.1.
  8179. * `UPPERCASE'                              (2): Section 6.2.3.
  8180. * `USE16'                                  (1): Section 6.2.1.
  8181. * `USE32'                                  (1): Section 6.2.1.
  8182. * user-defined errors                      (1): Section 4.3.6.
  8183. * user-level assembler directives          (1): Section 4.7.
  8184. * user-level directives                    (1): Chapter 5.
  8185. * VAL                                      (1): Section 7.1.1.
  8186. * valid characters                         (1): Section 3.1.
  8187. * variable types                           (1): Section 2.2.3.
  8188. * `VERR'                                   (1): Section A.162.
  8189. * version number of NASM                   (1): Section 4.7.1.
  8190. * `VERW'                                   (1): Section A.162.
  8191. * Visual C++                               (1): Section 6.3.
  8192. * `-w' option                              (1): Section 2.1.10.
  8193. * `WAIT'                                   (1): Section A.163.
  8194. * warnings                                 (1): Section 2.1.10.
  8195. * `WBINVD'                                 (1): Section A.164.
  8196. * Win32                                    (1): Section 1.3.1.
  8197. * Win32                                    (2): Section 2.1.1.
  8198. * Win32                                    (3): Section 6.2.
  8199. * Win32                                    (4): Section 6.3.
  8200. * Win32                                    (5): Chapter 8.
  8201. * Windows                                  (1): Section 7.1.
  8202. * Windows 95                               (1): Section 1.3.1.
  8203. * Windows NT                               (1): Section 1.3.1.
  8204. * `write'                                  (1): Section 6.5.1.
  8205. * writing operating systems                (1): Section 9.1.
  8206. * `WRMSR'                                  (1): Section A.165.
  8207. * `WRT'                                    (1): Section 3.6.
  8208. * `WRT'                                    (2): Section 6.2.
  8209. * `WRT'                                    (3): Section 6.5.2.
  8210. * `WRT'                                    (4): Section 6.7.
  8211. * `WRT ..got'                              (1): Section 8.2.3.
  8212. * `WRT ..gotoff'                           (1): Section 8.2.2.
  8213. * `WRT ..gotpc'                            (1): Section 8.2.1.
  8214. * `WRT ..plt'                              (1): Section 8.2.5.
  8215. * `WRT ..sym'                              (1): Section 8.2.4.
  8216. * WWW page                                 (1): Section 1.2.
  8217. * `www.delorie.com'                        (1): Section 7.1.1.
  8218. * `www.pcorner.com'                        (1): Section 7.1.1.
  8219. * `www.perl.org'                           (1): Section 1.3.1.
  8220. * `XADD'                                   (1): Section A.166.
  8221. * `XBTS'                                   (1): Section A.167.
  8222. * `XCHG'                                   (1): Section A.168.
  8223. * `x2ftp.oulu.fi'                          (1): Section 7.1.1.
  8224. * `XLATB'                                  (1): Section A.169.
  8225. * `XOR'                                    (1): Section A.170.
  8226. Tag Table:
  8227. Node: Top
  8228. Node: Chapter 1
  8229. Node: Section 1.1
  8230. Node: Section 1.1.1
  8231. Node: Section 1.1.2
  8232. Node: Section 1.2
  8233. Node: Section 1.3
  8234. Node: Section 1.3.1
  8235. Node: Section 1.3.2
  8236. Node: Chapter 2
  8237. Node: Section 2.1
  8238. Node: Section 2.1.1
  8239. 11071
  8240. Node: Section 2.1.2
  8241. 12441
  8242. Node: Section 2.1.3
  8243. 13197
  8244. Node: Section 2.1.4
  8245. 13849
  8246. Node: Section 2.1.5
  8247. 14594
  8248. Node: Section 2.1.6
  8249. 16037
  8250. Node: Section 2.1.7
  8251. 16507
  8252. Node: Section 2.1.8
  8253. 17268
  8254. Node: Section 2.1.9
  8255. 18055
  8256. Node: Section 2.1.10
  8257. 18600
  8258. Node: Section 2.1.11
  8259. 20467
  8260. Node: Section 2.2
  8261. 21688
  8262. Node: Section 2.2.1
  8263. 22484
  8264. Node: Section 2.2.2
  8265. 23093
  8266. Node: Section 2.2.3
  8267. 25448
  8268. Node: Section 2.2.4
  8269. 26314
  8270. Node: Section 2.2.5
  8271. 26721
  8272. Node: Section 2.2.6
  8273. 27484
  8274. Node: Section 2.2.7
  8275. 28115
  8276. Node: Chapter 3
  8277. 28970
  8278. Node: Section 3.1
  8279. 29397
  8280. Node: Section 3.2
  8281. 33422
  8282. Node: Section 3.2.1
  8283. 34261
  8284. Node: Section 3.2.2
  8285. 35476
  8286. Node: Section 3.2.3
  8287. 36410
  8288. Node: Section 3.2.4
  8289. 37152
  8290. Node: Section 3.2.5
  8291. 38131
  8292. Node: Section 3.3
  8293. 39681
  8294. Node: Section 3.4
  8295. 42433
  8296. Node: Section 3.4.1
  8297. 42825
  8298. Node: Section 3.4.2
  8299. 43806
  8300. Node: Section 3.4.3
  8301. 44676
  8302. Node: Section 3.4.4
  8303. 45854
  8304. Node: Section 3.5
  8305. 47292
  8306. Node: Section 3.5.1
  8307. 48813
  8308. Node: Section 3.5.2
  8309. 49147
  8310. Node: Section 3.5.3
  8311. 49361
  8312. Node: Section 3.5.4
  8313. 49575
  8314. Node: Section 3.5.5
  8315. 50077
  8316. Node: Section 3.5.6
  8317. 50369
  8318. Node: Section 3.5.7
  8319. 51122
  8320. Node: Section 3.6
  8321. 51664
  8322. Node: Section 3.7
  8323. 53728
  8324. Node: Section 3.8
  8325. 57141
  8326. Node: Chapter 4
  8327. 59602
  8328. Node: Section 4.1
  8329. 60295
  8330. Node: Section 4.1.1
  8331. 60545
  8332. Node: Section 4.1.2
  8333. 63363
  8334. Node: Section 4.2
  8335. 64649
  8336. Node: Section 4.2.1
  8337. 66652
  8338. Node: Section 4.2.2
  8339. 68015
  8340. Node: Section 4.2.3
  8341. 69174
  8342. Node: Section 4.2.4
  8343. 71462
  8344. Node: Section 4.2.5
  8345. 73647
  8346. Node: Section 4.2.6
  8347. 74174
  8348. Node: Section 4.2.7
  8349. 76898
  8350. Node: Section 4.2.8
  8351. 78927
  8352. Node: Section 4.2.9
  8353. 80316
  8354. Node: Section 4.3
  8355. 81160
  8356. Node: Section 4.3.1
  8357. 82249
  8358. Node: Section 4.3.2
  8359. 83353
  8360. Node: Section 4.3.3
  8361. 83968
  8362. Node: Section 4.3.4
  8363. 85425
  8364. Node: Section 4.3.5
  8365. 86421
  8366. Node: Section 4.3.6
  8367. 88600
  8368. Node: Section 4.4
  8369. 89474
  8370. Node: Section 4.5
  8371. 91165
  8372. Node: Section 4.6
  8373. 92532
  8374. Node: Section 4.6.1
  8375. 93703
  8376. Node: Section 4.6.2
  8377. 94434
  8378. Node: Section 4.6.3
  8379. 95455
  8380. Node: Section 4.6.4
  8381. 95975
  8382. Node: Section 4.6.5
  8383. 96736
  8384. Node: Section 4.7
  8385. 99165
  8386. Node: Section 4.7.1
  8387. 100148
  8388. Node: Section 4.7.2
  8389. 100631
  8390. Node: Section 4.7.3
  8391. 101984
  8392. Node: Section 4.7.4
  8393. 104334
  8394. Node: Section 4.7.5
  8395. 105874
  8396. Node: Chapter 5
  8397. 108362
  8398. Node: Section 5.1
  8399. 109846
  8400. Node: Section 5.2
  8401. 111794
  8402. Node: Section 5.2.1
  8403. 112837
  8404. Node: Section 5.3
  8405. 114652
  8406. Node: Section 5.4
  8407. 116545
  8408. Node: Section 5.5
  8409. 118069
  8410. Node: Section 5.6
  8411. 119265
  8412. Node: Chapter 6
  8413. 120506
  8414. Node: Section 6.1
  8415. 121950
  8416. Node: Section 6.1.1
  8417. 123550
  8418. Node: Section 6.1.2
  8419. 124573
  8420. Node: Section 6.2
  8421. 125323
  8422. Node: Section 6.2.1
  8423. 127806
  8424. Node: Section 6.2.2
  8425. 130795
  8426. Node: Section 6.2.3
  8427. 132497
  8428. Node: Section 6.2.4
  8429. 133223
  8430. Node: Section 6.2.5
  8431. 134212
  8432. Node: Section 6.2.6
  8433. 136199
  8434. Node: Section 6.2.7
  8435. 136752
  8436. Node: Section 6.2.8
  8437. 138320
  8438. Node: Section 6.3
  8439. 140206
  8440. Node: Section 6.3.1
  8441. 141296
  8442. Node: Section 6.4
  8443. 143535
  8444. Node: Section 6.5
  8445. 144051
  8446. Node: Section 6.5.1
  8447. 144658
  8448. Node: Section 6.5.2
  8449. 146575
  8450. Node: Section 6.5.3
  8451. 149576
  8452. Node: Section 6.5.4
  8453. 151120
  8454. Node: Section 6.6
  8455. 151778
  8456. Node: Section 6.7
  8457. 152624
  8458. Node: Section 6.8
  8459. 153788
  8460. Node: Section 6.9
  8461. 154656
  8462. Node: Section 6.9.1
  8463. 155804
  8464. Node: Section 6.10
  8465. 156279
  8466. Node: Chapter 7
  8467. 158555
  8468. Node: Section 7.1
  8469. 159308
  8470. Node: Section 7.1.1
  8471. 160403
  8472. Node: Section 7.1.2
  8473. 163906
  8474. Node: Section 7.2
  8475. 166287
  8476. Node: Section 7.2.1
  8477. 166796
  8478. Node: Section 7.2.2
  8479. 168328
  8480. Node: Section 7.3
  8481. 169910
  8482. Node: Section 7.4
  8483. 170919
  8484. Node: Section 7.4.1
  8485. 171593
  8486. Node: Section 7.4.2
  8487. 173096
  8488. Node: Section 7.4.3
  8489. 176555
  8490. Node: Section 7.4.4
  8491. 183307
  8492. Node: Section 7.4.5
  8493. 185503
  8494. Node: Section 7.5
  8495. 188017
  8496. Node: Section 7.5.1
  8497. 189756
  8498. Node: Section 7.5.2
  8499. 194029
  8500. Node: Section 7.5.3
  8501. 195058
  8502. Node: Chapter 8
  8503. 196399
  8504. Node: Section 8.1
  8505. 197860
  8506. Node: Section 8.1.1
  8507. 198458
  8508. Node: Section 8.1.2
  8509. 199280
  8510. Node: Section 8.1.3
  8511. 203986
  8512. Node: Section 8.1.4
  8513. 206242
  8514. Node: Section 8.2
  8515. 207837
  8516. Node: Section 8.2.1
  8517. 210115
  8518. Node: Section 8.2.2
  8519. 212856
  8520. Node: Section 8.2.3
  8521. 214141
  8522. Node: Section 8.2.4
  8523. 215257
  8524. Node: Section 8.2.5
  8525. 217806
  8526. Node: Section 8.2.6
  8527. 218716
  8528. Node: Chapter 9
  8529. 219578
  8530. Node: Section 9.1
  8531. 220279
  8532. Node: Section 9.2
  8533. 222238
  8534. Node: Section 9.3
  8535. 224806
  8536. Node: Chapter 10
  8537. 227254
  8538. Node: Section 10.1
  8539. 227692
  8540. Node: Section 10.1.1
  8541. 228020
  8542. Node: Section 10.1.2
  8543. 228693
  8544. Node: Section 10.1.3
  8545. 229825
  8546. Node: Section 10.1.4
  8547. 231010
  8548. Node: Section 10.2
  8549. 232375
  8550. Node: Appendix A
  8551. 236891
  8552. Node: Section A.1
  8553. 247461
  8554. Node: Section A.2
  8555. 249525
  8556. Node: Section A.2.1
  8557. 253697
  8558. Node: Section A.2.2
  8559. 255416
  8560. Node: Section A.2.3
  8561. 256877
  8562. Node: Section A.3
  8563. 261449
  8564. Node: Section A.4
  8565. 263012
  8566. Node: Section A.5
  8567. 265005
  8568. Node: Section A.6
  8569. 266786
  8570. Node: Section A.7
  8571. 268443
  8572. Node: Section A.8
  8573. 270139
  8574. Node: Section A.9
  8575. 270750
  8576. Node: Section A.10
  8577. 271520
  8578. Node: Section A.11
  8579. 272373
  8580. Node: Section A.12
  8581. 272833
  8582. Node: Section A.13
  8583. 274573
  8584. Node: Section A.14
  8585. 276738
  8586. Node: Section A.15
  8587. 277589
  8588. Node: Section A.16
  8589. 278455
  8590. Node: Section A.17
  8591. 278784
  8592. Node: Section A.18
  8593. 279530
  8594. Node: Section A.19
  8595. 281103
  8596. Node: Section A.20
  8597. 282653
  8598. Node: Section A.21
  8599. 284596
  8600. Node: Section A.22
  8601. 285183
  8602. Node: Section A.23
  8603. 287123
  8604. Node: Section A.24
  8605. 288219
  8606. Node: Section A.25
  8607. 288898
  8608. Node: Section A.26
  8609. 289908
  8610. Node: Section A.27
  8611. 290409
  8612. Node: Section A.28
  8613. 292182
  8614. Node: Section A.29
  8615. 292584
  8616. Node: Section A.30
  8617. 292925
  8618. Node: Section A.31
  8619. 294051
  8620. Node: Section A.32
  8621. 294673
  8622. Node: Section A.33
  8623. 295015
  8624. Node: Section A.34
  8625. 295591
  8626. Node: Section A.35
  8627. 298246
  8628. Node: Section A.36
  8629. 300312
  8630. Node: Section A.37
  8631. 300652
  8632. Node: Section A.38
  8633. 301174
  8634. Node: Section A.39
  8635. 302055
  8636. Node: Section A.40
  8637. 304043
  8638. Node: Section A.41
  8639. 304374
  8640. Node: Section A.42
  8641. 304828
  8642. Node: Section A.43
  8643. 305516
  8644. Node: Section A.44
  8645. 306252
  8646. Node: Section A.45
  8647. 307291
  8648. Node: Section A.46
  8649. 307766
  8650. Node: Section A.47
  8651. 308409
  8652. Node: Section A.48
  8653. 308975
  8654. Node: Section A.49
  8655. 309722
  8656. Node: Section A.50
  8657. 310291
  8658. Node: Section A.51
  8659. 311274
  8660. Node: Section A.52
  8661. 311751
  8662. Node: Section A.53
  8663. 312289
  8664. Node: Section A.54
  8665. 313290
  8666. Node: Section A.55
  8667. 313569
  8668. Node: Section A.56
  8669. 314440
  8670. Node: Section A.57
  8671. 315824
  8672. Node: Section A.58
  8673. 316255
  8674. Node: Section A.59
  8675. 317095
  8676. Node: Section A.60
  8677. 317573
  8678. Node: Section A.61
  8679. 317998
  8680. Node: Section A.62
  8681. 318649
  8682. Node: Section A.63
  8683. 318983
  8684. Node: Section A.64
  8685. 319798
  8686. Node: Section A.65
  8687. 320440
  8688. Node: Section A.66
  8689. 321167
  8690. Node: Section A.67
  8691. 321833
  8692. Node: Section A.68
  8693. 323840
  8694. Node: Section A.69
  8695. 324280
  8696. Node: Section A.70
  8697. 326023
  8698. Node: Section A.71
  8699. 326610
  8700. Node: Section A.72
  8701. 327165
  8702. Node: Section A.73
  8703. 327687
  8704. Node: Section A.74
  8705. 328438
  8706. Node: Section A.75
  8707. 328795
  8708. Node: Section A.76
  8709. 329482
  8710. Node: Section A.77
  8711. 330493
  8712. Node: Section A.78
  8713. 332833
  8714. Node: Section A.79
  8715. 333667
  8716. Node: Section A.80
  8717. 334337
  8718. Node: Section A.81
  8719. 335706
  8720. Node: Section A.82
  8721. 336350
  8722. Node: Section A.83
  8723. 337586
  8724. Node: Section A.84
  8725. 337942
  8726. Node: Section A.85
  8727. 338512
  8728. Node: Section A.86
  8729. 338866
  8730. Node: Section A.87
  8731. 339851
  8732. Node: Section A.88
  8733. 340331
  8734. Node: Section A.89
  8735. 342521
  8736. Node: Section A.90
  8737. 343387
  8738. Node: Section A.91
  8739. 343755
  8740. Node: Section A.92
  8741. 344288
  8742. Node: Section A.93
  8743. 345555
  8744. Node: Section A.94
  8745. 346410
  8746. Node: Section A.95
  8747. 346878
  8748. Node: Section A.96
  8749. 347920
  8750. Node: Section A.97
  8751. 348386
  8752. Node: Section A.98
  8753. 349162
  8754. Node: Section A.99
  8755. 350304
  8756. Node: Section A.100
  8757. 352047
  8758. Node: Section A.101
  8759. 352793
  8760. Node: Section A.102
  8761. 353202
  8762. Node: Section A.103
  8763. 355835
  8764. Node: Section A.104
  8765. 356358
  8766. Node: Section A.105
  8767. 356797
  8768. Node: Section A.106
  8769. 358189
  8770. Node: Section A.107
  8771. 359022
  8772. Node: Section A.108
  8773. 359966
  8774. Node: Section A.109
  8775. 360765
  8776. Node: Section A.110
  8777. 361158
  8778. Node: Section A.111
  8779. 362867
  8780. Node: Section A.112
  8781. 363679
  8782. Node: Section A.113
  8783. 365006
  8784. Node: Section A.114
  8785. 366362
  8786. Node: Section A.115
  8787. 367775
  8788. Node: Section A.116
  8789. 368473
  8790. Node: Section A.117
  8791. 369176
  8792. Node: Section A.118
  8793. 369673
  8794. Node: Section A.119
  8795. 371027
  8796. Node: Section A.120
  8797. 371922
  8798. Node: Section A.121
  8799. 372595
  8800. Node: Section A.122
  8801. 373182
  8802. Node: Section A.123
  8803. 373744
  8804. Node: Section A.124
  8805. 374777
  8806. Node: Section A.125
  8807. 375456
  8808. Node: Section A.126
  8809. 376687
  8810. Node: Section A.127
  8811. 378658
  8812. Node: Section A.128
  8813. 379812
  8814. Node: Section A.129
  8815. 380553
  8816. Node: Section A.130
  8817. 381023
  8818. Node: Section A.131
  8819. 383190
  8820. Node: Section A.132
  8821. 384778
  8822. Node: Section A.133
  8823. 385408
  8824. Node: Section A.134
  8825. 387114
  8826. Node: Section A.135
  8827. 389423
  8828. Node: Section A.136
  8829. 390518
  8830. Node: Section A.137
  8831. 391267
  8832. Node: Section A.138
  8833. 391743
  8834. Node: Section A.139
  8835. 393830
  8836. Node: Section A.140
  8837. 394263
  8838. Node: Section A.141
  8839. 394667
  8840. Node: Section A.142
  8841. 394985
  8842. Node: Section A.143
  8843. 396013
  8844. Node: Section A.144
  8845. 397999
  8846. Node: Section A.145
  8847. 398366
  8848. Node: Section A.146
  8849. 398736
  8850. Node: Section A.147
  8851. 400853
  8852. Node: Section A.148
  8853. 401298
  8854. Node: Section A.149
  8855. 403143
  8856. Node: Section A.150
  8857. 404572
  8858. Node: Section A.151
  8859. 404931
  8860. Node: Section A.152
  8861. 405932
  8862. Node: Section A.153
  8863. 407955
  8864. Node: Section A.154
  8865. 409576
  8866. Node: Section A.155
  8867. 410036
  8868. Node: Section A.156
  8869. 410473
  8870. Node: Section A.157
  8871. 411193
  8872. Node: Section A.158
  8873. 412524
  8874. Node: Section A.159
  8875. 412872
  8876. Node: Section A.160
  8877. 414568
  8878. Node: Section A.161
  8879. 415532
  8880. Node: Section A.162
  8881. 416348
  8882. Node: Section A.163
  8883. 416907
  8884. Node: Section A.164
  8885. 417671
  8886. Node: Section A.165
  8887. 418266
  8888. Node: Section A.166
  8889. 418693
  8890. Node: Section A.167
  8891. 419290
  8892. Node: Section A.168
  8893. 419983
  8894. Node: Section A.169
  8895. 421073
  8896. Node: Section A.170
  8897. 421891
  8898. Node: Index
  8899. 423602
  8900. End Tag Table
  8901.