<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>NASM - The Netwide Assembler</title> <link href="nasmdoc.css" rel="stylesheet" type="text/css" /> <link href="local.css" rel="stylesheet" type="text/css" /> </head> <body> <ul class="navbar"> <li class="first"><a class="prev" href="nasmdoc4.html">Chapter 4</a></li> <li><a class="next" href="nasmdoc6.html">Chapter 6</a></li> <li><a class="toc" href="nasmdoc0.html">Contents</a></li> <li class="last"><a class="index" href="nasmdoci.html">Index</a></li> </ul> <div class="title"> <h1>NASM - The Netwide Assembler</h1> <span class="subtitle">version 2.13.03</span> </div> <div class="contents" > <h2 id="chapter-5">Chapter 5: Standard Macro Packages</h2> <p>The <code>%use</code> directive (see <a href="nasmdoc4.html#section-4.6.4">section 4.6.4</a>) includes one of the standard macro packages included with the NASM distribution and compiled into the NASM binary. It operates like the <code>%include</code> directive (see <a href="nasmdoc4.html#section-4.6.1">section 4.6.1</a>), but the included contents is provided by NASM itself.</p> <p>The names of standard macro packages are case insensitive, and can be quoted or not.</p> <h3 id="section-5.1">5.1 <code>altreg</code>: Alternate Register Names</h3> <p>The <code>altreg</code> standard macro package provides alternate register names. It provides numeric register names for all registers (not just <code>R8</code>–<code>R15</code>), the Intel-defined aliases <code>R8L</code>–<code>R15L</code> for the low bytes of register (as opposed to the NASM/AMD standard names <code>R8B</code>–<code>R15B</code>), and the names <code>R0H</code>–<code>R3H</code> (by analogy with <code>R0L</code>–<code>R3L</code>) for <code>AH</code>, <code>CH</code>, <code>DH</code>, and <code>BH</code>.</p> <p>Example use:</p> <pre> %use altreg proc: mov r0l,r3h ; mov al,bh ret </pre> <p>See also <a href="nasmdo11.html#section-11.1">section 11.1</a>.</p> <h3 id="section-5.2">5.2 <code>smartalign</code>: Smart <code>ALIGN</code> Macro</h3> <p>The <code>smartalign</code> standard macro package provides for an <code>ALIGN</code> macro which is more powerful than the default (and backwards-compatible) one (see <a href="nasmdoc4.html#section-4.11.12">section 4.11.12</a>). When the <code>smartalign</code> package is enabled, when <code>ALIGN</code> is used without a second argument, NASM will generate a sequence of instructions more efficient than a series of <code>NOP</code>. Furthermore, if the padding exceeds a specific threshold, then NASM will generate a jump over the entire padding sequence.</p> <p>The specific instructions generated can be controlled with the new <code>ALIGNMODE</code> macro. This macro takes two parameters: one mode, and an optional jump threshold override. If (for any reason) you need to turn off the jump completely just set jump threshold value to –1 (or set it to <code>nojmp</code>). The following modes are possible:</p> <ul> <li> <p><code>generic</code>: Works on all x86 CPUs and should have reasonable performance. The default jump threshold is 8. This is the default.</p> </li> <li> <p><code>nop</code>: Pad out with <code>NOP</code> instructions. The only difference compared to the standard <code>ALIGN</code> macro is that NASM can still jump over a large padding area. The default jump threshold is 16.</p> </li> <li> <p><code>k7</code>: Optimize for the AMD K7 (Athlon/Althon XP). These instructions should still work on all x86 CPUs. The default jump threshold is 16.</p> </li> <li> <p><code>k8</code>: Optimize for the AMD K8 (Opteron/Althon 64). These instructions should still work on all x86 CPUs. The default jump threshold is 16.</p> </li> <li> <p><code>p6</code>: Optimize for Intel CPUs. This uses the long <code>NOP</code> instructions first introduced in Pentium Pro. This is incompatible with all CPUs of family 5 or lower, as well as some VIA CPUs and several virtualization solutions. The default jump threshold is 16.</p> </li> </ul> <p>The macro <code>__ALIGNMODE__</code> is defined to contain the current alignment mode. A number of other macros beginning with <code>__ALIGN_</code> are used internally by this macro package.</p> <h3 id="section-5.3">5.3 <code>fp</code>: Floating-point macros</h3> <p>This packages contains the following floating-point convenience macros:</p> <pre> %define Inf __Infinity__ %define NaN __QNaN__ %define QNaN __QNaN__ %define SNaN __SNaN__ %define float8(x) __float8__(x) %define float16(x) __float16__(x) %define float32(x) __float32__(x) %define float64(x) __float64__(x) %define float80m(x) __float80m__(x) %define float80e(x) __float80e__(x) %define float128l(x) __float128l__(x) %define float128h(x) __float128h__(x) </pre> <h3 id="section-5.4">5.4 <code>ifunc</code>: Integer functions</h3> <p>This package contains a set of macros which implement integer functions. These are actually implemented as special operators, but are most conveniently accessed via this macro package.</p> <p>The macros provided are:</p> <h4 id="section-5.4.1">5.4.1 Integer logarithms</h4> <p>These functions calculate the integer logarithm base 2 of their argument, considered as an unsigned integer. The only differences between the functions is their respective behavior if the argument provided is not a power of two.</p> <p>The function <code>ilog2e()</code> (alias <code>ilog2()</code>) generates an error if the argument is not a power of two.</p> <p>The function <code>ilog2f()</code> rounds the argument down to the nearest power of two; if the argument is zero it returns zero.</p> <p>The function <code>ilog2c()</code> rounds the argument up to the nearest power of two.</p> <p>The functions <code>ilog2fw()</code> (alias <code>ilog2w()</code>) and <code>ilog2cw()</code> generate a warning if the argument is not a power of two, but otherwise behaves like <code>ilog2f()</code> and <code>ilog2c()</code>, respectively.</p> </div> </body> </html>