x86-64 directives

Directives are not executed by the processor: they tell the assembler where to put code and data, what bytes to emit, which names stand for which values, and when to expand a macro. The list is NASM's own, so it is what this editor accepts rather than what another assembler might.

Directives

Directives tell the assembler what to do. They are not instructions and the processor never sees them.

section

Opens a section: .text for code, .data for initialised data, .bss for space that starts as zeroes, .rodata for constants. Everything after the line belongs to that section until the next one. segment is the same directive under its other name.

global

Makes a label visible outside the file. The program has to declare _start, because that is the label the linker makes the entry point.

extern

Declares that a name is defined in another file, so this one may refer to it.

bits

Assembles for 16, 32 or 64 bit mode. Programs here are 64 bit and the object format already says so, so a program needs this only to say something unusual.

default

Chooses whether a bare memory reference is rel (an offset from rip) or abs (an absolute address). Long mode code is usually written default rel.

cpu

Refuses to assemble instructions newer than the processor named, which is a way to keep a program inside the instruction set a course is teaching.

absolute

Starts a block of labels that describe a layout without emitting anything, the way a structure declaration does.

Data and space

These live in the instruction table and behave like directives: they put bytes in the output, or reserve room for them.

db, dw, dd, dq

Emit bytes, words (2 bytes), doublewords (4) and quadwords (8), in order, where the line is. They take numbers, characters, strings and label addresses: msg: db "hi", 10.

dt, do, dy, dz

Emit 10, 16, 32 and 64 byte values, for the x87 and vector types.

resb, resw, resd, resq

Reserve room without writing anything: buffer: resb 64. They belong in .bss, which costs nothing in the file because it is all zeroes.

equ

Gives a name to a value, evaluated once where it is written: LEN equ 64. Nothing is emitted and nothing can change it later.

incbin

Copies a file into the output at this point, byte for byte.

times

Repeats the rest of the line: times 64 db 0 emits 64 zero bytes, and times 8 - ($ - start) db 0 pads to a fixed size.

The preprocessor

The preprocessor runs over the text before the assembler reads it, so it can define names, repeat blocks and include files, and knows nothing about registers or instructions.

%define

A macro expanded wherever its name appears, with arguments if it was given any. Expanded late, so it sees the value a name has when it is used.

%assign

A single line macro whose value is evaluated at once, and may be reassigned.

%macro

A multi line macro, ended by %endmacro. The number after the name says how many arguments it takes, and %1, %2 stand for them.

%include

Assembles another file here, the way a header is included.

%ifdef, %ifndef, %if

Assemble a block only under a condition, ending at %endif, with %else and %elif in between.

%rep

Repeats a block a fixed number of times, ending at %endrep.

Prefixes and operand sizes

Words that go in front of an instruction or an operand rather than standing on their own.

lock

Makes a read-modify-write instruction atomic against other processors. Only a handful of instructions accept it, and only when the destination is memory.

rep

Repeats a string instruction rcx times, counting down. On movs and stos this is the whole loop, written in one instruction.

repe, repz, repne, repnz

Repeat while the comparison keeps saying equal, or keeps saying not equal, and stop early when it changes. They are for cmps and scas, which set the flags on every step.

o16, o32, o64, a16, a32, a64

Force the operand or address size of one instruction, overriding what the mode implies. NASM chooses these on its own; writing one by hand is for the rare case where the choice matters.

byte, word, dword, qword

Say how wide a memory operand is, which the instruction cannot always work out on its own: mov qword [rsp], 0 writes eight bytes, mov byte [rsp], 0 writes one.

near, short, far

Choose the reach of a jump or call. NASM picks the shortest form that works, so these are for forcing a longer one.

rel, abs

Say whether a memory reference is an offset from rip or an absolute address, for one operand rather than for the file the way default does.

Everything else

The rest of what NASM accepts, from its own tables. These are here so the list is complete; the NASM manual documents them.

absolutebitscommoncpudebugdefaultdollarhexexternfloatglobalstaticlistsectionsegmentwarningsectalignpragmarequired %aliases%arg%assign%clear%defalias%define%defstr%deftok%depend%elif%elifctx%elifdef%elifdefalias%elifdifi%elifdirective%elifempty%elifenv%eliffile%elifid%elifidn%elifidni%elifmacro%elifn%elifnctx%elifndef%elifndefalias%elifndifi%elifndirective%elifnempty%elifnenv%elifnfile%elifnid%elifnidn%elifnidni%elifnmacro%elifnnum%elifnstr%elifntoken%elifnum%elifnusable%elifnusing%elifstr%eliftoken%elifusable%elifusing%else%endif%endm%endmacro%endrep%error%exitmacro%exitrep%fatal%if%ifctx%ifdef%ifdefalias%ifdifi%ifdirective%ifempty%ifenv%iffile%ifid%ifidn%ifidni%ifmacro%ifn%ifnctx%ifndef%ifndefalias%ifndifi%ifndirective%ifnempty%ifnenv%ifnfile%ifnid%ifnidn%ifnidni%ifnmacro%ifnnum%ifnstr%ifntoken%ifnum%ifnusable%ifnusing%ifstr%iftoken%ifusable%ifusing%include%line%local%macro%note%null%pathsearch%pop%pragma%push%rep%repl%require%rmacro%rotate%stacksize%strcat%strlen%substr%undef%undefalias%unmacro%use%warning%xdefine