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: Licence 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: Send Errors to a File
Section 2.1.5: The Option: Send Errors to
Section 2.1.6: The Option: Include File Search Directories
Section 2.1.7: The Option: Pre-Include a File
Section 2.1.8: The Option: Pre-Define a Macro
Section 2.1.9: The Option: Undefine a Macro
Section 2.1.10: The Option: Preprocess Only
Section 2.1.11: The Option: Don't Preprocess At All
Section 2.1.12: The option: Enable TASM Compatibility Mode
Section 2.1.13: The Option: Enable or Disable Assembly Warnings
Section 2.1.14: 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 Initialised Data
Section 3.2.2: and friends: Declaring Uninitialised 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 Constants
Section 3.4.3: String Constants
Section 3.4.4: 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: Critical Expressions
Section 3.8: Local Labels
Chapter 4: The NASM Preprocessor
Section 4.1: Single-Line Macros
Section 4.1.1: The Normal Way:
Section 4.1.2: Undefining macros:
Section 4.1.3: Preprocessor Variables:
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 the Context Stack
Section 4.4.3: : Testing Arbitrary Numeric Expressions
Section 4.4.4: and : Testing Exact Text Identity
Section 4.4.5: , , : Testing Token Types
Section 4.4.6: : Reporting User-Defined Errors
Section 4.5: Preprocessor Loops:
Section 4.6: Including Other 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: and : File Name and Line Number
Section 4.8.3: and : Declaring Structure Data Types
Section 4.8.4: , and : Declaring Instances of Structures
Section 4.8.5: and : Data Alignment
Section 4.9: TASM Compatible Preprocessor Directives
Section 4.9.1: Directive
Section 4.9.2: Directive
Section 4.9.3: Directive
Chapter 5: Assembler Directives
Section 5.1: : Specifying Target Processor Mode
Section 5.2: or : Changing and Defining Sections
Section 5.2.1: The Macro
Section 5.3: : Defining Absolute Labels
Section 5.4: : Importing Symbols from Other Modules
Section 5.5: : Exporting Symbols to Other Modules
Section 5.6: : Defining Common Data Areas
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.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.4: : Common Object File Format
Section 6.5: : Linux ELFObject Files
Section 6.5.1: Extensions to the Directive
Section 6.5.2: Position-Independent Code: Special Symbols and
Section 6.5.3: Extensions to the Directive
Section 6.5.4: Extensions to the Directive
Section 6.6: : Linux Object Files
Section 6.7: : NetBSD/FreeBSD/OpenBSD Object Files
Section 6.8: : Linux Object Files
Section 6.9: : Relocatable Dynamic Object File Format
Section 6.9.1: Requiring a Library: The Directive
Section 6.9.2: Specifying a Module Name: The Directive
Section 6.9.3: Extensions to the directive
Section 6.10: : 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: Troubleshooting
Section 10.1: Common Problems
Section 10.1.1: NASM Generates Inefficient Code
Section 10.1.2: My Jumps are Out of Range
Section 10.1.3: Doesn't Work
Section 10.1.4: Doesn't Work
Section 10.2: Bugs
Appendix A: Intel x86 Instruction Reference
Section A.1: Key to Operand Specifications
Section A.2: Key to Opcode Descriptions
Section A.2.1: Register Values
Section A.2.2: Condition Codes
Section A.2.3: Effective Address Encoding: ModR/M and SIB
Section A.3: Key to Instruction Flags
Section A.4: , , , : ASCII Adjustments
Section A.5: : Add with Carry
Section A.6: : Add Integers
Section A.7: : Packed Single FP ADD
Section A.8: : Scalar Single FP ADD
Section A.9: : Bitwise AND
Section A.10: : Bitwise Logical AND NOT For Single FP
Section A.11: : Bitwise Logical AND For Single FP
Section A.12: : Adjust RPL Field of Selector
Section A.13: : Check Array Index against Bounds
Section A.14: , : Bit Scan
Section A.15: : Byte Swap
Section A.16: , , , : Bit Test
Section A.17: : Call Subroutine
Section A.18: , , , : Sign Extensions
Section A.19: , , , : Clear Flags
Section A.20: : Complement Carry Flag
Section A.21: : Conditional Move
Section A.22: : Compare Integers
Section A.23: : Packed Single FP Compare (CMPPS)
Section A.24: : Scalar Single FP Compare (CMPSS)
Section A.25: : Packed Single FP Compare (CMPPS)
Section A.26: : Scalar Single FP Compare (CMPSS)
Section A.27: : Packed Single FP Compare (CMPPS)
Section A.28: : Scalar Single FP Compare (CMPSS)
Section A.29: : Packed Single FP Compare (CMPPS)
Section A.30: : Scalar Single FP Compare (CMPSS)
Section A.31: : Packed Single FP Compare (CMPPS)
Section A.32: : Scalar Single FP Compare (CMPSS)
Section A.33: : Packed Single FP Compare (CMPPS)
Section A.34: : Scalar Single FP Compare (CMPSS)
Section A.35: : Packed Single FP Compare (CMPPS)
Section A.36: : Scalar Single FP Compare (CMPSS)
Section A.37: : Packed Single FP Compare
Section A.38: , , : Compare Strings
Section A.39: : Scalar Single FP Compare
Section A.40: : Packed Single FP Compare
Section A.41: : Scalar Single FP Compare
Section A.42: , : Compare and Exchange
Section A.43: : Compare and Exchange Eight Bytes
Section A.44: : Scalar Ordered Single-FP Compare and Set EFLAGS
Section A.45: : Get CPU Identification Code
Section A.46: : Packed Signed INT32 to Packed Single-FP Conversion
Section A.47: : Packed Single-FP to Packed INT32 Conversion
Section A.48: : Scalar Signed INT32 to Single-FP Conversion
Section A.49: : Scalar Single-FP to Signed INT32 Conversion
Section A.50: : Packed Single-FP to Packed INT32 Conversion
Section A.51: : Scalr Single-FP to Signed INT32 Conversion
Section A.52: , : Decimal Adjustments
Section A.53: : Decrement Integer
Section A.54: : Unsigned Integer Divide
Section A.55: : Packed Single-FP Divide
Section A.56: : Scalar Single-FP Divide
Section A.57: : Empty MMX State
Section A.58: : Create Stack Frame
Section A.59: : Calculate 2**X-1
Section A.60: : Floating-Point Absolute Value
Section A.61: , : Floating-Point Addition
Section A.62: , : BCD Floating-Point Load and Store
Section A.63: : Floating-Point Change Sign
Section A.64: , : Clear Floating-Point Exceptions
Section A.65: : Floating-Point Conditional Move
Section A.66: , , , , : Floating-Point Compare
Section A.67: : Cosine
Section A.68: : Decrement Floating-Point Stack Pointer
Section A.69: , : Disable and Enable Floating-Point Interrupts
Section A.70: , , , : Floating-Point Division
Section A.71: : 3dnow instruction (duh!)
Section A.72: : Flag Floating-Point Register as Unused
Section A.73: : Floating-Point/Integer Addition
Section A.74: , : Floating-Point/Integer Compare
Section A.75: , : Floating-Point/Integer Division
Section A.76: , , : Floating-Point/Integer Conversion
Section A.77: : Floating-Point/Integer Multiplication
Section A.78: : Increment Floating-Point Stack Pointer
Section A.79: , : Initialise Floating-Point Unit
Section A.80: : Floating-Point/Integer Subtraction
Section A.81: : Floating-Point Load
Section A.82: : Floating-Point Load Constants
Section A.83: : Load Floating-Point Control Word
Section A.84: : Load Floating-Point Environment
Section A.85: , : Floating-Point Multiply
Section A.86: : Floating-Point No Operation
Section A.87: , : Arctangent and Tangent
Section A.88: , : Floating-Point Partial Remainder
Section A.89: : Floating-Point Round to Integer
Section A.90: , : Save/Restore Floating-Point State
Section A.91: : Scale Floating-Point Value by Power of Two
Section A.92: : Set Protected Mode
Section A.93: , : Sine and Cosine
Section A.94: : Floating-Point Square Root
Section A.95: , : Floating-Point Store
Section A.96: : Store Floating-Point Control Word
Section A.97: : Store Floating-Point Environment
Section A.98: : Store Floating-Point Status Word
Section A.99: , , , : Floating-Point Subtract
Section A.100: : Test Against Zero
Section A.101: : Floating-Point Unordered Compare
Section A.102: : Examine Class of Value in
Section A.103: : Floating-Point Exchange
Section A.104: : Restore FP and MMXTM State and Streaming SIMD Extension State
Section A.105: : Store FP and MMXTM State and Streaming SIMD
Section A.106: : Extract Exponent and Significand
Section A.107: , : Compute Y times Log2(X) or Log2(X+1)
Section A.108: : Halt Processor
Section A.109: : Insert Bit String
Section A.110: : Signed Integer Divide
Section A.111: : Signed Integer Multiply
Section A.112: : Input from I/O Port
Section A.113: : Increment Integer
Section A.114: , , : Input String from I/O Port
Section A.115: : Software Interrupt
Section A.116: , , , : Breakpoints
Section A.117: : Interrupt if Overflow
Section A.118: : Invalidate Internal Caches
Section A.119: : Invalidate TLB Entry
Section A.120: , , : Return from Interrupt
Section A.121: , : Jump if CX/ECX Zero
Section A.122: : Jump
Section A.123: : Conditional Branch
Section A.124: : Load AH from Flags
Section A.125: : Load Access Rights
Section A.126: , , , , : Load Far Pointer
Section A.127: : Load Streaming SIMD Extension Control/Status
Section A.128: : Load Effective Address
Section A.129: : Destroy Stack Frame
Section A.130: , , : Load Descriptor Tables
Section A.131: : Load/Store Machine Status Word
Section A.132: , : Load Processor State
Section A.133: , , : Load from String
Section A.134: , , , , : Loop with Counter
Section A.135: : Load Segment Limit
Section A.136: : Load Task Register
Section A.137: : Byte Mask Write
Section A.138: : Packed Single-FP Maximum
Section A.139: : Scalar Single-FP Maximum
Section A.140: : Packed Single-FP Minimum
Section A.141: : Scalar Single-FP Minimum
Section A.142: : Move Data
Section A.143: : Move Aligned Four Packed Single-FP
Section A.144: : Move Doubleword to/from MMX Register
Section A.145: : High to Low Packed Single-FP
Section A.146: : Move High Packed Single-FP
Section A.147: : Move Mask To Integer
Section A.148: : Move Aligned Four Packed Single-FP Non Temporal
Section A.149: : Move 64 Bits Non Temporal
Section A.150: : Move Quadword to/from MMX Register
Section A.151: , , : Move String
Section A.152: : Move Scalar Single-FP
Section A.153: , : Move Data with Sign or Zero Extend
Section A.154: : Move Unaligned Four Packed Single-FP
Section A.155: : Unsigned Integer Multiply
Section A.156: : Packed Single-FP Multiply
Section A.157: : Scalar Single-FP Multiply
Section A.158: , : Two's and One's Complement
Section A.159: : No Operation
Section A.160: : Bitwise OR
Section A.161: : Bit-wise Logical OR for Single-FP Data
Section A.162: : Output Data to I/O Port
Section A.163: , , : Output String to I/O Port
Section A.164: , , : Pack Data
Section A.165: : MMX Packed Addition
Section A.166: : MMX Packed Addition to Implicit Destination
Section A.167: , : MMX Bitwise AND and AND-NOT
Section A.168: : MMX Packed Average
Section A.169: : Packed Average
Section A.170: : Packed Average
Section A.171: : 3dnow instruction (duh!)
Section A.172: : MMX Packed Comparison
Section A.173: : MMX Packed Distance and Accumulate with Implied Register
Section A.174: : Extract Word
Section A.175: : 3dnow instruction (duh!)
Section A.176: : 3dnow instruction (duh!)
Section A.177: : 3dnow instruction (duh!)
Section A.178: : 3dnow instruction (duh!)
Section A.179: : 3dnow instruction (duh!)
Section A.180: : 3dnow instruction (duh!)
Section A.181: : 3dnow instruction (duh!)
Section A.182: : 3dnow instruction (duh!)
Section A.183: : 3dnow instruction (duh!)
Section A.184: : 3dnow instruction (duh!)
Section A.185: : 3dnow instruction (duh!)
Section A.186: : 3dnow instruction (duh!)
Section A.187: : 3dnow instruction (duh!)
Section A.188: : 3dnow instruction (duh!)
Section A.189: : 3dnow instruction (duh!)
Section A.190: : 3dnow instruction (duh!)
Section A.191: : 3dnow instruction (duh!)
Section A.192: : Insert Word
Section A.193: : MMX Packed Multiply and Accumulate with Rounding
Section A.194: : MMX Packed Multiply and Add
Section A.195: : MMX Packed Magnitude
Section A.196: : Packed Signed Integer Word Maximum
Section A.197: : Packed Unsigned Integer Byte Maximum
Section A.198: : Packed Signed Integer Word Minimum
Section A.199: : Packed Unsigned Integer Byte Minimum
Section A.200: : Move Byte Mask To Integer
Section A.201: , : MMX Packed Multiply High with Rounding
Section A.202: : 3dnow instruction (duh!)
Section A.203: : Packed Multiply High Unsigned
Section A.204: , : MMX Packed Multiply
Section A.205: : MMX Packed Conditional Move
Section A.206: : Pop Data from Stack
Section A.207: : Pop All General-Purpose Registers
Section A.208: : Pop Flags Register
Section A.209: : MMX Bitwise OR
Section A.210: : Prefetch
Section A.211: : Prefetch
Section A.212: : Prefetch
Section A.213: : Prefetch
Section A.214: : 3dnow instruction (duh!)
Section A.215: : 3dnow instruction (duh!)
Section A.216: : Packed Sum of Absolute Differences
Section A.217: : Packed Shuffle Word
Section A.218: , , : MMX Bit Shifts
Section A.219: : MMX Packed Subtraction
Section A.220: : MMX Packed Subtract with Saturation to Implied Destination
Section A.221: : Unpack Data
Section A.222: : Push Data on Stack
Section A.223: : Push All General-Purpose Registers
Section A.224: : Push Flags Register
Section A.225: : MMX Bitwise XOR
Section A.226: , : Bitwise Rotate through Carry Bit
Section A.227: : Packed Single-FP Reciprocal
Section A.228: : Scalar Single-FP Reciprocal
Section A.229: : Read Model-Specific Registers
Section A.230: : Read Performance-Monitoring Counters
Section A.231: : Read Time-Stamp Counter
Section A.232: , , : Return from Procedure Call
Section A.233: , : Bitwise Rotate
Section A.234: : Resume from System-Management Mode
Section A.235: :Packed Single-FP Square Root Reciprocal
Section A.236: :Scalar Single-FP Square Root Reciprocal
Section A.237: : Store AH to Flags
Section A.238: , : Bitwise Arithmetic Shifts
Section A.239: : Set AL from Carry Flag
Section A.240: : Subtract with Borrow
Section A.241: , , : Scan String
Section A.242: : Set Register from Condition
Section A.243: : Store Fence
Section A.244: , , : Store Descriptor Table Pointers
Section A.245: , : Bitwise Logical Shifts
Section A.246: , : Bitwise Double-Precision Shifts
Section A.247: : Shuffle Single-FP
Section A.248: : System Management Interrupt
Section A.249: : Store Machine Status Word
Section A.250: : Packed Single-FP Square Root
Section A.251: : Scalar Single-FP Square Root
Section A.252: , , : Set Flags
Section A.253: : Store Streaming SIMD Extension Control/Status
Section A.254: , , : Store Byte to String
Section A.255: : Store Task Register
Section A.256: : Subtract Integers
Section A.257: : Packed Single-FP Subtract
Section A.258: : Scalar Single-FP Subtract
Section A.259: : Test Bits (notional bitwise AND)
Section A.260: : Unordered Scalar Single-FP compare and set EFLAGS
Section A.261: : User Move Data
Section A.262: : Unpack High Packed Single-FP Data
Section A.263: : Unpack Low Packed Single-FP Data
Section A.264: , : Verify Segment Readability/Writability
Section A.265: : Wait for Floating-Point Processor
Section A.266: : Write Back and Invalidate Cache
Section A.267: : Write Model-Specific Registers
Section A.268: : Exchange and Add
Section A.269: : Extract Bit String
Section A.270: : Exchange
Section A.271: : Translate Byte in Lookup Table
Section A.272: : Bitwise Exclusive OR
Section A.273: : Bit-wise Logical Xor for Single-FP Data