This manual documents NASM, the Netwide Assembler: an assembler targetting the Intel x86 series of processors, with portable source.
Chapter 1: Introduction
Section 1.1: What Is NASM?
Section 1.1.1: Why Yet Another Assembler?
Section 1.1.2: License Conditions
Section 1.2: Contact Information
Section 1.3: Installation
Section 1.3.1: Installing NASM under MS-DOS or Windows
Section 1.3.2: Installing NASM under Unix
Chapter 2: Running NASM
Section 2.1: NASM Command-Line Syntax
Section 2.1.1: The
Option: Specifying the Output File Name
Section 2.1.2: The
Option: Specifying the Output File Format
Section 2.1.3: The
Option: Generating a Listing File
Section 2.1.4: The
Option: Generate Makefile Dependencies
Section 2.1.5: The
Option: Generate Makefile Dependencies
Section 2.1.6: The
Option: Set Makefile Dependency File
Section 2.1.7: The
Option: Assemble and Generate Dependencies
Section 2.1.8: The
Option: Dependency Target Name
Section 2.1.9: The
Option: Dependency Target Name (Quoted)
Section 2.1.10: The
Option: Emit phony targets
Section 2.1.11: The
Option: Selecting a Debug Information Format
Section 2.1.12: The
Option: Enabling Debug Information.
Section 2.1.13: The
Option: Selecting an Error Reporting Format
Section 2.1.14: The
Option: Send Errors to a File
Section 2.1.15: The
Option: Send Errors to
Section 2.1.16: The
Option: Include File Search Directories
Section 2.1.17: The
Option: Pre-Include a File
Section 2.1.18: The
Option: Pre-Define a Macro
Section 2.1.19: The
Option: Undefine a Macro
Section 2.1.20: The
Option: Preprocess Only
Section 2.1.21: The
Option: Don't Preprocess At All
Section 2.1.22: The
Option: Specifying Multipass Optimization
Section 2.1.23: The
Option: Enable TASM Compatibility Mode
Section 2.1.24: The
and
Options: Enable or Disable Assembly Warnings
Section 2.1.25: The
Option: Display Version Info
Section 2.1.26: The
Option: Display Available Debug Info Formats
Section 2.1.27: The
and
Options.
Section 2.1.28: The
Environment Variable
Section 2.2: Quick Start for MASM Users
Section 2.2.1: NASM Is Case-Sensitive
Section 2.2.2: NASM Requires Square Brackets For Memory References
Section 2.2.3: NASM Doesn't Store Variable Types
Section 2.2.4: NASM Doesn't
Section 2.2.5: NASM Doesn't Support Memory Models
Section 2.2.6: Floating-Point Differences
Section 2.2.7: Other Differences
Chapter 3: The NASM Language
Section 3.1: Layout of a NASM Source Line
Section 3.2: Pseudo-Instructions
Section 3.2.1:
and Friends: Declaring Initialized Data
Section 3.2.2:
and Friends: Declaring Uninitialized Data
Section 3.2.3:
: Including External Binary Files
Section 3.2.4:
: Defining Constants
Section 3.2.5:
: Repeating Instructions or Data
Section 3.3: Effective Addresses
Section 3.4: Constants
Section 3.4.1: Numeric Constants
Section 3.4.2: Character Strings
Section 3.4.3: Character Constants
Section 3.4.4: String Constants
Section 3.4.5: Unicode Strings
Section 3.4.6: Floating-Point Constants
Section 3.4.7: Packed BCD Constants
Section 3.5: Expressions
Section 3.5.1:
: Bitwise OR Operator
Section 3.5.2:
: Bitwise XOR Operator
Section 3.5.3:
: Bitwise AND Operator
Section 3.5.4:
and
: Bit Shift Operators
Section 3.5.5:
and
: Addition and Subtraction Operators
Section 3.5.6:
,
,
,
and
: Multiplication and Division
Section 3.5.7: Unary Operators
Section 3.6:
and
Section 3.7:
: Inhibiting Optimization
Section 3.8: Critical Expressions
Section 3.9: Local Labels
Chapter 4: The NASM Preprocessor
Section 4.1: Single-Line Macros
Section 4.1.1: The Normal Way:
Section 4.1.2: Resolving
:
Section 4.1.3: Macro Indirection:
Section 4.1.4: Concatenating Single Line Macro Tokens:
Section 4.1.5: The Macro Name Itself:
and
Section 4.1.6: Undefining Single-Line Macros:
Section 4.1.7: Preprocessor Variables:
Section 4.1.8: Defining Strings:
Section 4.1.9: Defining Tokens:
Section 4.2: String Manipulation in Macros
Section 4.2.1: Concatenating Strings:
Section 4.2.2: String Length:
Section 4.2.3: Extracting Substrings:
Section 4.3: Multi-Line Macros:
Section 4.3.1: Overloading Multi-Line Macros
Section 4.3.2: Macro-Local Labels
Section 4.3.3: Greedy Macro Parameters
Section 4.3.4: Macro Parameters Range
Section 4.3.5: Default Macro Parameters
Section 4.3.6:
: Macro Parameter Counter
Section 4.3.7:
: Label Preceeding Macro
Section 4.3.8:
: Rotating Macro Parameters
Section 4.3.9: Concatenating Macro Parameters
Section 4.3.10: Condition Codes as Macro Parameters
Section 4.3.11: Disabling Listing Expansion
Section 4.3.12: Undefining Multi-Line Macros:
Section 4.4: Conditional Assembly
Section 4.4.1:
: Testing Single-Line Macro Existence
Section 4.4.2:
: Testing Multi-Line Macro Existence
Section 4.4.3:
: Testing the Context Stack
Section 4.4.4:
: Testing Arbitrary Numeric Expressions
Section 4.4.5:
and
: Testing Exact Text Identity
Section 4.4.6:
,
,
: Testing Token Types
Section 4.4.7:
: Test for a Single Token
Section 4.4.8:
: Test for Empty Expansion
Section 4.4.9:
: Test If Environment Variable Exists
Section 4.5: Preprocessor Loops:
Section 4.6: Source Files and Dependencies
Section 4.6.1:
: Including Other Files
Section 4.6.2:
: Search the Include Path
Section 4.6.3:
: Add Dependent Files
Section 4.6.4:
: Include Standard Macro Package
Section 4.7: The Context Stack
Section 4.7.1:
and
: Creating and Removing Contexts
Section 4.7.2: Context-Local Labels
Section 4.7.3: Context-Local Single-Line Macros
Section 4.7.4: Context Fall-Through Lookup
Section 4.7.5:
: Renaming a Context
Section 4.7.6: Example Use of the Context Stack: Block IFs
Section 4.8: Stack Relative Preprocessor Directives
Section 4.8.1:
Directive
Section 4.8.2:
Directive
Section 4.8.3:
Directive
Section 4.9: Reporting User-Defined Errors:
,
,
Section 4.10: Other Preprocessor Directives
Section 4.10.1:
Directive
Section 4.10.2:
: Read an environment variable.
Section 4.11: Comment Blocks:
Section 4.12: Standard Macros
Section 4.12.1: NASM Version Macros
Section 4.12.2:
: NASM Version ID
Section 4.12.3:
: NASM Version string
Section 4.12.4:
and
: File Name and Line Number
Section 4.12.5:
: Current BITS Mode
Section 4.12.6:
: Current Output Format
Section 4.12.7: Assembly Date and Time Macros
Section 4.12.8:
package
: Package Include Test
Section 4.12.9:
: Assembly Pass
Section 4.12.10:
and
: Declaring Structure Data Types
Section 4.12.11:
,
and
: Declaring Instances of Structures
Section 4.12.12:
and
: Data Alignment
Section 4.12.13:
: Section Alignment
Chapter 5: Standard Macro Packages
Section 5.1:
: Alternate Register Names
Section 5.2:
: Smart
Macro
Section 5.3:
: Floating-point macros
Section 5.4:
: Integer functions
Section 5.4.1: Integer logarithms
Chapter 6: Assembler Directives
Section 6.1:
: Specifying Target Processor Mode
Section 6.1.1:
&
: Aliases for BITS
Section 6.2:
: Change the assembler defaults
Section 6.2.1:
&
: RIP-relative addressing
Section 6.2.2:
&
:
prefix
Section 6.3:
or
: Changing and Defining Sections
Section 6.3.1: The
Macro
Section 6.4:
: Defining Absolute Labels
Section 6.5:
: Importing Symbols from Other Modules
Section 6.6:
: Exporting Symbols to Other Modules
Section 6.7:
: Defining Common Data Areas
Section 6.8:
: Defining CPU Dependencies
Section 6.9:
: Handling of floating-point constants
Chapter 7: Output Formats
Section 7.1:
: Flat-Form Binary Output
Section 7.1.1:
: Binary File Program Origin
Section 7.1.2:
Extensions to the
Directive
Section 7.1.3: Multisection Support for the
Format
Section 7.1.4: Map Files
Section 7.2:
: Intel Hex Output
Section 7.3:
: Motorola S-Records Output
Section 7.4:
: Microsoft OMF Object Files
Section 7.4.1:
Extensions to the
Directive
Section 7.4.2:
: Defining Groups of Segments
Section 7.4.3:
: Disabling Case Sensitivity in Output
Section 7.4.4:
: Importing DLL Symbols
Section 7.4.5:
: Exporting DLL Symbols
Section 7.4.6:
: Defining the Program Entry Point
Section 7.4.7:
Extensions to the
Directive
Section 7.4.8:
Extensions to the
Directive
Section 7.5:
: Microsoft Win32 Object Files
Section 7.5.1:
Extensions to the
Directive
Section 7.5.2:
: Safe Structured Exception Handling
Section 7.6:
: Microsoft Win64 Object Files
Section 7.6.1:
: Writing Position-Independent Code
Section 7.6.2:
: Structured Exception Handling
Section 7.7:
: Common Object File Format
Section 7.8:
and
: Mach Object File Format
Section 7.9:
,
,
: Executable and Linkable Format Object Files
Section 7.9.1: ELF specific directive
Section 7.9.2:
Extensions to the
Directive
Section 7.9.3: Position-Independent Code:
Special Symbols and
Section 7.9.4: Thread Local Storage:
Special Symbols and
Section 7.9.5:
Extensions to the
Directive
Section 7.9.6:
Extensions to the
Directive
Section 7.9.7: 16-bit code and ELF
Section 7.9.8: Debug formats and ELF
Section 7.10:
: Linux
Object Files
Section 7.11:
: NetBSD/FreeBSD/OpenBSD
Object Files
Section 7.12:
: Minix/Linux
Object Files
Section 7.13:
: Relocatable Dynamic Object File Format
Section 7.13.1: Requiring a Library: The
Directive
Section 7.13.2: Specifying a Module Name: The
Directive
Section 7.13.3:
Extensions to the
Directive
Section 7.13.4:
Extensions to the
Directive
Section 7.14:
: Debugging Format
Chapter 8: Writing 16-bit Code (DOS, Windows 3/3.1)
Section 8.1: Producing
Files
Section 8.1.1: Using the
Format To Generate
Files
Section 8.1.2: Using the
Format To Generate
Files
Section 8.2: Producing
Files
Section 8.2.1: Using the
Format To Generate
Files
Section 8.2.2: Using the
Format To Generate
Files
Section 8.3: Producing
Files
Section 8.4: Interfacing to 16-bit C Programs
Section 8.4.1: External Symbol Names
Section 8.4.2: Memory Models
Section 8.4.3: Function Definitions and Function Calls
Section 8.4.4: Accessing Data Items
Section 8.4.5:
: Helper Macros for the 16-bit C Interface
Section 8.5: Interfacing to Borland Pascal Programs
Section 8.5.1: The Pascal Calling Convention
Section 8.5.2: Borland Pascal Segment Name Restrictions
Section 8.5.3: Using
With Pascal Programs
Chapter 9: Writing 32-bit Code (Unix, Win32, DJGPP)
Section 9.1: Interfacing to 32-bit C Programs
Section 9.1.1: External Symbol Names
Section 9.1.2: Function Definitions and Function Calls
Section 9.1.3: Accessing Data Items
Section 9.1.4:
: Helper Macros for the 32-bit C Interface
Section 9.2: Writing NetBSD/FreeBSD/OpenBSD and Linux/ELF Shared Libraries
Section 9.2.1: Obtaining the Address of the GOT
Section 9.2.2: Finding Your Local Data Items
Section 9.2.3: Finding External and Common Data Items
Section 9.2.4: Exporting Symbols to the Library User
Section 9.2.5: Calling Procedures Outside the Library
Section 9.2.6: Generating the Library File
Chapter 10: Mixing 16 and 32 Bit Code
Section 10.1: Mixed-Size Jumps
Section 10.2: Addressing Between Different-Size Segments
Section 10.3: Other Mixed-Size Instructions
Chapter 11: Writing 64-bit Code (Unix, Win64)
Section 11.1: Register Names in 64-bit Mode
Section 11.2: Immediates and Displacements in 64-bit Mode
Section 11.3: Interfacing to 64-bit C Programs (Unix)
Section 11.4: Interfacing to 64-bit C Programs (Win64)
Chapter 12: Troubleshooting
Section 12.1: Common Problems
Section 12.1.1: NASM Generates Inefficient Code
Section 12.1.2: My Jumps are Out of Range
Section 12.1.3:
Doesn't Work
Section 12.1.4:
Doesn't Work
Section 12.2: Bugs
Appendix A: Ndisasm
Section A.1: Introduction
Section A.2: Getting Started: Installation
Section A.3: Running NDISASM
Section A.3.1: COM Files: Specifying an Origin
Section A.3.2: Code Following Data: Synchronisation
Section A.3.3: Mixed Code and Data: Automatic (Intelligent) Synchronisation
Section A.3.4: Other Options
Section A.4: Bugs and Improvements
Appendix B: Instruction List
Section B.1: Introduction
Section B.1.1: Special instructions...
Section B.1.2: Conventional instructions
Section B.1.3: Katmai Streaming SIMD instructions (SSE -- a.k.a. KNI, XMM, MMX2)
Section B.1.4: Introduced in Deschutes but necessary for SSE support
Section B.1.5: XSAVE group (AVX and extended state)
Section B.1.6: Generic memory operations
Section B.1.7: New MMX instructions introduced in Katmai
Section B.1.8: AMD Enhanced 3DNow! (Athlon) instructions
Section B.1.9: Willamette SSE2 Cacheability Instructions
Section B.1.10: Willamette MMX instructions (SSE2 SIMD Integer Instructions)
Section B.1.11: Willamette Streaming SIMD instructions (SSE2)
Section B.1.12: Prescott New Instructions (SSE3)
Section B.1.13: VMX/SVM Instructions
Section B.1.14: Extended Page Tables VMX instructions
Section B.1.15: Tejas New Instructions (SSSE3)
Section B.1.16: AMD SSE4A
Section B.1.17: New instructions in Barcelona
Section B.1.18: Penryn New Instructions (SSE4.1)
Section B.1.19: Nehalem New Instructions (SSE4.2)
Section B.1.20: Intel SMX
Section B.1.21: Geode (Cyrix) 3DNow! additions
Section B.1.22: Intel new instructions in ???
Section B.1.23: Intel AES instructions
Section B.1.24: Intel AVX AES instructions
Section B.1.25: Intel AVX instructions
Section B.1.26: Intel Carry-Less Multiplication instructions (CLMUL)
Section B.1.27: Intel AVX Carry-Less Multiplication instructions (CLMUL)
Section B.1.28: Intel Fused Multiply-Add instructions (FMA)
Section B.1.29: Intel post-32 nm processor instructions
Section B.1.30: VIA (Centaur) security instructions
Section B.1.31: AMD Lightweight Profiling (LWP) instructions
Section B.1.32: AMD XOP and FMA4 instructions (SSE5)
Section B.1.33: Intel AVX2 instructions
Section B.1.34: Transactional Synchronization Extensions (TSX)
Section B.1.35: Intel BMI1 and BMI2 instructions, AMD TBM instructions
Section B.1.36: Intel AVX-512 instructions
Section B.1.37: Systematic names for the hinting nop instructions
Appendix C: NASM Version History
Section C.1: NASM 2 Series
Section C.1.1: Version 2.11.05
Section C.1.2: Version 2.11.04
Section C.1.3: Version 2.11.03
Section C.1.4: Version 2.11.02
Section C.1.5: Version 2.11.01
Section C.1.6: Version 2.11
Section C.1.7: Version 2.10.09
Section C.1.8: Version 2.10.08
Section C.1.9: Version 2.10.07
Section C.1.10: Version 2.10.06
Section C.1.11: Version 2.10.05
Section C.1.12: Version 2.10.04
Section C.1.13: Version 2.10.03
Section C.1.14: Version 2.10.02
Section C.1.15: Version 2.10.01
Section C.1.16: Version 2.10
Section C.1.17: Version 2.09.10
Section C.1.18: Version 2.09.09
Section C.1.19: Version 2.09.08
Section C.1.20: Version 2.09.07
Section C.1.21: Version 2.09.06
Section C.1.22: Version 2.09.05
Section C.1.23: Version 2.09.04
Section C.1.24: Version 2.09.03
Section C.1.25: Version 2.09.02
Section C.1.26: Version 2.09.01
Section C.1.27: Version 2.09
Section C.1.28: Version 2.08.02
Section C.1.29: Version 2.08.01
Section C.1.30: Version 2.08
Section C.1.31: Version 2.07
Section C.1.32: Version 2.06
Section C.1.33: Version 2.05.01
Section C.1.34: Version 2.05
Section C.1.35: Version 2.04
Section C.1.36: Version 2.03.01
Section C.1.37: Version 2.03
Section C.1.38: Version 2.02
Section C.1.39: Version 2.01
Section C.1.40: Version 2.00
Section C.2: NASM 0.98 Series
Section C.2.1: Version 0.98.39
Section C.2.2: Version 0.98.38
Section C.2.3: Version 0.98.37
Section C.2.4: Version 0.98.36
Section C.2.5: Version 0.98.35
Section C.2.6: Version 0.98.34
Section C.2.7: Version 0.98.33
Section C.2.8: Version 0.98.32
Section C.2.9: Version 0.98.31
Section C.2.10: Version 0.98.30
Section C.2.11: Version 0.98.28
Section C.2.12: Version 0.98.26
Section C.2.13: Version 0.98.25alt
Section C.2.14: Version 0.98.25
Section C.2.15: Version 0.98.24p1
Section C.2.16: Version 0.98.24
Section C.2.17: Version 0.98.23
Section C.2.18: Version 0.98.22
Section C.2.19: Version 0.98.21
Section C.2.20: Version 0.98.20
Section C.2.21: Version 0.98.19
Section C.2.22: Version 0.98.18
Section C.2.23: Version 0.98.17
Section C.2.24: Version 0.98.16
Section C.2.25: Version 0.98.15
Section C.2.26: Version 0.98.14
Section C.2.27: Version 0.98.13
Section C.2.28: Version 0.98.12
Section C.2.29: Version 0.98.11
Section C.2.30: Version 0.98.10
Section C.2.31: Version 0.98.09
Section C.2.32: Version 0.98.08
Section C.2.33: Version 0.98.09b with John Coffman patches released 28-Oct-2001
Section C.2.34: Version 0.98.07 released 01/28/01
Section C.2.35: Version 0.98.06f released 01/18/01
Section C.2.36: Version 0.98.06e released 01/09/01
Section C.2.37: Version 0.98p1
Section C.2.38: Version 0.98bf (bug-fixed)
Section C.2.39: Version 0.98.03 with John Coffman's changes released 27-Jul-2000
Section C.2.40: Version 0.98.03
Section C.2.41: Version 0.98
Section C.2.42: Version 0.98p9
Section C.2.43: Version 0.98p8
Section C.2.44: Version 0.98p7
Section C.2.45: Version 0.98p6
Section C.2.46: Version 0.98p3.7
Section C.2.47: Version 0.98p3.6
Section C.2.48: Version 0.98p3.5
Section C.2.49: Version 0.98p3.4
Section C.2.50: Version 0.98p3.3
Section C.2.51: Version 0.98p3.2
Section C.2.52: Version 0.98p3-hpa
Section C.2.53: Version 0.98 pre-release 3
Section C.2.54: Version 0.98 pre-release 2
Section C.2.55: Version 0.98 pre-release 1
Section C.3: NASM 0.9 Series
Section C.3.1: Version 0.97 released December 1997
Section C.3.2: Version 0.96 released November 1997
Section C.3.3: Version 0.95 released July 1997
Section C.3.4: Version 0.94 released April 1997
Section C.3.5: Version 0.93 released January 1997
Section C.3.6: Version 0.92 released January 1997
Section C.3.7: Version 0.91 released November 1996
Section C.3.8: Version 0.90 released October 1996