NASM vs GAS vs MASM vs FASM: Which x86 Assembler to Use
Choose an x86 assembler by platform, syntax, macro power and output formats. A decision table compares NASM, GNU as, MASM and FASM, with when not to pick each.

Four assemblers account for nearly all hand-written x86 code: NASM, the GNU assembler, Microsoft's MASM and Tomasz Grysztar's FASM. They accept different syntax, target different object formats, and come with different build tools, so the right one depends on where the code will live. This post compares them on the points that decide a project, ends with a decision table, and says when not to choose each. The comparison is for x86-64, with NASM 2.16, binutils 2.42 and FASM 1.73 as reference versions. The cornerstone guide to NASM, GAS and assembler syntax covers the syntax details; this post is about the choice.
What each one is
NASM, the Netwide Assembler, is an independent x86 and x86-64 assembler with Intel syntax, a capable macro preprocessor and output formats for ELF, Mach-O, PE and COFF, flat binaries, and others. It runs on Linux, macOS and Windows, and it is the usual choice for tutorials and for code that must build the same everywhere. It supports only x86.
GAS, the GNU assembler, is as from binutils. It is the back end of GCC, so it has to accept everything GCC emits. It supports dozens of architectures with one consistent set of directives, defaults to AT&T syntax for x86 and accepts Intel syntax through .intel_syntax noprefix. It needs the C preprocessor for macros that share headers with C, and it has its own .macro facility.
MASM, the Microsoft Macro Assembler, ships with the Visual Studio build tools as ml.exe for 32-bit and ml64.exe for 64-bit. It uses an Intel-style syntax with high-level conveniences such as PROC, ENDP, .IF and typed structures. It targets Windows PE and COFF only.
FASM, the flat assembler, is a self-hosted assembler written in assembly. It has a unique syntax, a macro system that can define new instructions, and the ability to produce flat binaries, ELF, PE and others directly without a separate linker. It is a single small executable with no dependencies.
The comparison
| Point | NASM | GAS | MASM | FASM |
|---|---|---|---|---|
| Default x86 syntax | Intel | AT&T | Intel (MASM) | Intel (FASM) |
| Intel option | native | .intel_syntax noprefix | native | native |
| Platforms it runs on | Linux, macOS, Windows | Linux, macOS, Windows, BSD | Windows | Linux, Windows, DOS |
| Output | ELF, Mach-O, COFF, PE-ish, bin | ELF, Mach-O, COFF through binutils builds | COFF only | ELF, PE, COFF, bin |
| Needs a linker | yes | yes | yes | no, for executables |
| Other architectures | no | yes | no | no |
| Macro system | strong, %macro and preprocessor | .macro, plus C preprocessor with .S | strong, with high-level directives | very strong, can define instruction syntax |
| Used by GCC and Clang | no | yes | no | no |
| Standard in kernel sources | no | yes | no | no |
| Debug info | DWARF, CodeView in some formats | DWARF, CFI | CodeView | limited |
The table hides the biggest practical fact: GAS is the only one of the four that every GCC and Clang toolchain already has installed. If you have a compiler, you have as. NASM, MASM and FASM are extra tools to install.
Where each one fits
NASM: tutorials, cross-platform code, bootloaders
NASM is the default for learning on Linux because its Intel syntax matches the manuals, its error messages are clear, and its flat binary output (-f bin) is the standard way to produce boot sectors. It is also the right tool for a library of assembly routines that has to build on Linux, macOS and Windows with one source, since only the -f flag and a few section names change.
When not to use it: when the assembly has to share macros with C headers, because NASM does not read C preprocessor output as such. When the project must also target ARM or RISC-V with the same tool and directive vocabulary. When the code ends up inside the Linux kernel or a GCC-built project that already assumes GAS.
GAS: compiler output, kernel code, multi-architecture work
GAS is the right choice when the assembly sits next to C in a GNU or LLVM toolchain. It reads the same .cfi_* directives, .type and .size as compiler output, honors -g debug line tables, and works with .S files preprocessed by GCC. Because one assembler covers every architecture the GNU toolchain targets, a project with x86, ARM and RISC-V code can use a common set of directives.
When not to use it: when you only write Intel-syntax assembly and want the clearest macros. GAS in Intel mode has quirks, notably that a bare symbol means memory contents, which surprises anyone coming from NASM. And standalone builds on Windows outside MinGW or MSYS2 are inconvenient.
MASM: Windows-only work with Microsoft tools
MASM is correct when the project is built by Visual Studio or MSBuild and the assembly must follow Microsoft's x64 conventions, integrate with structured exception handling directives (.PUSHREG, .ALLOCSTACK, .ENDPROLOG) and appear in .vcxproj files. Its high-level directives save typing for large Windows drivers and legacy code.
When not to use it: for anything that must also build on Linux or macOS, since no other platform has it, and for new learners, because the high-level directives hide what the instructions are. 64-bit MASM also drops some conveniences from the 32-bit version, such as INVOKE and .MODEL, so older examples fail with unhelpful errors.
FASM: small tools, boot code and self-contained binaries
FASM is attractive when you want one tiny tool that writes a finished executable. format ELF64 executable produces a runnable program without a linker, and format binary produces a flat image. Its macro language can build entire domain-specific instruction sets, which is why OS hobbyists favor it.
When not to use it: when collaborators expect a mainstream toolchain, since FASM syntax is not shared by any other assembler and tooling support such as debugger line numbers and IDE integrations is thinner. When your build system is based on object files and a linker, because FASM's strength is bypassing them.
A single program in all four
The same program makes the differences visible. Each version exits with status 42 on Linux x86-64 or Windows as noted.
NASM, Linux, built with nasm -f elf64 exit.asm -o exit.o && ld exit.o -o exit:
global _start
section .text
_start:
mov eax, 60
mov edi, 42
syscallGAS, Linux, built with as exit.s -o exit.o && ld exit.o -o exit:
.globl _start
.text
_start:
movl $60, %eax
movl $42, %edi
syscallFASM, Linux, built with fasm exit.fasm exit, with no linker involved:
format ELF64 executable 3
entry start
segment readable executable
start:
mov eax, 60
mov edi, 42
syscallMASM on Windows exits through the C runtime or the kernel API rather than a system call, because the Windows system call numbers change between releases and are not a stable interface. The standard route calls ExitProcess:
extrn ExitProcess : proc
.code
main PROC
sub rsp, 40 ; shadow space plus alignment
mov ecx, 42
call ExitProcess
main ENDP
ENDml64 exit.asm /link /subsystem:console /entry:main kernel32.libAfter running each, echo $? on Linux or echo %ERRORLEVEL% on Windows prints:
42Only the Windows version needs the shadow space reservation. Only the FASM version needed no linker and no section directives. The GAS and NASM versions are identical in structure and differ in spelling, which is why moving between them is easy.
Decision table
| If your project... | Use | Reason |
|---|---|---|
| is a Linux tutorial or learning exercise | NASM | Intel syntax matches the manuals, clear errors |
| lives in a GCC, LLVM or Linux kernel tree | GAS | Already installed, shares CFI and preprocessor with compiler output |
| must support x86 and ARM or RISC-V with one tool | GAS | One directive set across architectures |
| builds only on Windows with Visual Studio | MASM | Native to the toolchain and exception directives |
| must build on Windows, Linux and macOS with one source | NASM | One syntax and format flags for each platform |
| produces boot sectors or flat firmware blobs | NASM or FASM | Both write raw binaries directly |
| needs a tiny self-contained assembler with no linker | FASM | Emits executables on its own |
| needs heavy macro metaprogramming | FASM or NASM | Both have strong preprocessors |
| includes C headers in the assembly | GAS with .S | The C preprocessor handles the headers |
What about YASM and LLVM
Two other tools come up. YASM is a rewrite of NASM that accepted both NASM and GAS syntax. Its last release was 1.3.0 in 2014, so it is a legacy choice, though some old build systems still call it. And LLVM's integrated assembler, used by Clang, reads GAS-compatible syntax, so a GAS-syntax file builds with Clang without binutils installed. That makes GAS syntax the most widely accepted dialect, even when the tool is not GAS.
A reasonable default
If you have no constraints, learn NASM on Linux for Intel syntax and its tooling, and learn to read GAS output because every compiler listing uses it. If you are joining an existing project, use the assembler it already uses, and avoid converting for taste. The cost of translating a code base between dialects is far higher than the benefit of a preferred notation.


