NASM(1)
๐ NASM(1) โ The Netwide Assembler Project ๐
okay bestie, sit DOWN, we're learning the Netwide Assembler today and honestly? it's giving iconic. this is nasm, the portable 80x86 assembler, and this page is your group chat briefing. ๐ซถ
โจ NAME โจ
nasm โ the Netwide Assembler, a portable 80x86 assembler ๐
โจ SYNOPSIS โจ
nasm [-@ response file] [-f format] [-o outfile] [-l listfile]
[options...] filename
โจ DESCRIPTION โจ
so the nasm command takes your filename and assembles it, then yeets the output into outfile if you said so. no outfile? no problem, queen โ nasm will just make up a default output name based on your input file, usually by slapping .o or .obj on the end, or by stripping ALL the extensions if it's a raw binary file. and if even that fails? the output file is literally just nasm.out. default queen behavior. ๐
โจ OPTIONS โจ
-@ filenameโ makesnasmread options out offilename, like they were typed on the command line. cute lil shortcut, love that for us.-aโ assemble the input file without running the macro preprocessor first. raw. unfiltered. no cap.-D|-d macro[=value]โ pre-defines a single-line macro. yes, lowercase works too, they're twins. ๐ฏ-E|-eโ preprocess the input file and write the result to stdout (or wherever your output file name points), and then... not assemble anything. just vibes. it's the "look but don't touch" option.-f formatโ pick your output file format. wanna see the valid ones? hit up-hf, bestie.-F formatโ pick your debug information format. to see the valid ones, use the-yoption (like, for example,-felf -y). yes really, that's the example. ๐-gโ generate debug information.-gformatโ literally the same thing as-g -F format. two for one, slay.-hโnasmexits immediately after giving you a lil summary of its invocation options. bye girl ๐จ-hfโ same as-h, but it ALSO lists all valid output formats. the deluxe version.-I|-i directoryโ adds a directory to the search path for include files. โ ๏ธ the directory spec must include the trailing slash, because it gets directly prepended to the name of the include file. no slash, no search, no mercy.-l listfileโ sends an assembly listing to the given file. in that listing, the original source sits on the right hand side (plus the source for included files and the expansions of multi-line macros) and the generated code shows up in hex on the left. aesthetic AND informative. โจ-Mโ outputs Makefile-style dependencies to stdout; normal output gets suppressed. we're in dependency mode now.-MG fileโ same as-Mbut it assumes that missing Makefile dependencies are generated and added to the dependency list without a prefix.-MF fileโ output Makefile-style dependencies to the specified file.-MD fileโ same as combining-Mand-MF. it's the mashup.-MT fileโ override the default name of the dependency target dependency target name. (yes, the original page says "dependency target" twice, I'm not fixing it, that's how it is, we respect the text.) normally this is the same as the output filename you gave with-o.-MQ fileโ same as-MTexcept it tries to quote characters that have special meaning in Makefile syntax. ๐จ not foolproof tho โ not all characters with special meaning are quotable in Make.-MPโ emit phony target.-O numberโ optimize branch offsets. here are your levels:-O0: No optimization-O1: Minimal optimization-Ox: Multipass optimization (default)
-o outfileโ give the output file a precise name, overridingnasm's whole default-determination situation. you're in charge now.-P|-p fileโ specifies a file to be pre-included, before the main source file starts to be processed. early bird gets the include.-sโ sends error messages and/or help text to stdout instead of stderr. redirecting who? we go straight to stdout now.-tโ assemble in SciTech TASM compatible mode. nostalgia core.-U|-u macroโ undefines a single-line macro. un-define. un-slay. (jk, it's very useful.)-vโ exits immediately after displaying its version number. just a quick hello. ๐ธ-W[no-]fooโ enables or disables certain classes of warning messages, gcc-style. for example-Wlabel-orphanor-Wno-orphan-labels.-w[+-]fooโ enables or disables certain classes of warning messages too, but with the other flavor of syntax. for example-w+label-orphanor-w-macro-params.-X formatโ specifies the error reporting format (gnuorvc).-yโ lists supported debug formats. the lil menu. ๐-Z filenameโ redirects error messages tofilename. this option exists to support operating systems on which stderr is not easily redirected. it's a workaround, and we love a workaround.--prefix,--postfixโ prepend or append (respectively) the given argument to all global or extern variables. bookends for your symbols. ๐
โจ SYNTAX โจ
okay so real talk: this man page does not fully describe the syntax of nasm's assembly language. what it does do is give you a summary of the differences from other assemblers. so if you're coming from somewhere else, this is your diff. ๐
Registers have no leading % sign, unlike gas, and floating-point stack registers are referred to as st0, st1, and so on. no percent, we're not doing that here.
Floating-point instructions may use either the single-operand form or the double. A TO keyword is provided; thus, one could either write
fadd st0,st1
fadd st1,st0
or one could use the alternative single-operand forms
fadd st1
fadd to st1
Uninitialised storage is reserved using the RESB, RESW, RESD, RESQ, REST and RESO pseudo-opcodes, each taking one parameter which gives the number of bytes, words, doublewords, quadwords or ten-byte words to reserve. one parameter, that's the whole job. ๐ซถ
Repetition of data items is not done by the DUP keyword like in those DOS assemblers โ it's done with the TIMES prefix, like this:
message: times 3 db 'abc'
times 64-$+message db 0
which defines the string abcabcabc, followed by the right number of zero bytes to make the total length up to 64 bytes. math but make it assembly. ๐งฎโจ
Symbol references are always understood to be immediate (i.e. the address of the symbol), unless square brackets are used, in which case the contents of the memory location are used. so:
mov ax,wordvar
loads AX with the address of the variable wordvar, whereas
mov ax,[wordvar]
mov ax,[wordvar+1]
mov ax,[es:wordvar+bx]
all refer to the contents of memory locations. brackets = dereference, periodt. but the syntaxes
mov ax,es:wordvar[bx]
es mov ax,wordvar[1]
are not legal at all, bestie. not even a little. although the use of a segment register name as an instruction prefix is valid, and can be used with instructions such as LODSB which can't be overridden any other way. so there's your loophole, use it wisely. ๐
Constants may be expressed numerically in most formats: a trailing H, Q or B denotes hex, octal or binary respectively, and a leading 0x or $ denotes hex as well. Leading zeros are not treated specially at all. Character constants may be enclosed in single or double quotes; there is no escape character. and here's the twist โ the ordering is little-endian (reversed), so that the character constant 'abcd' denotes 0x64636261 and not 0x61626364. yes it's backwards. yes that's intentional. ๐ญ
Local labels begin with a period, and their 'locality' is granted by the assembler prepending the name of the previous non-local symbol. Thus declaring a label .loop after a label label has actually defined a symbol called label.loop. sneaky lil namespacing, iykyk. ๐ฆ
โจ DIRECTIVES โจ
SECTION name or SEGMENT name causes nasm to direct all following code to the named section. Section names vary with output file format, although most formats support the names .text, .data and .bss. (The exception is the obj format, in which all segments are user-definable.) okay so obj is the wild child, noted.
ABSOLUTE address causes nasm to position its notional assembly point at an absolute address: so no code or data may be generated, but you can use RESB, RESW and RESD to move the assembly point further on, and you can define labels. So this directive may be used to define data structures. ๐๏ธ and when you have finished doing absolute assembly, you must issue another SECTION directive to return to normal assembly. don't forget, girl, you'll be stuck in absolute-land forever.
BITS 16, BITS 32 or BITS 64 switches the default processor mode for which nasm is generating code: it is equivalent to USE16 or USE32 in DOS assemblers. glow-up mode selector. ๐
EXTERN symbol and GLOBAL symbol import and export symbol definitions, respectively, from and to other modules. โ ๏ธ Note that the GLOBAL directive must appear before the definition of the symbol it refers to. order matters, no skipping.
STRUC strucname and ENDSTRUC, when used to bracket a number of RESB, RESW or similar instructions, define a data structure. In addition to defining the offsets of the structure members, the construct also defines a symbol for the size of the structure, which is simply the structure name with size tacked on to the end. free size symbol, we love a bonus. ๐
โจ FORMAT-SPECIFIC DIRECTIVES โจ
ORG address is used by the bin flat-form binary output format, and specifies the address at which the output code will eventually be loaded.
GROUP grpname seg1 seg2... is used by the obj (Microsoft 16-bit) output format, and defines segment groups. This format also uses UPPERCASE, which directs that all segment, group and symbol names output to the object file should be in uppercase. ๐จ Note that the actual assembly is still case sensitive. so the output is shouting but the input still cares about your capital letters. tricky lil situation.
LIBRARY libname is used by the rdf output format, and causes a dependency record to be written to the output file which indicates that the program requires a certain library in order to run. ๐
part 1 done bestie, keep scrolling, there's more of this masterpiece ๐
๐ง MACRO PREPROCESSOR ๐
Okay bestie, this is the part where NASM gets actually magical. โจ
Single-line macros are defined using the %define or %idefine commands, and the vibe is very much like the C preprocessor. They can be overloaded with respect to number of parameters โ but heads up: defining a macro with no parameters blocks you from defining any macro with the same name that takes parameters, and vice versa. %define defines macros whose names match case-sensitively, whereas %idefine defines case-insensitive macros. ๐ซถ
Multi-line macros are defined using %macro and %imacro (same distinction as between %define and %idefine), and the syntax goes like this:
%macro name minprm[-maxprm][+][.nolist] [defaults]
<some lines of macro expansion text>
%endmacro
Again, these macros may be overloaded. The trailing plus sign means any parameters after the last one get subsumed โ with their separating commas โ into the last parameter. The defaults part can be used to specify defaults for unspecified macro parameters after minparam. And %endm is a totally valid synonym for %endmacro. ๐
To refer to the macro parameters inside a macro expansion, you use %1, %2, and so on. You can also enforce that a macro parameter should contain a condition code by using %+1, and you can invert the condition code using %-1. Obsessed. ๐ You can also define a label specific to a macro invocation by prefixing it with a double % sign.
Files can be included using the %include directive, which works like C. ๐ธ
The preprocessor has a โcontext stackโ, which may be used by one macro to store information that a later one will retrieve. The whole roster:
%pushโ push a context on the stack%popโ remove one%replโ change the name of the top context (without disturbing any associated definitions)
Labels and %define macros specific to the top context may be defined by prefixing their names with %$, and things specific to the next context down with %$$, and so on. ๐
Conditional assembly is done by means of %ifdef, %ifndef, %else and %endif as in C. (Except that %ifdef can accept several putative macro names, and will evaluate TRUE if any of them is defined โ little overachiever. ๐)
In addition, the directives %ifctx and %ifnctx can be used to condition on the name of the top context on the context stack. And the obvious set of โelse-ifโ directives โ %elifdef, %elifndef, %elifctx and %elifnctx โ is also supported. Periodt. ๐
๐ BUGS
Please report bugs through the bug tracker function at http://nasm.us. Not me begging you to file an issue โ okay yes, that's exactly what's happening. ๐
๐ SEE ALSO
And that's the whole page, bestie!! ๐ This was NASM(1) straight from the NASM crew, dated 06/28/2026 โ go forth and assemble something iconic. ๐โจ
๐ฆ where this page comes from
- arch rolling: nasm 3.02-1 ยท BSD-2-Clause
- fedora 44: nasm 3.02-1.fc44 ยท BSD-2-Clause
- nixos 26.05: nasm 3.02
- nixpkgs unstable: coreboot-toolchain-i386 26.09
- nixpkgs unstable: coreboot-toolchain-x64 26.09
- nixpkgs unstable: nasm 3.02
- opensuse-leap 16.0: nasm 3.02-160000.1.1 ยท BSD-2-Clause
- opensuse-leap 16.0: nasm 3.02-160000.1.1 ยท BSD-2-Clause
- opensuse-leap 16.0: nasm 3.02-160000.1.1 ยท BSD-2-Clause
- opensuse-leap 16.0: nasm 3.02-160000.1.1 ยท BSD-2-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms