Assembly Directives Reference: GAS vs NASM vs MASM Syntax Compared

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.

PurposeGAS (GNU)NASMMASM
Code section.textsection .text.code
Initialized data.datasection .data.data
Uninitialized data.bsssection .bss.data?
Read-only data.section .rodatasection .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.

PurposeGAS (GNU)NASMMASM
Global symbol (export).global _startglobal _startPUBLIC _start
External symbol (import).extern printf*extern printfEXTERN printf:PROC
Weak symbol.weak my_funcglobal my_func:function weak— (not directly supported)
Local label.L0: (dot prefix).local: (dot prefix)@@:
Entry point marker.global _startglobal _startEND 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.

PurposeGAS (GNU)NASMMASM
Define byte (8-bit).byte 0x41db 0x41DB 41h
Define word (16-bit)*.word 0x1234 / .shortdw 0x1234DW 1234h
Define double word (32-bit).long 42dd 42DD 42
Define quad word (64-bit).quad 42dq 42DQ 42
Define string.ascii "hello"db "hello"DB "hello"
Null-terminated string.asciz "hello"db "hello", 0DB "hello", 0
Define float (32-bit).float 3.14dd 3.14REAL4 3.14
Define double (64-bit).double 3.14dq 3.14REAL8 3.14
Reserve bytes (uninitialized).skip 64 / .space 64resb 64DB 64 DUP(?)
Reserve words.skip 128 (bytes)resw 64DW 64 DUP(?)
Reserve double words.skip 256 (bytes)resd 64DD 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.

PurposeGAS (GNU)NASMMASM
Align to N bytes.align 16align 16ALIGN 16
Align with fill byte.align 16, 0x90align 16, nopALIGN 16
Pad with bytes.fill 8, 1, 0x90times 8 nopDB 8 DUP(90h)
Repeat instruction.rept 4 / .endrtimes 4 nopREPT 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.

PurposeGAS (GNU)NASMMASM
Define macro.macro name arg1%macro name 1name MACRO arg1
End macro.endm%endmacroENDM
Macro parameter referencearg1%1arg1
Conditional (if defined).ifdef SYMBOL%ifdef SYMBOLIFDEF SYMBOL
Conditional (if equal).if expr == 1%if expr == 1IF expr EQ 1
Else.else%elseELSE
End conditional.endif%endifENDIF
Include file.include "file.inc"%include "file.inc"INCLUDE file.inc
Define constant.equ NAME, 42NAME equ 42NAME 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.

FeatureGAS (AT&T)NASM (Intel)MASM (Intel)
Operand orderSource, DestinationDestination, SourceDestination, Source
Register prefix%raxraxrax
Immediate prefix$424242
Memory reference(%rbp) or -8(%rbp)[rbp] or [rbp-8][rbp] or [rbp-8]
Size suffixmovq, movl, movbmov qword, mov dwordmov QWORD PTR
Comment# comment; comment; comment
Hex format0x12340x1234 or 1234h1234h

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

Scroll to Top