Skip to content

Assembly Directives Reference: GAS vs NASM vs MASM

Compare the three major x86/x64 assembler syntaxes side by side: GAS (GNU Assembler), NASM (Netwide Assembler), and MASM (Microsoft Macro Assembler).

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.

Interactive Lab: Assembly Directives Quick Reference

Search and filter 22 essential assembler directives across GAS, NASM, and MASM. Expand any directive to compare syntax, see its purpose, and view real usage examples.


1. Section Control

Directives that define the memory segments where code and data will reside.

PurposeGAS (GNU)NASMMASMDescription
Code section.textsection .text.codeDefines the executable code section.
Initialized data.datasection .data.dataDefines the section for initialized variables.
Uninitialized data.bsssection .bss.data?Defines the section for uninitialized variables.
Read-only data.section .rodatasection .rodata.constDefines the section for constants/read-only data.
Custom section.section .mydata,"aw"section .mydata_mydata SEGMENTDefines a user-specified custom section.

2. Symbol & Scope

Directives that control the visibility and scope of symbols for the linker.

PurposeGAS (GNU)NASMMASMDescription
Global symbol.global _startglobal _startPUBLIC _startExports a symbol to make it visible to the linker.
External symbol.extern printfextern printfEXTERN printf:PROCImports a symbol defined in another file.
Weak symbol.weak my_funcglobal my_func:function weakDefines a symbol that can be overridden at link time.
Local label.L0:.local:@@:Defines a label with scope limited to the current block.
Entry point.global _startglobal _startEND mainMarks the starting point of the program.

3. Data Definition Directives

Directives used to allocate memory and initialize data of various sizes.

PurposeGAS (GNU)NASMMASMDescription
Define byte.byte 0x41db 0x41DB 41hDefines an 8-bit value.
Define word.word 0x1234dw 0x1234DW 1234hDefines a 16-bit value.
Define dword.long 42dd 42DD 42Defines a 32-bit value.
Define qword.quad 42dq 42DQ 42Defines a 64-bit value.
Define string.ascii "hello"db "hello"DB "hello"Defines a character string.
Null-term string.asciz "hello"db "hello", 0DB "hello", 0Defines a string with a trailing null byte.
Define float.float 3.14dd 3.14REAL4 3.14Defines a 32-bit floating point value.
Define double.double 3.14dq 3.14REAL8 3.14Defines a 64-bit floating point value.
Reserve bytes.skip 64resb 64DB 64 DUP(?)Reserves uninitialized space in bytes.
Reserve words.skip 128resw 64DW 64 DUP(?)Reserves uninitialized space in words.
Reserve dwords.skip 256resd 64DD 64 DUP(?)Reserves uninitialized space in double words.

4. Alignment & Spacing

Directives used to align instructions/data for performance or to pad sections.

PurposeGAS (GNU)NASMMASMDescription
Align to N.align 16align 16ALIGN 16Aligns the next instruction/data to a byte boundary.
Align with fill.align 16, 0x90align 16, nopALIGN 16Aligns to boundary and fills gap with specific byte.
Pad with bytes.fill 8, 1, 0x90times 8 nopDB 8 DUP(90h)Inserts a specific number of padding bytes.
Repeat.rept 4 / .endrtimes 4 nopREPT 4 / ENDMRepeats a block of code or an instruction.

5. Macros & Conditional Assembly

Directives used for basic metaprogramming and selective code generation.

PurposeGAS (GNU)NASMMASMDescription
Define macro.macro name arg1%macro name 1name MACRO arg1Starts a macro definition.
End macro.endm%endmacroENDMEnds a macro definition.
Macro param\arg1%1arg1References a parameter within a macro.
If defined.ifdef SYMBOL%ifdef SYMBOLIFDEF SYMBOLConditional assembly if a symbol is defined.
If equal.if expr == 1%if expr == 1IF expr EQ 1Conditional assembly based on an expression.
Else.else%elseELSEAlternative branch for conditional assembly.
End if.endif%endifENDIFEnds a conditional assembly block.
Define constant.equ NAME, 42NAME equ 42NAME EQU 42Assigns a constant value to a symbol.

6. External Files

Directives used to modularize source code across multiple files.

PurposeGAS (GNU)NASMMASMDescription
Include file.include "file.inc"%include "file.inc"INCLUDE file.incIncludes the contents of an external source file.

Key Syntax Differences

Beyond directives, the three assemblers differ in how they express instructions and operands:

FeatureGAS (AT&T)NASM (Intel)MASM (Intel)
Operand OrderSource, DestinationDestination, SourceDestination, Source
Register PrefixRequires % (e.g., %rax)None (e.g., rax)None (e.g., rax)
Immediate PrefixRequires $ (e.g., $42)None (e.g., 42)None (e.g., 42)
Memory Refoffset(base, index, scale)[base + index*scale + offset][base + index*scale + offset]
Size SuffixesSuffixes like q, l, w, bKeywords like qword, dwordKeywords like QWORD PTR
Comments#;;
Hex Format0x12340x1234 or 1234h1234h

Example Comparison

; Move the 64-bit 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

Deep Dives

Cheat Sheets

Official Manuals

Coder Musings

A modern technical laboratory for systems programming. Master Assembly, Compilers, and Low-Level Engineering through curated paths and interactive visualizations.

© 2026 Coder Musings. All rights reserved. Built for the systems community.