This assembly directives reference compares the three major x86/x64 assembler syntaxes side by side: GAS (GNU Assembler, AT&T syntax), NASM (Netwide Assembler, Intel syntax), and MASM (Microsoft Macro Assembler, Intel syntax). Use it to translate between toolchains when reading examples, porting code, or switching platforms.
For hands-on tutorials using these assemblers, see our Assembly Hello World (GAS & NASM on Linux/macOS) and Windows Assembly Toolchain: MASM Guide. The official manuals are the GNU Assembler Manual, NASM Documentation, and MASM Reference.
Section Directives
Sections partition your program into code, data, and uninitialized memory. This assembly directives reference starts with sections because they are the first thing in every source file.
| Purpose | GAS (GNU) | NASM | MASM |
|---|---|---|---|
| Code section | .text | section .text | .code |
| Initialized data | .data | section .data | .data |
| Uninitialized data | .bss | section .bss | .data? |
| Read-only data | .section .rodata | section .rodata | .const |
| Custom section | .section .mydata,"aw" | section .mydata | _mydata SEGMENT |
Symbol & Label Directives
These directives control symbol visibility and linking behavior. Getting them right is essential for multi-file projects and calling C library functions.
| Purpose | GAS (GNU) | NASM | MASM |
|---|---|---|---|
| Global symbol (export) | .global _start | global _start | PUBLIC _start |
| External symbol (import) | .extern printf* | extern printf | EXTERN printf:PROC |
| Weak symbol | .weak my_func | global my_func:function weak | — (not directly supported) |
| Local label | .L0: (dot prefix) | .local: (dot prefix) | @@: |
| Entry point marker | .global _start | global _start | END main |
*GAS .extern note: In modern GNU as, .extern is essentially a no-op compatibility directive — undefined symbols are automatically treated as external. It is accepted for documentation purposes and cross-assembler portability, but is not required.
Data Definition Directives
Data definition is where GAS, NASM, and MASM diverge the most. GAS uses descriptive names (.byte, .long), NASM uses traditional abbreviations (db, dd), and MASM uses uppercase versions (DB, DD). This assembly directives reference section is especially useful for translating between the three.
| Purpose | GAS (GNU) | NASM | MASM |
|---|---|---|---|
| Define byte (8-bit) | .byte 0x41 | db 0x41 | DB 41h |
| Define word (16-bit)* | .word 0x1234 / .short | dw 0x1234 | DW 1234h |
| Define double word (32-bit) | .long 42 | dd 42 | DD 42 |
| Define quad word (64-bit) | .quad 42 | dq 42 | DQ 42 |
| Define string | .ascii "hello" | db "hello" | DB "hello" |
| Null-terminated string | .asciz "hello" | db "hello", 0 | DB "hello", 0 |
| Define float (32-bit) | .float 3.14 | dd 3.14 | REAL4 3.14 |
| Define double (64-bit) | .double 3.14 | dq 3.14 | REAL8 3.14 |
| Reserve bytes (uninitialized) | .skip 64 / .space 64 | resb 64 | DB 64 DUP(?) |
| Reserve words | .skip 128 (bytes) | resw 64 | DW 64 DUP(?) |
| Reserve double words | .skip 256 (bytes) | resd 64 | DD 64 DUP(?) |
*.word cross-architecture caveat: On x86 GAS, .word defines a 16-bit value. However, on ARM AArch32 GAS, .word defines a 32-bit value. This page uses x86 semantics. When porting between architectures, prefer .short (always 16-bit) or .long (always 32-bit) for unambiguous sizing.
Alignment & Padding
Proper alignment improves performance and is sometimes required for SIMD instructions. The alignment directives have subtle semantic differences — GAS takes a power of two (or byte count depending on platform), NASM takes the byte boundary.
| Purpose | GAS (GNU) | NASM | MASM |
|---|---|---|---|
| Align to N bytes | .align 16 | align 16 | ALIGN 16 |
| Align with fill byte | .align 16, 0x90 | align 16, nop | ALIGN 16 |
| Pad with bytes | .fill 8, 1, 0x90 | times 8 nop | DB 8 DUP(90h) |
| Repeat instruction | .rept 4 / .endr | times 4 nop | REPT 4 / ENDM |
Macros & Conditional Assembly
All three assemblers support macros with parameters, but the syntax varies significantly. MASM has the most powerful macro system with advanced features like INVOKE for automatic parameter pushing.
| Purpose | GAS (GNU) | NASM | MASM |
|---|---|---|---|
| Define macro | .macro name arg1 | %macro name 1 | name MACRO arg1 |
| End macro | .endm | %endmacro | ENDM |
| Macro parameter reference | arg1 | %1 | arg1 |
| Conditional (if defined) | .ifdef SYMBOL | %ifdef SYMBOL | IFDEF SYMBOL |
| Conditional (if equal) | .if expr == 1 | %if expr == 1 | IF expr EQ 1 |
| Else | .else | %else | ELSE |
| End conditional | .endif | %endif | ENDIF |
| Include file | .include "file.inc" | %include "file.inc" | INCLUDE file.inc |
| Define constant | .equ NAME, 42 | NAME equ 42 | NAME EQU 42 |
Key Syntax Differences
Beyond directives, the three assemblers differ in how they express instructions themselves. These syntax differences are the most common source of confusion when translating between assemblers.
| Feature | GAS (AT&T) | NASM (Intel) | MASM (Intel) |
|---|---|---|---|
| Operand order | Source, Destination | Destination, Source | Destination, Source |
| Register prefix | %rax | rax | rax |
| Immediate prefix | $42 | 42 | 42 |
| Memory reference | (%rbp) or -8(%rbp) | [rbp] or [rbp-8] | [rbp] or [rbp-8] |
| Size suffix | movq, movl, movb | mov qword, mov dword | mov QWORD PTR |
| Comment | # comment | ; comment | ; comment |
| Hex format | 0x1234 | 0x1234 or 1234h | 1234h |
Example — the same instruction in all three syntaxes:
; Move the value at [rbp-8] into rax
GAS: movq -8(%rbp), %rax # source, destination
NASM: mov rax, qword [rbp-8] ; destination, source
MASM: mov rax, QWORD PTR [rbp-8] ; destination, source
Related Resources
Deep dives: Assembly Hello World: Cross-Platform Syscall Tutorial | Windows Assembly Toolchain: MASM Guide
Also see: Calling Conventions Cheat Sheet | x86-64 ↔ ARM64 Instruction Map | Systems Programming Glossary
Official documentation: GAS Manual | NASM Docs | MASM Reference
