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
Option: 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: Floating-Point 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:
,
,
,
and
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: Enhancing
:
Section 4.1.3: Concatenating Single Line Macro Tokens:
Section 4.1.4: The Macro Name Itself:
and
Section 4.1.5: Undefining Macros:
Section 4.1.6: Preprocessor Variables:
Section 4.1.7: Defining Strings:
Section 4.2: String Handling in Macros:
and
Section 4.2.1: String Length:
Section 4.2.2: Sub-strings:
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: Default Macro Parameters
Section 4.3.5:
: Macro Parameter Counter
Section 4.3.6:
: Rotating Macro Parameters
Section 4.3.7: Concatenating Macro Parameters
Section 4.3.8: Condition Codes as Macro Parameters
Section 4.3.9: Disabling Listing Expansion
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:
: Reporting User-Defined Errors
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.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:
: Renaming a Context
Section 4.7.5: Example Use of the Context Stack: Block IFs
Section 4.8: Standard Macros
Section 4.8.1:
,
,
and
: NASM Version
Section 4.8.2:
: NASM Version ID
Section 4.8.3:
: NASM Version string
Section 4.8.4:
and
: File Name and Line Number
Section 4.8.5:
: Current BITS Mode
Section 4.8.6:
: Current Output Format
Section 4.8.7: Assembly Date and Time Macros
Section 4.8.8:
and
: Declaring Structure Data Types
Section 4.8.9:
,
and
: Declaring Instances of Structures
Section 4.8.10:
and
: Data Alignment
Section 4.9: Stack Relative Preprocessor Directives
Section 4.9.1:
Directive
Section 4.9.2:
Directive
Section 4.9.3:
Directive
Section 4.10: Other Preprocessor Directives
Section 4.10.1:
Directive
Section 4.10.2:
: Read an environment variable.
Chapter 5: Assembler Directives
Section 5.1:
: Specifying Target Processor Mode
Section 5.1.1:
&
: Aliases for BITS
Section 5.2:
: Change the assembler defaults
Section 5.3:
or
: Changing and Defining Sections
Section 5.3.1: The
Macro
Section 5.4:
: Defining Absolute Labels
Section 5.5:
: Importing Symbols from Other Modules
Section 5.6:
: Exporting Symbols to Other Modules
Section 5.7:
: Defining Common Data Areas
Section 5.8:
: Defining CPU Dependencies
Section 5.9:
: Handling of floating-point constants
Chapter 6: Output Formats
Section 6.1:
: Flat-Form Binary Output
Section 6.1.1:
: Binary File Program Origin
Section 6.1.2:
Extensions to the
Directive
Section 6.1.3:
support for the BIN format.
Section 6.1.4: Map files
Section 6.2:
: Microsoft OMF Object Files
Section 6.2.1:
Extensions to the
Directive
Section 6.2.2:
: Defining Groups of Segments
Section 6.2.3:
: Disabling Case Sensitivity in Output
Section 6.2.4:
: Importing DLL Symbols
Section 6.2.5:
: Exporting DLL Symbols
Section 6.2.6:
: Defining the Program Entry Point
Section 6.2.7:
Extensions to the
Directive
Section 6.2.8:
Extensions to the
Directive
Section 6.3:
: Microsoft Win32 Object Files
Section 6.3.1:
Extensions to the
Directive
Section 6.3.2:
: safe structured exception handling
Section 6.4:
: Microsoft Win64 Object Files
Section 6.4.1:
: writing position-independent code
Section 6.4.2:
: structured exception handling
Section 6.5:
: Common Object File Format
Section 6.6:
: Mach Object File Format
Section 6.7:
: Executable and Linkable Format Object Files
Section 6.7.1: ELF specific directive
Section 6.7.2:
Extensions to the
Directive
Section 6.7.3: Position-Independent Code:
Special Symbols and
Section 6.7.4:
Extensions to the
Directive
Section 6.7.5:
Extensions to the
Directive
Section 6.7.6: 16-bit code and ELF
Section 6.7.7: Debug formats and ELF
Section 6.8:
: Linux
Object Files
Section 6.9:
: NetBSD/FreeBSD/OpenBSD
Object Files
Section 6.10:
: Minix/Linux
Object Files
Section 6.11:
: Relocatable Dynamic Object File Format
Section 6.11.1: Requiring a Library: The
Directive
Section 6.11.2: Specifying a Module Name: The
Directive
Section 6.11.3:
Extensions to the
directive
Section 6.11.4:
Extensions to the
directive
Section 6.12:
: Debugging Format
Chapter 7: Writing 16-bit Code (DOS, Windows 3/3.1)
Section 7.1: Producing
Files
Section 7.1.1: Using the
Format To Generate
Files
Section 7.1.2: Using the
Format To Generate
Files
Section 7.2: Producing
Files
Section 7.2.1: Using the
Format To Generate
Files
Section 7.2.2: Using the
Format To Generate
Files
Section 7.3: Producing
Files
Section 7.4: Interfacing to 16-bit C Programs
Section 7.4.1: External Symbol Names
Section 7.4.2: Memory Models
Section 7.4.3: Function Definitions and Function Calls
Section 7.4.4: Accessing Data Items
Section 7.4.5:
: Helper Macros for the 16-bit C Interface
Section 7.5: Interfacing to Borland Pascal Programs
Section 7.5.1: The Pascal Calling Convention
Section 7.5.2: Borland Pascal Segment Name Restrictions
Section 7.5.3: Using
With Pascal Programs
Chapter 8: Writing 32-bit Code (Unix, Win32, DJGPP)
Section 8.1: Interfacing to 32-bit C Programs
Section 8.1.1: External Symbol Names
Section 8.1.2: Function Definitions and Function Calls
Section 8.1.3: Accessing Data Items
Section 8.1.4:
: Helper Macros for the 32-bit C Interface
Section 8.2: Writing NetBSD/FreeBSD/OpenBSD and Linux/ELF Shared Libraries
Section 8.2.1: Obtaining the Address of the GOT
Section 8.2.2: Finding Your Local Data Items
Section 8.2.3: Finding External and Common Data Items
Section 8.2.4: Exporting Symbols to the Library User
Section 8.2.5: Calling Procedures Outside the Library
Section 8.2.6: Generating the Library File
Chapter 9: Mixing 16 and 32 Bit Code
Section 9.1: Mixed-Size Jumps
Section 9.2: Addressing Between Different-Size Segments
Section 9.3: Other Mixed-Size Instructions
Chapter 10: Writing 64-bit Code (Unix, Win64)
Section 10.1: Register names in 64-bit mode
Section 10.2: Immediates and displacements in 64-bit mode
Section 10.3: Interfacing to 64-bit C Programs (Unix)
Section 10.4: Interfacing to 64-bit C Programs (Win64)
Chapter 11: Troubleshooting
Section 11.1: Common Problems
Section 11.1.1: NASM Generates Inefficient Code
Section 11.1.2: My Jumps are Out of Range
Section 11.1.3:
Doesn't Work
Section 11.1.4:
Doesn't Work
Section 11.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 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: AMD SSE5 instructions
Section B.1.21: Intel SMX
Section B.1.22: Geode (Cyrix) 3DNow! additions
Section B.1.23: Intel new instructions in ???
Section B.1.24: Intel AES instructions
Section B.1.25: Intel AVX instructions
Section B.1.26: Intel Carry-Less Multiplication instructions (CLMUL)
Section B.1.27: Intel Fused Multiply-Add instructions (FMA)
Section B.1.28: VIA (Centaur) security instructions
Section B.1.29: Systematic names for the hinting nop instructions