Next Chapter | Previous Chapter | Contents | Index
NASM, though it attempts to avoid the bureaucracy of assemblers like MASM and TASM, is nevertheless forced to support a few directives. These are described in this chapter.
NASM's directives come in two types: user-level directives and primitive directives. Typically, each directive has a user-level form and a primitive form. In almost all cases, we recommend that users use the user-level forms of the directives, which are implemented as macros which call the primitive forms.
Primitive directives are enclosed in square brackets; user-level directives are not.
In addition to the universal directives described in this chapter, each object file format can optionally supply extra directives in order to control particular features of that file format. These format-specific directives are documented along with the formats that implement them, in chapter 7.
BITS The 
In most cases, you should not need to use 
The most likely reason for using the 
You do not need to specify 
When NASM is in 
When NASM is in 
The default address size is 64 bits; 32-bit addressing can be selected
with the 0x67 prefix. The default operand size is still 32 bits, however,
and the 0x66 prefix selects 16-bit operand size. The
When the 
The 
Note that the space is neccessary, e.g. 
USE16 USE32 The `
DEFAULT The 
Currently, the only 
The special handling of 
SECTION SEGMENT The 
The Unix object formats, and the 
__SECT__ The 
        SECTION .text
expands to the two lines
%define __SECT__        [SECTION .text] 
        [SECTION .text]
Users may find it useful to make use of this in their own macros. For
example, the 
%macro  writefile 2+ 
        [section .data] 
  %%str:        db      %2 
  %%endstr: 
        __SECT__ 
        mov     dx,%%str 
        mov     cx,%%endstr-%%str 
        mov     bx,%1 
        mov     ah,0x40 
        int     0x21 
%endmacro
This form of the macro, once passed a string to output, first switches
temporarily to the data section of the file, using the primitive form of
the 
ABSOLUTE The 
absolute 0x1A 
    kbuf_chr    resw    1 
    kbuf_free   resw    1 
    kbuf        resw    16
This example describes a section of the PC BIOS data area, at segment
address 0x40: the above code defines 
The user-level form of 
        org     100h               ; it's a .COM program 
        jmp     setup              ; setup code comes last 
        ; the resident part of the TSR goes here 
setup: 
        ; now write the code that installs the TSR here 
absolute setup 
runtimevar1     resw    1 
runtimevar2     resd    20 
tsr_end:
This defines some variables `on top of' the setup code, so that after the setup has finished running, the space it took up can be re-used as data storage for the running TSR. The symbol `tsr_end' can be used to calculate the total size of the part of the TSR that needs to be made resident.
EXTERN 
The 
extern _printf extern _sscanf,_fscanf
Some object-file formats provide extra features to the
extern _variable:wrt dgroup
The primitive form of 
You can declare the same variable as 
GLOBAL 
The 
global _main 
_main: 
        ; some code
global hashlookup:function, hashtable:data
Like 
COMMON The 
common intvar 4
is similar in function to
global intvar section .bss intvar resd 1
The difference is that if more than one module defines the same common
variable, then at link time those variables will be merged, and
references to 
Like 
common commvar 4:near ; works in OBJ common intarray 100:4 ; works in ELF: 4 byte aligned
Once again, like 
CPU The 
Options are:
CPU 8086 CPU 186 CPU 286 CPU 386 CPU 486 CPU 586 CPU PENTIUM CPU 686 CPU PPRO CPU P2 CPU P3 CPU KATMAI CPU P4 CPU WILLAMETTE CPU PRESCOTT CPU X64 CPU IA64 All options are case insensitive. All instructions will be selected only if they apply to the selected CPU or lower. By default, all instructions are available.
FLOAT By default, floating-point constants are rounded to nearest, and IEEE denormals are supported. The following options can be set to alter this behaviour:
FLOAT DAZ FLOAT NODAZ FLOAT NEAR FLOAT UP FLOAT DOWN FLOAT ZERO FLOAT DEFAULT The standard macros