← 返回命令列表

Linux command

yasm 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

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

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]

说明

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.

参数

-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.

FAQ

What is the yasm command used for?

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.

How do I run a basic yasm example?

Run `yasm -f elf64 -o [output.o] [input.asm]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -f _format_, --oformat=_format_ do in yasm?

Output format (default: bin): bin, elf32, elf64, win32, win64, macho32, macho64, coff.