yasm

Modular x86 and AMD64 assembler

TLDR

Assemble to ELF64 object file
$ yasm -f elf64 -o [output.o] [input.asm]
Assemble for Windows 64-bit
$ yasm -f win64 -o [output.obj] [input.asm]
Assemble 32-bit ELF
$ yasm -f elf32 -o [output.o] [input.asm]
Use GAS syntax
$ yasm -p gas -f elf64 -o [output.o] [input.s]
Generate debug info in DWARF format
$ yasm -g dwarf2 -f elf64 -o [output.o] [input.asm]
Preprocess only
$ yasm -e [input.asm]
Define macro
$ yasm -D [DEBUG=1] -f elf64 -o [output.o] [input.asm]

SYNOPSIS

yasm [options] infile

DESCRIPTION

yasm is a modular assembler supporting x86 and AMD64 instruction sets. It is a complete rewrite of NASM under the BSD license, offering multiple input syntaxes and output formats.Supported syntaxes include NASM (default) and GAS (GNU Assembler). Output formats cover ELF, Win32/Win64 PE, Mach-O, COFF, and raw binary (bin, the default). Debug information can be generated in DWARF 2, STABS, or CodeView 8 formats. Use `yasm -f help` to list all available object formats.The assembler is used for low-level system programming, operating system development, and performance-critical code. It integrates with C/C++ toolchains through standard object file formats.

PARAMETERS

-f format, --oformat=format

Output format (default: bin): bin, elf32, elf64, win32, win64, macho32, macho64, coff.
-o outfile, --objfile=outfile
Output file name.
-a arch, --arch=arch
Target architecture (default: x86).
-m machine, --machine=machine
Machine subtype: x86, amd64.
-p parser, --parser=parser
Syntax parser: nasm (default), gas.
-r preproc, --preproc=preproc
Preprocessor: nasm (default), raw, cpp, gas.
-g debug, --dformat=debug
Debug format: dwarf2, stabs, cv8, null.
-L list, --lformat=list
List file format (default: nasm).
-l file, --list=file
Output list file name.
-D macro[=value]
Define preprocessor macro.
-U macro
Undefine macro.
-I path
Add include search directory.
-P file
Pre-include file before input.
-e, --preproc-only
Preprocess only (no assembly), output to stdout.
-w
Suppress all warning messages.
-Werror
Treat warnings as errors.
-Worphan-labels
Warn on labels lacking trailing colons (NASM mode).
-X style
Error/warning reporting style: gnu or vc.
--force-strict
Treat all sized operands as strict.
--version
Display version.
-h, --help
Display help.

INSTALL

sudo apt install yasm
sudo dnf install yasm
sudo pacman -S yasm
sudo apk add yasm
sudo zypper install yasm
brew install yasm
nix profile install nixpkgs#yasm

CAVEATS

Some NASM syntax extensions may not be fully compatible. GAS syntax support is not complete. AMD64 mode requires explicit selection via -m amd64 or 64-bit object format.

HISTORY

yasm was created by Peter Johnson and Michael Urman as a rewrite of NASM with a modular architecture. It aimed to support multiple architectures and syntaxes while maintaining NASM compatibility. Development began in 2001 with the project remaining actively used in various build systems.

SEE ALSO

nasm(1), as(1), ld(1), objdump(1)