Linux command
nasm 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Assemble to object file
nasm -f [elf64] [source.asm] -o [output.o]
Assemble for Linux 32-bit
nasm -f elf32 [source.asm]
Assemble for Windows 64-bit
nasm -f win64 [source.asm]
Generate listing file
nasm -f [elf64] -l [listing.lst] [source.asm]
Define preprocessor macro
nasm -D [MACRO_NAME]=[value] [source.asm]
Include search path
nasm -I [/path/to/includes/] [source.asm]
Preprocess only
nasm -E [source.asm]
Show available output formats
nasm -hf
说明
NASM (Netwide Assembler) is a portable x86 and x86-64 assembler using Intel syntax. It produces object files for various operating systems and formats, making it suitable for cross-platform assembly development. The Intel syntax NASM uses is generally considered more readable than AT&T syntax: destination comes first (mov eax, 1), memory references use brackets (var), and size specifiers are explicit (dword, qword). Output formats cover major platforms: ELF for Linux/Unix, PE/COFF for Windows, Mach-O for macOS, and flat binary for bootloaders and embedded systems. The -f option selects the target format. NASM includes a powerful macro preprocessor supporting multi-line macros, conditional assembly, string manipulation, and file inclusion. Context-local labels enable reusable code structures. For debugging, NASM generates debugging information in formats like DWARF and CodeView, compatible with GDB, LLDB, and Visual Studio debuggers.
参数
- -f _format_
- Output format (elf64, elf32, win64, win32, macho64, bin, etc.).
- -o _file_
- Output file name.
- -l _file_
- Generate listing file.
- -M
- Generate Makefile dependencies.
- -E
- Preprocess only, output to stdout.
- -a
- Preprocess only, no output.
- -D _macro_=_value_
- Define preprocessor macro.
- -U _macro_
- Undefine preprocessor macro.
- -I _path_
- Add include file search directory.
- -P _file_
- Pre-include file before source.
- -w+|-_warning_
- Enable/disable warning type.
- -g
- Generate debug information.
- -F _format_
- Debug information format.
- -O _level_
- Optimization level (0, 1, x for multi-pass).
- -@ _file_
- Read additional command-line options from file.
- -Z _file_
- Redirect error messages to file.
- -s
- Output errors to stdout.
- -v
- Display version.
- -y
- List available debug info formats for a given output format.
- -h
- Display help.
- -hf
- List available output formats.
FAQ
What is the nasm command used for?
NASM (Netwide Assembler) is a portable x86 and x86-64 assembler using Intel syntax. It produces object files for various operating systems and formats, making it suitable for cross-platform assembly development. The Intel syntax NASM uses is generally considered more readable than AT&T syntax: destination comes first (mov eax, 1), memory references use brackets (var), and size specifiers are explicit (dword, qword). Output formats cover major platforms: ELF for Linux/Unix, PE/COFF for Windows, Mach-O for macOS, and flat binary for bootloaders and embedded systems. The -f option selects the target format. NASM includes a powerful macro preprocessor supporting multi-line macros, conditional assembly, string manipulation, and file inclusion. Context-local labels enable reusable code structures. For debugging, NASM generates debugging information in formats like DWARF and CodeView, compatible with GDB, LLDB, and Visual Studio debuggers.
How do I run a basic nasm example?
Run `nasm -f [elf64] [source.asm] -o [output.o]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -f _format_ do in nasm?
Output format (elf64, elf32, win64, win32, macho64, bin, etc.).