NASM — the Netwide Assembler Version 2.09.10
Total Page:16
File Type:pdf, Size:1020Kb
NASM — The Netwide Assembler version 2.09.10 -~~..~:#;L .-:#;L,.- .~:#:;.T -~~.~:;. .~:;. E8+U *T +U' *T# .97 *L E8+' *;T' *;, D97 `*L .97 '*L "T;E+:, D9 *L *L H7 I# T7 I# "*:. H7 I# I# U: :8 *#+ , :8 T, 79 U: :8 :8 ,#B. .IE, "T;E* .IE, J *+;#:T*" ,#B. .IE, .IE, © 1996−2011 The NASM Development Team — All Rights Reserved This document is redistributable under the license given in the file "LICENSE" distributed in the NASM archive. Contents Chapter 1: Introduction . .15 1.1 What Is NASM? . .15 1.1.1 Why Yet Another Assembler?. .15 1.1.2 License Conditions . .15 1.2 Contact Information . .16 1.3 Installation. .16 1.3.1 Installing NASM under MS−DOS or Windows . .16 1.3.2 Installing NASM under Unix . .17 Chapter 2: Running NASM . .18 2.1 NASM Command−Line Syntax . .18 2.1.1 The −o Option: Specifying the Output File Name . .18 2.1.2 The −f Option: Specifying the Output File Format . .19 2.1.3 The −l Option: Generating a Listing File . .19 2.1.4 The −M Option: Generate Makefile Dependencies . .19 2.1.5 The −MG Option: Generate Makefile Dependencies . .19 2.1.6 The −MF Option: Set Makefile Dependency File . .19 2.1.7 The −MD Option: Assemble and Generate Dependencies. .19 2.1.8 The −MT Option: Dependency Target Name. .20 2.1.9 The −MQ Option: Dependency Target Name (Quoted) . .20 2.1.10 The −MP Option: Emit phony targets. .20 2.1.11 The −F Option: Selecting a Debug Information Format . .20 2.1.12 The −g Option: Enabling Debug Information. .20 2.1.13 The −X Option: Selecting an Error Reporting Format. .20 2.1.14 The −Z Option: Send Errors to a File. .21 2.1.15 The −s Option: Send Errors to stdout ............................21 2.1.16 The −i Option: Include File Search Directories . .21 2.1.17 The −p Option: Pre−Include a File. .21 2.1.18 The −d Option: Pre−Define a Macro. .21 2.1.19 The −u Option: Undefine a Macro . .22 2.1.20 The −E Option: Preprocess Only. .22 3 2.1.21 The −a Option: Don’t Preprocess At All . .22 2.1.22 The −O Option: Specifying Multipass Optimization . .22 2.1.23 The −t Option: Enable TASM Compatibility Mode . .23 2.1.24 The −w and −W Options: Enable or Disable Assembly Warnings . .23 2.1.25 The −v Option: Display Version Info . .24 2.1.26 The −y Option: Display Available Debug Info Formats . .24 2.1.27 The −−prefix and −−postfix Options. .24 2.1.28 The NASMENV Environment Variable . .24 2.2 Quick Start for MASM Users . .25 2.2.1 NASM Is Case−Sensitive . .25 2.2.2 NASM Requires Square Brackets For Memory References . .25 2.2.3 NASM Doesn’t Store Variable Types . .25 2.2.4 NASM Doesn’t ASSUME ....................................26 2.2.5 NASM Doesn’t Support Memory Models . .26 2.2.6 Floating−Point Differences . .26 2.2.7 Other Differences . .26 Chapter 3: The NASM Language . .27 3.1 Layout of a NASM Source Line . .27 3.2 Pseudo−Instructions . .28 3.2.1 DB and Friends: Declaring Initialized Data . .28 3.2.2 RESB and Friends: Declaring Uninitialized Data . .28 3.2.3 INCBIN: Including External Binary Files . .28 3.2.4 EQU: Defining Constants . .29 3.2.5 TIMES: Repeating Instructions or Data . .29 3.3 Effective Addresses . .29 3.4 Constants . .30 3.4.1 Numeric Constants . .30 3.4.2 Character Strings . .31 3.4.3 Character Constants. .32 3.4.4 String Constants . .32 3.4.5 Unicode Strings. .32 3.4.6 Floating−Point Constants . .33 3.4.7 Packed BCD Constants . .34 3.5 Expressions . .34 3.5.1 |: Bitwise OR Operator. .34 4 3.5.2 ^: Bitwise XOR Operator . .34 3.5.3 &: Bitwise AND Operator . .34 3.5.4 << and >>: Bit Shift Operators . .34 3.5.5 + and −: Addition and Subtraction Operators . .34 3.5.6 *, /, //, % and %%: Multiplication and Division. .34 3.5.7 Unary Operators: +, −, ~, ! and SEG ..............................35 3.6 SEG and WRT ............................................35 3.7 STRICT: Inhibiting Optimization . .35 3.8 Critical Expressions . .36 3.9 Local Labels. .36 Chapter 4: The NASM Preprocessor . .38 4.1 Single−Line Macros . .38 4.1.1 The Normal Way: %define ..................................38 4.1.2 Resolving %define: %xdefine ...............................39 4.1.3 Macro Indirection: %[...] ..................................40 4.1.4 Concatenating Single Line Macro Tokens: %+..........................40 4.1.5 The Macro Name Itself: %? and %?? ..............................40 4.1.6 Undefining Single−Line Macros: %undef ...........................41 4.1.7 Preprocessor Variables: %assign ...............................41 4.1.8 Defining Strings: %defstr ..................................42 4.1.9 Defining Tokens: %deftok ..................................42 4.2 String Manipulation in Macros . .42 4.2.1 Concatenating Strings: %strcat ................................42 4.2.2 String Length: %strlen ....................................42 4.2.3 Extracting Substrings: %substr ................................43 4.3 Multi−Line Macros: %macro ....................................43 4.3.1 Overloading Multi−Line Macros . .44 4.3.2 Macro−Local Labels . .44 4.3.3 Greedy Macro Parameters. .45 4.3.4 Macro Parameters Range . .45 4.3.5 Default Macro Parameters . .46 4.3.6 %0: Macro Parameter Counter. .47 4.3.7 %00: Label Preceeding Macro . .47 4.3.8 %rotate: Rotating Macro Parameters . .47 4.3.9 Concatenating Macro Parameters . .48 5 4.3.10 Condition Codes as Macro Parameters . .49 4.3.11 Disabling Listing Expansion . .49 4.3.12 Undefining Multi−Line Macros: %unmacro..........................50 4.4 Conditional Assembly . .50 4.4.1 %ifdef: Testing Single−Line Macro Existence. .50 4.4.2 %ifmacro: Testing Multi−Line Macro Existence . .51 4.4.3 %ifctx: Testing the Context Stack. .51 4.4.4 %if: Testing Arbitrary Numeric Expressions . .51 4.4.5 %ifidn and %ifidni: Testing Exact Text Identity . .52 4.4.6 %ifid, %ifnum, %ifstr: Testing Token Types . ..