NASM — the Netwide Assembler Version 0.99.04
Total Page:16
File Type:pdf, Size:1020Kb
NASM — The Netwide Assembler version 0.99.04 -~~..~:#;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, © 2007 The NASM Development Team All rights reserved. This document is redistributable under the license given in the file "COPYING" distributed in the NASM archive. Contents Chapter 1: Introduction. .10 1.1 What Is NASM? . .10 1.1.1 Why Yet Another Assembler? . .10 1.1.2 License Conditions . .10 1.2 Contact Information . .10 1.3 Installation . .11 1.3.1 Installing NASM under MS−DOS or Windows . .11 1.3.2 Installing NASM under Unix . .11 Chapter 2: Running NASM . .13 2.1 NASM Command−Line Syntax . .13 2.1.1 The −o Option: Specifying the Output File Name . .13 2.1.2 The −f Option: Specifying the Output File Format . .14 2.1.3 The −l Option: Generating a Listing File. .14 2.1.4 The −M Option: Generate Makefile Dependencies . .14 2.1.5 The −MG Option: Generate Makefile Dependencies . .14 2.1.6 The −F Option: Selecting a Debug Information Format . .14 2.1.7 The −g Option: Enabling Debug Information. .15 2.1.8 The −X Option: Selecting an Error Reporting Format . .15 2.1.9 The −E Option: Send Errors to a File . .15 2.1.10 The −s Option: Send Errors to stdout . .15 2.1.11 The −i Option: Include File Search Directories. .15 2.1.12 The −p Option: Pre−Include a File. .16 2.1.13 The −d Option: Pre−Define a Macro . .16 2.1.14 The −u Option: Undefine a Macro . .16 2.1.15 The −e Option: Preprocess Only. .16 2.1.16 The −a Option: Don’t Preprocess At All . .17 2.1.17 The −On Option: Specifying Multipass Optimization. .17 2.1.18 The −t option: Enable TASM Compatibility Mode . .17 2.1.19 The −w Option: Enable or Disable Assembly Warnings . .18 2.1.20 The −v Option: Display Version Info . .18 3 2.1.21 The −y Option: Display Available Debug Info Formats . .18 2.1.22 The −−prefix and −−postfix Options. .19 2.1.23 The NASMENV Environment Variable . .19 2.2 Quick Start for MASM Users. .19 2.2.1 NASM Is Case−Sensitive . .19 2.2.2 NASM Requires Square Brackets For Memory References . .19 2.2.3 NASM Doesn’t Store Variable Types . .20 2.2.4 NASM Doesn’t ASSUME . .20 2.2.5 NASM Doesn’t Support Memory Models . .20 2.2.6 Floating−Point Differences . .20 2.2.7 Other Differences. .21 Chapter 3: The NASM Language . .22 3.1 Layout of a NASM Source Line . .22 3.2 Pseudo−Instructions . .23 3.2.1 DB and friends: Declaring initialized Data . .23 3.2.2 RESB and friends: Declaring Uninitialized Data . .23 3.2.3 INCBIN: Including External Binary Files . .23 3.2.4 EQU: Defining Constants. .24 3.2.5 TIMES: Repeating Instructions or Data . .24 3.3 Effective Addresses . .24 3.4 Constants. .25 3.4.1 Numeric Constants . .25 3.4.2 Character Constants . .26 3.4.3 String Constants . .26 3.4.4 Floating−Point Constants . .26 3.5 Expressions . .27 3.5.1 |: Bitwise OR Operator . .27 3.5.2 ^: Bitwise XOR Operator . .27 3.5.3 &: Bitwise AND Operator . .27 3.5.4 << and >>: Bit Shift Operators . .28 3.5.5 + and −: Addition and Subtraction Operators . .28 3.5.6 *, /, //, % and %%: Multiplication and Division . .28 3.5.7 Unary Operators: +, −, ~, ! and SEG . .28 3.6 SEG and WRT . .28 3.7 STRICT: Inhibiting Optimization . .29 4 3.8 Critical Expressions . .29 3.9 Local Labels . .30 Chapter 4: The NASM Preprocessor . .32 4.1 Single−Line Macros. .32 4.1.1 The Normal Way: %define . .32 4.1.2 Enhancing %define: %xdefine . .33 4.1.3 Concatenating Single Line Macro Tokens: %+ . .34 4.1.4 Undefining macros: %undef . .34 4.1.5 Preprocessor Variables: %assign . .35 4.2 String Handling in Macros: %strlen and %substr . .35 4.2.1 String Length: %strlen . .35 4.2.2 Sub−strings: %substr . .35 4.3 Multi−Line Macros: %macro . .36 4.3.1 Overloading Multi−Line Macros . .36 4.3.2 Macro−Local Labels . .37 4.3.3 Greedy Macro Parameters . .37 4.3.4 Default Macro Parameters . .38 4.3.5 %0: Macro Parameter Counter . .39 4.3.6 %rotate: Rotating Macro Parameters . .39 4.3.7 Concatenating Macro Parameters . .40 4.3.8 Condition Codes as Macro Parameters . .41 4.3.9 Disabling Listing Expansion. .41 4.4 Conditional Assembly. .41 4.4.1 %ifdef: Testing Single−Line Macro Existence . .42 4.4.2 ifmacro: Testing Multi−Line Macro Existence . .42 4.4.3 %ifctx: Testing the Context Stack . .42 4.4.4 %if: Testing Arbitrary Numeric Expressions . .43 4.4.5 %ifidn and %ifidni: Testing Exact Text Identity . .43 4.4.6 %ifid, %ifnum, %ifstr: Testing Token Types. .43 4.4.7 %error: Reporting User−Defined Errors . .44 4.5 Preprocessor Loops: %rep . .45 4.6 Including Other Files . .45 4.7 The Context Stack . .46 4.7.1 %push and %pop: Creating and Removing Contexts . .46.