The Netwide Assembler
Total Page:16
File Type:pdf, Size:1020Kb
NASM – The Netwide Assembler version 2.15.05rc1 © 1996-2020 The NASM Development Team — All Rights Reserved This document is redistributable under the license given in the section "License". Contents Chapter 1: Introduction . 17 1.1 What Is NASM?. 17 1.1.1 License . 17 Chapter 2: Running NASM . 19 2.1 NASM Command-Line Syntax . 19 2.1.1 The -o Option: Specifying the Output File Name . 19 2.1.2 The -f Option: Specifying the Output File Format . 20 2.1.3 The -l Option: Generating a Listing File . 20 2.1.4 The -L Option: Additional or Modified Listing Info . 20 2.1.5 The -M Option: Generate Makefile Dependencies . 21 2.1.6 The -MG Option: Generate Makefile Dependencies . 21 2.1.7 The -MF Option: Set Makefile Dependency File . 21 2.1.8 The -MD Option: Assemble and Generate Dependencies . 21 2.1.9 The -MT Option: Dependency Target Name . 21 2.1.10 The -MQ Option: Dependency Target Name (Quoted) . 21 2.1.11 The -MP Option: Emit phony targets . 21 2.1.12 The -MW Option: Watcom Make quoting style . 21 2.1.13 The -F Option: Selecting a Debug Information Format . 22 2.1.14 The -g Option: Enabling Debug Information. 22 2.1.15 The -X Option: Selecting an Error Reporting Format . 22 2.1.16 The -Z Option: Send Errors to a File . 22 2.1.17 The -s Option: Send Errors to stdout ...........................22 2.1.18 The -i Option: Include File Search Directories . 23 2.1.19 The -p Option: Pre-Include a File . 23 2.1.20 The -d Option: Pre-Define a Macro . 23 2.1.21 The -u Option: Undefine a Macro . 23 2.1.22 The -E Option: Preprocess Only . 24 2.1.23 The -a Option: Don’t Preprocess At All . 24 2.1.24 The -O Option: Specifying Multipass Optimization . 24 2.1.25 The -t Option: Enable TASM Compatibility Mode . 24 2.1.26 The -w and -W Options: Enable or Disable Assembly Warnings. 25 2.1.27 The -v Option: Display Version Info . 29 2.1.28 The --(g|l)prefix, --(g|l)postfix Options. 29 3 2.1.29 The --pragma Option . 29 2.1.30 The --before Option . 29 2.1.31 The --limit-X Option. 29 2.1.32 The --keep-all Option . 30 2.1.33 The --no-line Option. 30 2.1.34 The NASMENV Environment Variable . 30 2.2 Quick Start for MASM Users . 30 2.2.1 NASM Is Case-Sensitive . 30 2.2.2 NASM Requires Square Brackets For Memory References. 30 2.2.3 NASM Doesn’t Store Variable Types . 31 2.2.4 NASM Doesn’t ASSUME....................................31 2.2.5 NASM Doesn’t Support Memory Models . 31 2.2.6 Floating-Point Differences . 31 2.2.7 Other Differences. 32 2.2.8 MASM compatibility package . 32 Chapter 3: The NASM Language . 33 3.1 Layout of a NASM Source Line . 33 3.2 Pseudo-Instructions. 34 3.2.1 Dx: Declaring Initialized Data . 34 3.2.2 RESB and Friends: Declaring Uninitialized Data . 35 3.2.3 INCBIN: Including External Binary Files . 35 3.2.4 EQU: Defining Constants . 35 3.2.5 TIMES: Repeating Instructions or Data . 36 3.3 Effective Addresses . 36 3.4 Constants . 37 3.4.1 Numeric Constants . 37 3.4.2 Character Strings . 38 3.4.3 Character Constants . 39 3.4.4 String Constants . 39 3.4.5 Unicode Strings . 39 3.4.6 Floating-Point Constants . 39 3.4.7 Packed BCD Constants . 41 3.5 Expressions . 41 3.5.1 ? ... :: Conditional Operator . 41 3.5.2 : ||: Boolean OR Operator . 41 3.5.3 : ^^: Boolean XOR Operator . 41 4 3.5.4 : &&: Boolean AND Operator. 41 3.5.5 : Comparison Operators . 41 3.5.6 |: Bitwise OR Operator . 42 3.5.7 ^: Bitwise XOR Operator . 42 3.5.8 &: Bitwise AND Operator . 42 3.5.9 Bit Shift Operators . 42 3.5.10 + and -: Addition and Subtraction Operators . 42 3.5.11 Multiplication, Division and Modulo . 42 3.5.12 Unary Operators . 42 3.6 SEG and WRT ...........................................43 3.7 STRICT: Inhibiting Optimization . 43 3.8 Critical Expressions . 44 3.9 Local Labels . 44 Chapter 4: The NASM Preprocessor . 47 4.1 Single-Line Macros . 47 4.1.1 The Normal Way: %define .................................47 4.1.2 Resolving %define: %xdefine ................................48 4.1.3 Macro Indirection: %[...] .................................49 4.1.4 Concatenating Single Line Macro Tokens: %+ ........................49 4.1.5 The Macro Name Itself: %? and %?? .............................50 4.1.6 The Single-Line Macro Name: %*? and %*??.........................50 4.1.7 Undefining Single-Line Macros: %undef ...........................51 4.1.8 Preprocessor Variables: %assign ..............................51 4.1.9 Defining Strings: %defstr ..................................51 4.1.10 Defining Tokens: %deftok .................................52 4.1.11 Defining Aliases: %defalias ................................52 4.1.12 Conditional Comma Operator: %, .............................52 4.2 String Manipulation in Macros. 52 4.2.1 Concatenating Strings: %strcat ..............................53 4.2.2 String Length: %strlen ...................................53 4.2.3 Extracting Substrings: %substr ...............................53 4.3 Multi-Line Macros: %macro ....................................53 4.3.1 Overloading Multi-Line Macros . 54 4.3.2 Macro-Local Labels . 55 4.3.3 Greedy Macro Parameters . 55 4.3.4 Macro Parameters Range . 56 5 4.3.5 Default Macro Parameters . 56 4.3.6 %0: Macro Parameter Counter. 57 4.3.7 %00: Label Preceeding Macro . 57 4.3.8 %rotate: Rotating Macro Parameters . 57 4.3.9 Concatenating Macro Parameters . 58 4.3.10 Condition Codes as Macro Parameters . 59 4.3.11 Disabling Listing Expansion . 59 4.3.12 Undefining Multi-Line Macros: %unmacro .........................60 4.4 Conditional.