Contents In Detail

  1. Title Page
  2. Copyright
  3. Dedication
  4. About the Author
  5. Foreword
  6. Acknowledgments
  7. Introduction
  8. Part I: Machine Organization
    1. Chapter 1: Hello, World of Assembly Language
      1. 1.1 What You’ll Need
      2. 1.2 Setting Up MASM on Your Machine
      3. 1.3 Setting Up a Text Editor on Your Machine
      4. 1.4 The Anatomy of a MASM Program
      5. 1.5 Running Your First MASM Program
      6. 1.6 Running Your First MASM/C++ Hybrid Program
      7. 1.8 The Memory Subsystem
      8. 1.9 Declaring Memory Variables in MASM
        1. 1.9.1 Associating Memory Addresses with Variables
        2. 1.9.2 Associating Data Types with Variables
      9. 1.10 Declaring (Named) Constants in MASM
      10. 1.11 Some Basic Machine Instructions
        1. 1.11.1 The mov Instruction
        2. 1.11.2 Type Checking on Instruction Operands
        3. 1.11.3 The add and sub Instructions
        4. 1.11.4 The lea Instruction
        5. 1.11.5 The call and ret Instructions and MASM Procedures
      11. 1.12 Calling C/C++ Procedures
      12. 1.13 Hello, World!
      13. 1.14 Returning Function Results in Assembly Language
      14. 1.15 Automating the Build Process
      15. 1.16 Microsoft ABI Notes
        1. 1.16.1 Variable Size
        2. 1.16.2 Register Usage
        3. 1.16.3 Stack Alignment
      16. 1.17 For More Information
      17. 1.18 Test Yourself
    2. Chapter 2: Computer Data Representation and Operations
      1. 2.1 Numbering Systems
        1. 2.1.1 A Review of the Decimal System
        2. 2.1.2 The Binary Numbering System
        3. 2.1.3 Binary Conventions
      2. 2.2 The Hexadecimal Numbering System
      3. 2.3 A Note About Numbers vs. Representation
      4. 2.4 Data Organization
        1. 2.4.1 Bits
        2. 2.4.2 Nibbles
        3. 2.4.3 Bytes
        4. 2.4.4 Words
        5. 2.4.5 Double Words
        6. 2.4.6 Quad Words and Octal Words
      5. 2.5 Logical Operations on Bits
        1. 2.5.1 The AND Operation
        2. 2.5.2 The OR Operation
        3. 2.5.3 The XOR Operation
        4. 2.5.4 The NOT Operation
      6. 2.6 Logical Operations on Binary Numbers and Bit Strings
      7. 2.7 Signed and Unsigned Numbers
      8. 2.8 Sign Extension and Zero Extension
      9. 2.9 Sign Contraction and Saturation
        1. 2.10.1 The jmp Instruction
        2. 2.10.2 The Conditional Jump Instructions
        3. 2.10.3 The cmp Instruction and Corresponding Conditional Jumps
        4. 2.10.4 Conditional Jump Synonyms
      10. 2.11 Shifts and Rotates
      11. 2.12 Bit Fields and Packed Data
      12. 2.13 IEEE Floating-Point Formats
        1. 2.13.1 Single-Precision Format
        2. 2.13.2 Double-Precision Format
        3. 2.13.3 Extended-Precision Format
        4. 2.13.4 Normalized Floating-Point Values
        5. 2.13.5 Non-Numeric Values
        6. 2.13.6 MASM Support for Floating-Point Values
      13. 2.14 Binary-Coded Decimal Representation
      14. 2.15 Characters
        1. 2.15.1 The ASCII Character Encoding
        2. 2.15.2 MASM Support for ASCII Characters
      15. 2.16 The Unicode Character Set
        1. 2.16.1 Unicode Code Points
        2. 2.16.2 Unicode Code Planes
        3. 2.16.3 Unicode Encodings
      16. 2.17 MASM Support for Unicode
      17. 2.18 For More Information
      18. 2.19 Test Yourself
    3. Chapter 3: Memory Access and Organization
      1. 3.1 Runtime Memory Organization
        1. 3.1.1 The .code Section
        2. 3.1.2 The .data Section
        3. 3.1.3 The .const Section
        4. 3.1.4 The .data? Section
        5. 3.1.5 Organization of Declaration Sections Within Your Programs
        6. 3.1.6 Memory Access and 4K Memory Management Unit Pages
      2. 3.2 How MASM Allocates Memory for Variables
      3. 3.3 The Label Declaration
      4. 3.4 Little-Endian and Big-Endian Data Organization
      5. 3.5 Memory Access
      6. 3.6 MASM Support for Data Alignment
      7. 3.7 The x86-64 Addressing Modes
        1. 3.7.1 x86-64 Register Addressing Modes
        2. 3.7.2 x86-64 64-Bit Memory Addressing Modes
        3. 3.7.3 Large Address Unaware Applications
      8. 3.8 Address Expressions
      9. 3.9 The Stack Segment and the push and pop Instructions
        1. 3.9.1 The Basic push Instruction
        2. 3.9.2 The Basic pop Instruction
        3. 3.9.3 Preserving Registers with the push and pop Instructions
      10. 3.10 The Stack Is a LIFO Data Structure
      11. 3.11 Other push and pop Instructions
      12. 3.12 Removing Data from the Stack Without Popping It
      13. 3.13 Accessing Data You’ve Pushed onto the Stack Without Popping It
      14. 3.14 Microsoft ABI Notes
      15. 3.15 For More Information
      16. 3.16 Test Yourself
    4. Chapter 4: Constants, Variables, and Data Types
      1. 4.1 The imul Instruction
      2. 4.2 The inc and dec Instructions
      3. 4.3 MASM Constant Declarations
        1. 4.3.1 Constant Expressions
        2. 4.3.2 this and $ Operators
        3. 4.3.3 Constant Expression Evaluation
      4. 4.4 The MASM typedef Statement
      5. 4.5 Type Coercion
      6. 4.6 Pointer Data Types
        1. 4.6.1 Using Pointers in Assembly Language
        2. 4.6.2 Declaring Pointers in MASM
        3. 4.6.3 Pointer Constants and Pointer Constant Expressions
        4. 4.6.4 Pointer Variables and Dynamic Memory Allocation
        5. 4.6.5 Common Pointer Problems
      7. 4.7 Composite Data Types
      8. 4.8 Character Strings
        1. 4.8.1 Zero-Terminated Strings
        2. 4.8.2 Length-Prefixed Strings
        3. 4.8.3 String Descriptors
        4. 4.8.4 Pointers to Strings
        5. 4.8.5 String Functions
      9. 4.9 Arrays
        1. 4.9.1 Declaring Arrays in Your MASM Programs
        2. 4.9.2 Accessing Elements of a Single-Dimensional Array
        3. 4.9.3 Sorting an Array of Values
      10. 4.10 Multidimensional Arrays
        1. 4.10.1 Row-Major Ordering
        2. 4.10.2 Column-Major Ordering
        3. 4.10.3 Allocating Storage for Multidimensional Arrays
        4. 4.10.4 Accessing Multidimensional Array Elements in Assembly Language
      11. 4.11 Records/Structs
        1. 4.11.1 MASM Struct Declarations
        2. 4.11.2 Accessing Record/Struct Fields
        3. 4.11.3 Nesting MASM Structs
        4. 4.11.4 Initializing Struct Fields
        5. 4.11.5 Arrays of Structs
        6. 4.11.6 Aligning Fields Within a Record
      12. 4.12 Unions
        1. 4.12.1 Anonymous Unions
        2. 4.12.2 Variant Types
      13. 4.13 Microsoft ABI Notes
      14. 4.14 For More Information
      15. 4.15 Test Yourself
  9. Part II: Assembly Language Programming
    1. Chapter 5: Procedures
      1. 5.1 Implementing Procedures
        1. 5.1.1 The call and ret Instructions
        2. 5.1.2 Labels in a Procedure
      2. 5.2 Saving the State of the Machine
      3. 5.3 Procedures and the Stack
        1. 5.3.1 Activation Records
        2. 5.3.2 The Assembly Language Standard Entry Sequence
        3. 5.3.3 The Assembly Language Standard Exit Sequence
      4. 5.4 Local (Automatic) Variables
        1. 5.4.1 Low-Level Implementation of Automatic (Local) Variables
        2. 5.4.2 The MASM Local Directive
        3. 5.4.3 Automatic Allocation
      5. 5.5 Parameters
        1. 5.5.1 Pass by Value
        2. 5.5.2 Pass by Reference
        3. 5.5.3 Low-Level Parameter Implementation
        4. 5.5.4 Declaring Parameters with the proc Directive
        5. 5.5.5 Accessing Reference Parameters on the Stack
      6. 5.6 Calling Conventions and the Microsoft ABI
      7. 5.7 The Microsoft ABI and Microsoft Calling Convention
        1. 5.7.1 Data Types and the Microsoft ABI
        2. 5.7.2 Parameter Locations
        3. 5.7.3 Volatile and Nonvolatile Registers
        4. 5.7.4 Stack Alignment
        5. 5.7.5 Parameter Setup and Cleanup (or “What’s with These Magic Instructions?”)
      8. 5.8 Functions and Function Results
      9. 5.9 Recursion
      10. 5.10 Procedure Pointers
      11. 5.11 Procedural Parameters
      12. 5.12 Saving the State of the Machine, Part II
      13. 5.13 Microsoft ABI Notes
      14. 5.14 For More Information
      15. 5.15 Test Yourself
    2. Chapter 6: Arithmetic
      1. 6.1 x86-64 Integer Arithmetic Instructions
        1. 6.1.1 Sign- and Zero-Extension Instructions
        2. 6.1.2 The mul and imul Instructions
        3. 6.1.3 The div and idiv Instructions
        4. 6.1.4 The cmp Instruction, Revisited
        5. 6.1.5 The setcc Instructions
        6. 6.1.6 The test Instruction
      2. 6.2 Arithmetic Expressions
        1. 6.2.1 Simple Assignments
        2. 6.2.2 Simple Expressions
        3. 6.2.3 Complex Expressions
        4. 6.2.4 Commutative Operators
      3. 6.3 Logical (Boolean) Expressions
      4. 6.4 Machine and Arithmetic Idioms
        1. 6.4.1 Multiplying Without mul or imul
        2. 6.4.2 Dividing Without div or idiv
        3. 6.4.3 Implementing Modulo-N Counters with AND
      5. 6.5 Floating-Point Arithmetic
        1. 6.5.1 Floating-Point on the x86-64
        2. 6.5.2 FPU Registers
        3. 6.5.3 FPU Data Types
        4. 6.5.4 The FPU Instruction Set
        5. 6.5.5 FPU Data Movement Instructions
        6. 6.5.6 Conversions
        7. 6.5.7 Arithmetic Instructions
        8. 6.5.8 Comparison Instructions
        9. 6.5.9 Constant Instructions
        10. 6.5.10 Transcendental Instructions
        11. 6.5.11 Miscellaneous Instructions
      6. 6.6 Converting Floating-Point Expressions to Assembly Language
        1. 6.6.1 Converting Arithmetic Expressions to Postfix Notation
        2. 6.6.2 Converting Postfix Notation to Assembly Language
      7. 6.7 SSE Floating-Point Arithmetic
        1. 6.7.1 SSE MXCSR Register
        2. 6.7.2 SSE Floating-Point Move Instructions
        3. 6.7.3 SSE Floating-Point Arithmetic Instructions
        4. 6.7.4 SSE Floating-Point Comparisons
        5. 6.7.5 SSE Floating-Point Conversions
      8. 6.8 For More Information
      9. 6.9 Test Yourself
    3. Chapter 7: Low-Level Control Structures
      1. 7.1 Statement Labels
        1. 7.1.1 Using Local Symbols in Procedures
        2. 7.1.2 Initializing Arrays with Label Addresses
      2. 7.2 Unconditional Transfer of Control (jmp)
        1. 7.2.1 Register-Indirect Jumps
        2. 7.2.2 Memory-Indirect Jumps
      3. 7.3 Conditional Jump Instructions
      4. 7.4 Trampolines
      5. 7.5 Conditional Move Instructions
      6. 7.6 Implementing Common Control Structures in Assembly Language
        1. 7.6.1 Decisions
        2. 7.6.2 if/then/else Sequences
        3. 7.6.3 Complex if Statements Using Complete Boolean Evaluation
        4. 7.6.4 Short-Circuit Boolean Evaluation
        5. 7.6.5 Short-Circuit vs. Complete Boolean Evaluation
        6. 7.6.6 Efficient Implementation of if Statements in Assembly Language
        7. 7.6.7 switch/case Statements
      7. 7.7 State Machines and Indirect Jumps
      8. 7.8 Loops
        1. 7.8.1 while Loops
        2. 7.8.2 repeat/until Loops
        3. 7.8.3 forever/endfor Loops
        4. 7.8.4 for Loops
        5. 7.8.5 The break and continue Statements
        6. 7.8.6 Register Usage and Loops
      9. 7.9 Loop Performance Improvements
        1. 7.9.1 Moving the Termination Condition to the End of a Loop
        2. 7.9.2 Executing the Loop Backward
        3. 7.9.3 Using Loop-Invariant Computations
        4. 7.9.4 Unraveling Loops
        5. 7.9.5 Using Induction Variables
      10. 7.10 For More Information
      11. 7.11 Test Yourself
    4. Chapter 8: Advanced Arithmetic
      1. 8.1 Extended-Precision Operations
        1. 8.1.1 Extended-Precision Addition
        2. 8.1.2 Extended-Precision Subtraction
        3. 8.1.3 Extended-Precision Comparisons
        4. 8.1.4 Extended-Precision Multiplication
        5. 8.1.5 Extended-Precision Division
        6. 8.1.6 Extended-Precision Negation Operations
        7. 8.1.7 Extended-Precision AND Operations
        8. 8.1.8 Extended-Precision OR Operations
        9. 8.1.9 Extended-Precision XOR Operations
        10. 8.1.10 Extended-Precision NOT Operations
        11. 8.1.11 Extended-Precision Shift Operations
        12. 8.1.12 Extended-Precision Rotate Operations
      2. 8.2 Operating on Different-Size Operands
      3. 8.3 Decimal Arithmetic
        1. 8.3.1 Literal BCD Constants
        2. 8.3.2 Packed Decimal Arithmetic Using the FPU
      4. 8.4 For More Information
      5. 8.5 Test Yourself
    5. Chapter 9: Numeric Conversion
      1. 9.1 Converting Numeric Values to Strings
        1. 9.1.1 Converting Numeric Values to Hexadecimal Strings
        2. 9.1.2 Converting Extended-Precision Hexadecimal Values to Strings
        3. 9.1.3 Converting Unsigned Decimal Values to Strings
        4. 9.1.4 Converting Signed Integer Values to Strings
        5. 9.1.5 Converting Extended-Precision Unsigned Integers to Strings
        6. 9.1.6 Converting Extended-Precision Signed Decimal Values to Strings
        7. 9.1.7 Formatted Conversions
        8. 9.1.8 Converting Floating-Point Values to Strings
      2. 9.2 String-to-Numeric Conversion Routines
        1. 9.2.1 Converting Decimal Strings to Integers
        2. 9.2.2 Converting Hexadecimal Strings to Numeric Form
        3. 9.2.3 Converting Unsigned Decimal Strings to Integers
        4. 9.2.4 Conversion of Extended-Precision String to Unsigned Integer
        5. 9.2.5 Conversion of Extended-Precision Signed Decimal String to Integer
        6. 9.2.6 Conversion of Real String to Floating-Point
      3. 9.3 For More Information
      4. 9.4 Test Yourself
    6. Chapter 10: Table Lookups
      1. 10.1 Tables
        1. 10.1.1 Function Computation via Table Lookup
        2. 10.1.2 Generating Tables
        3. 10.1.3 Table-Lookup Performance
      2. 10.2 For More Information
      3. 10.3 Test Yourself
    7. Chapter 11: SIMD Instructions
      1. 11.1 The SSE/AVX Architectures
      2. 11.2 Streaming Data Types
      3. 11.3 Using cpuid to Differentiate Instruction Sets
      4. 11.4 Full-Segment Syntax and Segment Alignment
      5. 11.5 SSE, AVX, and AVX2 Memory Operand Alignment
      6. 11.6 SIMD Data Movement Instructions
        1. 11.6.1 The (v)movd and (v)movq Instructions
        2. 11.6.2 The (v)movaps, (v)movapd, and (v)movdqa Instructions
        3. 11.6.3 The (v)movups, (v)movupd, and (v)movdqu Instructions
        4. 11.6.4 Performance of Aligned and Unaligned Moves
        5. 11.6.5 The (v)movlps and (v)movlpd Instructions
        6. 11.6.6 The movhps and movhpd Instructions
        7. 11.6.7 The vmovhps and vmovhpd Instructions
        8. 11.6.8 The movlhps and vmovlhps Instructions
        9. 11.6.9 The movhlps and vmovhlps Instructions
        10. 11.6.10 The (v)movshdup and (v)movsldup Instructions
        11. 11.6.11 The (v)movddup Instruction
        12. 11.6.12 The (v)lddqu Instruction
        13. 11.6.13 Performance Issues and the SIMD Move Instructions
        14. 11.6.14 Some Final Comments on the SIMD Move Instructions
      7. 11.7 The Shuffle and Unpack Instructions
        1. 11.7.1 The (v)pshufb Instructions
        2. 11.7.2 The (v)pshufd Instructions
        3. 11.7.3 The (v)pshuflw and (v)pshufhw Instructions
        4. 11.7.4 The shufps and shufpd Instructions
        5. 11.7.5 The vshufps and vshufpd Instructions
        6. 11.7.6 The (v)unpcklps, (v)unpckhps, (v)unpcklpd, and (v)unpckhpd Instructions
        7. 11.7.7 The Integer Unpack Instructions
        8. 11.7.8 The (v)pextrb, (v)pextrw, (v)pextrd, and (v)pextrq Instructions
        9. 11.7.9 The (v)pinsrb, (v)pinsrw, (v)pinsrd, and (v)pinsrq Instructions
        10. 11.7.10 The (v)extractps and (v)insertps Instructions
      8. 11.8 SIMD Arithmetic and Logical Operations
      9. 11.9 The SIMD Logical (Bitwise) Instructions
        1. 11.9.1 The (v)ptest Instructions
        2. 11.9.2 The Byte Shift Instructions
        3. 11.9.3 The Bit Shift Instructions
      10. 11.10 The SIMD Integer Arithmetic Instructions
        1. 11.10.1 SIMD Integer Addition
        2. 11.10.2 Horizontal Additions
        3. 11.10.3 Double-Word–Sized Horizontal Additions
        4. 11.10.4 SIMD Integer Subtraction
        5. 11.10.5 SIMD Integer Multiplication
        6. 11.10.6 SIMD Integer Averages
        7. 11.10.7 SIMD Integer Minimum and Maximum
        8. 11.10.8 SIMD Integer Absolute Value
        9. 11.10.9 SIMD Integer Sign Adjustment Instructions
        10. 11.10.10 SIMD Integer Comparison Instructions
        11. 11.10.11 Integer Conversions
      11. 11.11 SIMD Floating-Point Arithmetic Operations
      12. 11.12 SIMD Floating-Point Comparison Instructions
        1. 11.12.1 SSE and AVX Comparisons
        2. 11.12.2 Unordered vs. Ordered Comparisons
        3. 11.12.3 Signaling and Quiet Comparisons
        4. 11.12.4 Instruction Synonyms
        5. 11.12.5 AVX Extended Comparisons
        6. 11.12.6 Using SIMD Comparison Instructions
        7. 11.12.7 The (v)movmskps, (v)movmskpd Instructions
      13. 11.13 Floating-Point Conversion Instructions
      14. 11.14 Aligning SIMD Memory Accesses
      15. 11.15 Aligning Word, Dword, and Qword Object Addresses
      16. 11.16 Filling an XMM Register with Several Copies of the Same Value
      17. 11.17 Loading Some Common Constants Into XMM and YMM Registers
      18. 11.18 Setting, Clearing, Inverting, and Testing a Single Bit in an SSE Register
      19. 11.19 Processing Two Vectors by Using a Single Incremented Index
      20. 11.20 Aligning Two Addresses to a Boundary
      21. 11.21 Working with Blocks of Data Whose Length Is Not a Multiple of the SSE/AVX Register Size
      22. 11.22 Dynamically Testing for a CPU Feature
      23. 11.23 The MASM Include Directive
      24. 11.24 And a Whole Lot More
      25. 11.25 For More Information
      26. 11.26 Test Yourself
    8. Chapter 12: Bit Manipulation
      1. 12.1 What Is Bit Data, Anyway?
      2. 12.2 Instructions That Manipulate Bits
        1. 12.2.1 The and Instruction
        2. 12.2.2 The or Instruction
        3. 12.2.3 The xor Instruction
        4. 12.2.4 Flag Modification by Logical Instructions
        5. 12.2.5 The Bit Test Instructions
        6. 12.2.6 Manipulating Bits with Shift and Rotate Instructions
      3. 12.3 The Carry Flag as a Bit Accumulator
      4. 12.4 Packing and Unpacking Bit Strings
      5. 12.5 BMI1 Instructions to Extract Bits and Create Bit Masks
      6. 12.6 Coalescing Bit Sets and Distributing Bit Strings
      7. 12.7 Coalescing and Distributing Bit Strings Using BMI2 Instructions
      8. 12.8 Packed Arrays of Bit Strings
      9. 12.9 Searching for a Bit
      10. 12.10 Counting Bits
      11. 12.11 Reversing a Bit String
      12. 12.12 Merging Bit Strings
      13. 12.13 Extracting Bit Strings
      14. 12.14 Searching for a Bit Pattern
      15. 12.15 For More Information
      16. 12.16 Test Yourself
    9. Chapter 13: Macros and the MASM Compile-Time Language
      1. 13.2 The echo and .err Directives
      2. 13.3 Compile-Time Constants and Variables
      3. 13.4 Compile-Time Expressions and Operators
        1. 13.4.1 The MASM Escape (!) Operator
        2. 13.4.2 The MASM Evaluation (%) Operator
        3. 13.4.3 The catstr Directive
        4. 13.4.4 The instr Directive
        5. 13.4.5 The sizestr Directive
        6. 13.4.6 The substr Directive
      4. 13.5 Conditional Assembly (Compile-Time Decisions)
      5. 13.6 Repetitive Assembly (Compile-Time Loops)
      6. 13.7 Macros (Compile-Time Procedures)
      7. 13.8 Standard Macros
      8. 13.9 Macro Parameters
        1. 13.9.1 Standard Macro Parameter Expansion
        2. 13.9.2 Optional and Required Macro Parameters
        3. 13.9.3 Default Macro Parameter Values
        4. 13.9.4 Macros with a Variable Number of Parameters
        5. 13.9.5 The Macro Expansion (&) Operator
      9. 13.10 Local Symbols in a Macro
      10. 13.11 The exitm Directive
      11. 13.12 MASM Macro Function Syntax
      12. 13.13 Macros as Compile-Time Procedures and Functions
      13. 13.14 Writing Compile-Time “Programs”
        1. 13.14.1 Constructing Data Tables at Compile Time
        2. 13.14.2 Unrolling Loops
      14. 13.15 Simulating HLL Procedure Calls
        1. 13.15.1 HLL-Like Calls with No Parameters
        2. 13.15.2 HLL-Like Calls with One Parameter
        3. 13.15.3 Using opattr to Determine Argument Types
        4. 13.15.4 HLL-Like Calls with a Fixed Number of Parameters
        5. 13.15.5 HLL-Like Calls with a Varying Parameter List
      15. 13.16 The invoke Macro
      16. 13.17 Advanced Macro Parameter Parsing
        1. 13.17.1 Checking for String Literal Constants
        2. 13.17.2 Checking for Real Constants
        3. 13.17.3 Checking for Registers
        4. 13.17.4 Compile-Time Arrays
      17. 13.18 Using Macros to Write Macros
      18. 13.19 Compile-Time Program Performance
      19. 13.20 For More Information
      20. 13.21 Test Yourself
    10. Chapter 14: The String Instructions
      1. 14.1 The x86-64 String Instructions
        1. 14.1.1 The rep, repe, repz, and the repnz and repne Prefixes
        2. 14.1.2 The Direction Flag
        3. 14.1.3 The movs Instruction
        4. 14.1.4 The cmps Instruction
        5. 14.1.5 The scas Instruction
        6. 14.1.6 The stos Instruction
        7. 14.1.7 The lods Instruction
        8. 14.1.8 Building Complex String Functions from lods and stos
      2. 14.2 Performance of the x86-64 String Instructions
      3. 14.3 SIMD String Instructions
        1. 14.3.1 Packed Compare Operand Sizes
        2. 14.3.2 Type of Comparison
        3. 14.3.3 Result Polarity
        4. 14.3.4 Output Processing
        5. 14.3.5 Packed String Compare Lengths
        6. 14.3.6 Packed String Comparison Results
      4. 14.4 Alignment and Memory Management Unit Pages
      5. 14.5 For More Information
      6. 14.6 Test Yourself
    11. Chapter 15: Managing Complex Projects
      1. 15.1 The include Directive
      2. 15.2 Ignoring Duplicate Include Operations
      3. 15.3 Assembly Units and External Directives
      4. 15.4 Header Files in MASM
      5. 15.5 The externdef Directive
      6. 15.6 Separate Compilation
        1. 15.7.1 Basic Makefile Syntax
        2. 15.7.2 Make Dependencies
        3. 15.7.3 Make Clean and Touch
      7. 15.8 The Microsoft Linker and Library Code
      8. 15.9 Object File and Library Impact on Program Size
      9. 15.10 For More Information
      10. 15.11 Test Yourself
    12. Chapter 16: Stand-Alone Assembly Language Programs
      1. 16.1 Hello World, by Itself
      2. 16.2 Header Files and the Windows Interface
      3. 16.3 The Win32 API and the Windows ABI
      4. 16.4 Building a Stand-Alone Console Application
      5. 16.5 Building a Stand-Alone GUI Application
      6. 16.6 A Brief Look at the MessageBox Windows API Function
      7. 16.7 Windows File I/O
      8. 16.8 Windows Applications
      9. 16.9 For More Information
      10. 16.10 Test Yourself
  10. Part III: Reference Material
    1. Appendix A: ASCII Character Set
    2. Appendix B: Glossary
    3. Appendix C: Installing and Using Visual Studio
      1. C.1 Installing Visual Studio Community
      2. C.2 Creating a Command Line Prompt for MASM
      3. C.3 Editing, Assembling, and Running a MASM Source File
    4. Appendix D: The Windows Command Line Interpreter
      1. D.1 Command Line Syntax
      2. D.2 Directory Names and Drive Letters
      3. D.3 Some Useful Built-in Commands
        1. D.3.1 The cd and chdir Commands
        2. D.3.2 The cls Command
        3. D.3.3 The copy Command
        4. D.3.4 The date Command
        5. D.3.5 The del (erase) Command
        6. D.3.6 The dir Command
        7. D.3.7 The more Command
        8. D.3.8 The move Command
        9. D.3.9 The ren and rename Commands
        10. D.3.10 The rd and rmdir Commands
        11. D.3.11 The time Command
      4. D.4 For More Information
    5. Appendix E: Answers to Questions
      1. E.1 Answers to Questions in Chapter 1
      2. E.2 Answers to Questions in Chapter 2
      3. E.3 Answers to Questions in Chapter 3
      4. E.4 Answers to Questions in Chapter 4
      5. E.5 Answers to Questions in Chapter 5
      6. E.6 Answers to Questions in Chapter 6
      7. E.7 Answers to Questions in Chapter 7
      8. E.8 Answers to Questions in Chapter 8
      9. E.9 Answers to Questions in Chapter 9
      10. E.10 Answers to Questions in Chapter 10
      11. E.11 Answers to Questions in Chapter 11
      12. E.12 Answers to Questions in Chapter 12
      13. E.13 Answers to Questions in Chapter 13
      14. E.14 Answers to Questions in Chapter 14
      15. E.15 Answers to Questions in Chapter 15
      16. E.16 Answers to Questions in Chapter 16
  11. Index

List of Tables

  1. Table 1-1: General-Purpose Registers on the x86-64
  2. Table 1-2: MASM Data Declaration Directives
  3. Table 1-3: Variable Address Assignment
  4. Table 1-4: MASM Data Types
  5. Table 1-5: Legal x86-64 mov Instruction Operands
  6. Table 1-6: C++ and Assembly Language Types
  7. Table 2-1: Binary/Hexadecimal Conversion
  8. Table 2-2: AND Truth Table
  9. Table 2-3: OR Truth Table
  10. Table 2-4: XOR Truth Table
  11. Table 2-5: NOT Truth Table
  12. Table 2-6: Sign Extension
  13. Table 2-7: Zero Extension
  14. Table 2-8: Conditional Jump Instructions That Test the Condition Code Flags
  15. Table 2-9: Flag Settings After Executing add or sub
  16. Table 2-10: Conditional Jump Instructions for Use After a cmp Instruction
  17. Table 2-11: Conditional Jump Synonyms
  18. Table 2-12: Instructions That Affect Certain Flags
  19. Table 2-13: ASCII Groups
  20. Table 2-14: ASCII Codes for Numeric Digits
  21. Table 2-15: UTF-8 Encoding
  22. Table 3-1: Word Object Little- and Big-Endian Data Organizations
  23. Table 3-2: Double-Word Object Little- and Big-Endian Data Organizations
  24. Table 3-3: Quad-Word Object Little- and Big-Endian Data Organizations
  25. Table 4-1: Operations Allowed in Constant Expressions
  26. Table 4-2: MASM Type-Coercion Operators
  27. Table 5-1: Parameter Location by Size
  28. Table 5-2: FASTCALL Parameter Locations
  29. Table 5-3: Register Volatility
  30. Table 6-1: Instructions for Extending AL, AX, EAX, and RAX
  31. Table 6-2: mul and imul Operations
  32. Table 6-3: Condition Code Settings After cmp
  33. Table 6-4: Sign and Overflow Flag Settings After Subtraction
  34. Table 6-5: setcc Instructions That Test Flags
  35. Table 6-6: setcc Instructions for Unsigned Comparisons
  36. Table 6-7: setcc Instructions for Signed Comparisons
  37. Table 6-8: Common Commutative Binary Operators
  38. Table 6-9: Common Noncommutative Binary Operators
  39. Table 6-10: Rounding Control
  40. Table 6-11: Mantissa Precision-Control Bits
  41. Table 6-12: FPU Comparison Condition Code Bits (X = “Don’t care”)
  42. Table 6-13: FPU Condition Code Bits (X = “Don’t care”)
  43. Table 6-14: Infix-to-Postfix Translation
  44. Table 6-15: More-Complex Infix-to-Postfix Translations
  45. Table 6-16: SSE MXCSR Register
  46. Table 6-17: SSE Compare Immediate Operand
  47. Table 6-18: SSE Conversion Instructions
  48. Table 7-1: jcc Instructions That Test Flags
  49. Table 7-2: jcc Instructions for Unsigned Comparisons
  50. Table 7-3: jcc Instructions for Signed Comparisons
  51. Table 7-4: cmovcc Instructions That Test Flags
  52. Table 7-5: cmovcc Instructions for Unsigned Comparisons
  53. Table 7-6: cmovcc Instructions for Signed Comparisons
  54. Table 8-1: Binary-Coded Decimal Representation
  55. Table 11-1: Intel cpuid Feature Flags (EAX = 1)
  56. Table 11-2: Intel cpuid Extended Feature Flags (EAX = 7, ECX = 0)
  57. Table 11-3: (v)pshufd imm8 Operand Values
  58. Table 11-4: Double-Word Transfers for vpshufd YMMdest, YMMsrc/memsrc, imm8
  59. Table 11-5: vshufps Destination Selection
  60. Table 11-6: vshufpd Destination Selection
  61. Table 11-7: Integer Unpack Instructions
  62. Table 11-8: AVX Integer Unpack Instructions
  63. Table 11-9: imm8 Bit Fields for insertps and vinsertps Instructions
  64. Table 11-10: SSE/AVX Logical Instructions
  65. Table 11-11: SIMD Integer Addition Instructions
  66. Table 11-12: SIMD Integer Saturation Addition Instructions
  67. Table 11-13: Horizontal Addition Instructions
  68. Table 11-14: SIMD Integer Subtraction Instructions
  69. Table 11-15: SIMD Integer Saturating Subtraction Instructions
  70. Table 11-16: SIMD 16-Bit Packed Integer Multiplication Instructions
  71. Table 11-17: SIMD 32- and 64-Bit Packed Integer Multiplication Instructions
  72. Table 11-18: imm8 Operand Values for pclmulqdq Instruction
  73. Table 11-19: imm8 Operand Values for vpclmulqdq Instruction
  74. Table 11-20: SIMD Minimum and Maximum Instructions
  75. Table 11-21: SSE4.1 and AVX Packed Zero-Extension Instructions
  76. Table 11-22: AVX2 Packed Zero-Extension Instructions
  77. Table 11-23: SSE Packed Sign-Extension Instructions
  78. Table 11-24: AVX Packed Sign-Extension Instructions
  79. Table 11-25: SSE Packed Sign-Extension with Saturation Instructions
  80. Table 11-26: AVX Packed Sign-Extension with Saturation Instructions
  81. Table 11-27: Floating-Point Arithmetic Instructions
  82. Table 11-28: imm8 Values for cmpps and cmppd Instructions†
  83. Table 11-29: Synonyms for Common Packed Floating-Point Comparisons
  84. Table 11-30: AVX Packed Compare Instructions
  85. Table 11-31: SSE Conversion Instructions
  86. Table 13-1: Text-Handling Conditional if Statements
  87. Table 13-2: opattr Return Values
  88. Table 13-3: 8-Bit Values for opattr Results
  89. Table 14-1: Packed Compare imm8 Bits 0 and 1
  90. Table 14-2: Packed Compare imm8 Bits 2 and 3
  91. Table 14-3: Packed Compare imm8 Bits 4 and 5
  92. Table 14-4: Packed Compare imm8 Bit 6 (and 7)
  93. Table 14-5: Comparison Result When Source 1 and Source 2 Are Valid or Invalid

List of Illustrations

  1. Figure 1-1: Von Neumann computer system block diagram
  2. Figure 1-2: Layout of the FLAGS register (lower 16 bits of RFLAGS)
  3. Figure 1-3: Memory write operation
  4. Figure 1-4: Memory read operation
  5. Figure 1-5: Byte, word, and double-word storage in memory
  6. Figure 2-1: Bit numbering
  7. Figure 2-2: The two nibbles in a byte
  8. Figure 2-3: Bit numbers in a word
  9. Figure 2-4: The 2 bytes in a word
  10. Figure 2-5: Nibbles in a word
  11. Figure 2-6: Bit numbers in a double word
  12. Figure 2-7: Nibbles, bytes, and words in a double word
  13. Figure 2-8: Shift-left operation
  14. Figure 2-9: shl by 1 operation
  15. Figure 2-10: Shift-right operation
  16. Figure 2-11: shr by 1 operation
  17. Figure 2-12: Arithmetic shift-right operation
  18. Figure 2-13: sar dest, 1 operation
  19. Figure 2-14: Rotate-left and rotate-right operations
  20. Figure 2-15: rol dest, 1 operation
  21. Figure 2-16: ror dest, 1 operation
  22. Figure 2-17: rcl dest, 1 and rcr dest, 1 operations
  23. Figure 2-18: Short packed date format (2 bytes)
  24. Figure 2-19: Long packed date format (4 bytes)
  25. Figure 2-20: FLAGS register as packed Boolean data
  26. Figure 2-21: Single-precision (32-bit) floating-point format
  27. Figure 2-22: 64-bit double-precision floating-point format
  28. Figure 2-23: 80-bit extended-precision floating-point format
  29. Figure 2-24: BCD data representation in memory
  30. Figure 2-25: ASCII codes for E and e
  31. Figure 2-26: Surrogate code point encoding for Unicode planes 1 to 16
  32. Figure 3-1: MASM typical runtime memory organization
  33. Figure 3-2: Word access at the end of an MMU page
  34. Figure 3-3: Address and data bus for 16-bit processors
  35. Figure 3-4: Reading a byte from an even address on a 16-bit CPU
  36. Figure 3-5: Reading a byte from an odd address on a 16-bit CPU
  37. Figure 3-6: Accessing a word on a 32-bit data bus
  38. Figure 3-7: PC-relative addressing mode
  39. Figure 3-8: Accessing a word or dword by using the PC-relative addressing mode
  40. Figure 3-9: Indirect-plus-offset addressing mode
  41. Figure 3-10: Scaled-indexed addressing mode
  42. Figure 3-11: Base address form of indirect-plus-offset addressing mode
  43. Figure 3-12: Small address plus constant form of indirect-plus-offset addressing mode
  44. Figure 3-13: Small address form of base-plus-scaled-indexed addressing mode
  45. Figure 3-14: Small address form of base-plus-scaled-indexed-plus-constant addressing mode
  46. Figure 3-15: Small address form of scaled-indexed addressing mode
  47. Figure 3-16: Small address form of scaled-indexed-plus-constant addressing mode
  48. Figure 3-17: Using an address expression to access data beyond a variable
  49. Figure 3-18: Stack segment before the push rax operation
  50. Figure 3-19: Stack segment after the push rax operation
  51. Figure 3-20: Memory before a pop rax operation
  52. Figure 3-21: Memory after the pop rax operation
  53. Figure 3-22: Stack after pushing RAX
  54. Figure 3-23: Stack after pushing RBX
  55. Figure 3-24: Stack after popping RAX
  56. Figure 3-25: Stack after popping RBX
  57. Figure 3-26: Removing data from the stack, before add rsp, 16
  58. Figure 3-27: Removing data from the stack, after add rsp, 16
  59. Figure 3-28: Stack after pushing RAX and RBX
  60. Figure 4-1: Array layout in memory
  61. Figure 4-2: Mapping a 4×4 array to sequential memory locations
  62. Figure 4-3: Row-major array element ordering
  63. Figure 4-4: Another view of row-major ordering for a 4×4 array
  64. Figure 4-5: Viewing a 4×4 array as an array of arrays
  65. Figure 4-6: Column-major array element ordering
  66. Figure 4-7: Student data structure storage in memory
  67. Figure 4-8: Layout of a union versus a struct variable
  68. Figure 5-1: Stack contents before ret in the MessedUp procedure
  69. Figure 5-2: Stack contents before ret in MessedUp2
  70. Figure 5-3: Stack organization immediately upon entry into ARDemo
  71. Figure 5-4: Activation record for ARDemo
  72. Figure 5-5: Offsets of objects in the ARDemo activation record
  73. Figure 5-6: Activation record for the LocalVars procedure
  74. Figure 5-7: Stack layout upon entry into CallProc
  75. Figure 5-8: Activation record for CallProc after standard entry sequence execution
  76. Figure 6-1: A floating-point format
  77. Figure 6-2: FPU floating-point register stack
  78. Figure 6-3: FPU control register
  79. Figure 6-4: The FPU status register
  80. Figure 6-5: FPU floating-point formats
  81. Figure 6-6: FPU integer formats
  82. Figure 6-7: FPU packed decimal format
  83. Figure 7-1: if/then/else/endif and if/then/endif statement flow
  84. Figure 7-2: continue destination for the for(;;) loop
  85. Figure 7-3: continue destination and the while loop
  86. Figure 7-4: continue destination and the for loop
  87. Figure 7-5: continue destination and the repeat/until loop
  88. Figure 8-1: Multi-digit addition
  89. Figure 8-2: Adding two 192-bit objects together
  90. Figure 8-3: Multi-digit multiplication
  91. Figure 8-4: Extended-precision multiplication
  92. Figure 8-5: Manual digit-by-digit division operation
  93. Figure 8-6: Longhand division in binary
  94. Figure 8-7: 128-bit shift-left operation
  95. Figure 8-8: shld operation
  96. Figure 8-9: shrd operation
  97. Figure 11-1: Packed and scalar single-precision floating-point data type
  98. Figure 11-2: Packed and scalar double-precision floating-point type
  99. Figure 11-3: Packed byte data type
  100. Figure 11-4: Packed word data type
  101. Figure 11-5: Packed double-word data type
  102. Figure 11-6: Packed quad-word data type
  103. Figure 11-7: Moving a 32-bit value from memory to an XMM register (with zero extension)
  104. Figure 11-8: Moving a 64-bit value from memory to an XMM register (with zero extension)
  105. Figure 11-9: movlps instruction
  106. Figure 11-10: vmovlps instruction
  107. Figure 11-11: movhps instruction
  108. Figure 11-12: movhpd instruction
  109. Figure 11-13: vmovhpd and vmovhps instructions
  110. Figure 11-14: movshdup and vmovshdup instructions
  111. Figure 11-15: movsldup and vmovsldup instructions
  112. Figure 11-16: movddup instruction behavior
  113. Figure 11-17: vmovddup instruction behavior
  114. Figure 11-18: Register aliasing at the microarchitectural level
  115. Figure 11-19: Lane index correspondence for pshufb instruction
  116. Figure 11-20: phsufb byte index
  117. Figure 11-21: Shuffle operation
  118. Figure 11-22: (v)pshuflw xmm, xmm/mem, imm8 operation
  119. Figure 11-23: vpshuflw ymm, ymm/mem, imm8 operation
  120. Figure 11-24: (v)pshufhw operation
  121. Figure 11-25: vpshufhw operation
  122. Figure 11-26: shufps operation
  123. Figure 11-27: shufpd operation
  124. Figure 11-28: unpcklps instruction operation
  125. Figure 11-29: unpckhps instruction operation
  126. Figure 11-30: unpcklpd instruction operation
  127. Figure 11-31: unpckhpd instruction operation
  128. Figure 11-32: vunpcklps instruction operation
  129. Figure 11-33: vunpckhps instruction operation
  130. Figure 11-34: punpcklbw instruction operation
  131. Figure 11-35: punpckhbw operation
  132. Figure 11-36: punpcklwd operation
  133. Figure 11-37: punpckhwd operation
  134. Figure 11-38: punpckldq operation
  135. Figure 11-39: punpckhdq operation
  136. Figure 11-40: punpcklqdq operation
  137. Figure 11-41: punpckhqdq operation
  138. Figure 11-42: SIMD concurrent arithmetic and logical operations
  139. Figure 11-43: Horizontal addition operation
  140. Figure 11-44: Merging bits from pcmpeqw
  141. Figure 11-45: movmskps operation
  142. Figure 11-46: movmskpd operation
  143. Figure 11-47: vmovmskps operation
  144. Figure 11-48: vmovmskpd operation
  145. Figure 12-1: Isolating a bit string by using the and instruction
  146. Figure 12-2: Inserting bits 0 to 12 of EAX into bits 12 to 24 of EBX
  147. Figure 12-3: Inserting a bit string into a destination operand
  148. Figure 12-4: Bit mask for pext instruction
  149. Figure 12-5: pdep instruction operation
  150. Figure 13-1: Compile-time versus runtime execution
  151. Figure 13-2: Operation of a MASM compile-time if statement
  152. Figure 13-3: MASM compile-time while statement operation
  153. Figure 14-1: Copying data between two overlapping arrays (forward direction)
  154. Figure 14-2: Using a backward copy to copy data in overlapping arrays
  155. Figure 14-3: Equal each aggregate comparison operation
  156. Figure 16-1: Sample dialog box output

List of Listings

  1. Listing 1-1: Trivial shell program
  2. Listing 1-2: A sample C/C++ program, listing1-2.cpp, that calls an assembly language function
  3. Listing 1-3: A MASM program, listing1-3.asm, that the C++ program in Listing 1-2 calls
  4. Listing 1-4: A sample user-defined procedure in an assembly language program
  5. Listing 1-5: Assembly language code for the “Hello, world!” program
  6. Listing 1-6: C++ code for the “Hello, world!” program
  7. Listing 1-7: Generic C++ code for calling assembly language programs
  8. Listing 1-8: Assembly language program that returns a function result
  9. Listing 1-9: Output sizes of common C++ data types
  10. Listing 2-1: Decimal-to-hexadecimal conversion program
  11. Listing 2-2: and, or, xor, and not example
  12. Listing 2-3: Two’s complement example
  13. Listing 2-4: Packing and unpacking date data
  14. Listing 3-1: Demonstration of address expressions
  15. Listing 4-1: MASM type checking
  16. Listing 4-2: Pointer constant expressions in a MASM program
  17. Listing 4-3: Demonstration of malloc() and free() calls
  18. Listing 4-4: Uninitialized pointer demonstration
  19. Listing 4-5: Type-unsafe pointer access example
  20. Listing 4-6: Calling C Standard Library string function from MASM source code
  21. Listing 4-7: A simple bubble sort example
  22. Listing 4-8: Initializing the fields of a structure
  23. Listing 5-1: Example of a simple procedure
  24. Listing 5-2: Effect of a missing ret instruction in a procedure
  25. Listing 5-3: Program with an unintended infinite loop
  26. Listing 5-4: Demonstration of caller register preservation
  27. Listing 5-5: Effect of popping too much data off the stack
  28. Listing 5-6: Sample procedure that accesses local variables
  29. Listing 5-7: Local variables using equates
  30. Listing 5-8: Using the offset operator to obtain the address of a static variable
  31. Listing 5-9: Obtaining the address of a variable using the lea instruction
  32. Listing 5-10: Passing parameters in registers to the strfill procedure
  33. Listing 5-11: Print procedure implementation (using code stream parameters)
  34. Listing 5-12: Demonstration of value parameters
  35. Listing 5-13: Accessing a reference parameter
  36. Listing 5-14: Passing an array of records by referencing
  37. Listing 5-15: Recursive quicksort program
  38. Listing 6-1: Demonstration of fadd instructions
  39. Listing 6-2: Demonstration of the fsub instructions
  40. Listing 6-3: Demonstration of the fmul instruction
  41. Listing 6-4: Demonstration of the fdiv/fdivr instructions
  42. Listing 6-5: Program that demonstrates the fcom instructions
  43. Listing 6-6: Sample program demonstrating floating-point comparisons
  44. Listing 7-1: Demonstration of lexically scoped symbols
  45. Listing 7-2: The option scoped and option noscoped directives
  46. Listing 7-3: Initializing qword variables with the address of statement labels
  47. Listing 7-4: Using register-indirect jmp instructions
  48. Listing 7-5: Using memory-indirect jmp instructions
  49. Listing 7-6: A state machine example
  50. Listing 7-7: A state machine using an indirect jump
  51. Listing 8-1: Extended-precision multiplication
  52. Listing 8-2: Unsigned 128 / 32-bit extended-precision division
  53. Listing 8-3: Extended-precision division
  54. Listing 9-1: A function that converts a byte to two hexadecimal characters
  55. Listing 9-2: btoStr, wtoStr, dtoStr, and qtoStr functions
  56. Listing 9-3: Faster implementation of qtoStr
  57. Listing 9-4: Unsigned integer-to-string function (recursive)
  58. Listing 9-5: A fist and fbstp-based utoStr function
  59. Listing 9-6: Signed integer-to-string conversion
  60. Listing 9-7: 128-bit extended-precision decimal output routine
  61. Listing 9-8: 128-bit signed integer-to-string conversion
  62. Listing 9-9: Formatted integer-to-string conversion functions
  63. Listing 9-10: Floating-point mantissa-to-string conversion
  64. Listing 9-11: r10ToStr conversion function
  65. Listing 9-12: Exponent conversion function
  66. Listing 9-13: e10ToStr conversion function
  67. Listing 9-14: Numeric-to-string conversions
  68. Listing 9-15: Hexadecimal string-to-numeric conversion
  69. Listing 9-16: 128-bit hexadecimal string-to-numeric conversion
  70. Listing 9-17: Unsigned decimal string-to-numeric conversion
  71. Listing 9-18: Extended-precision unsigned decimal input
  72. Listing 9-19: A strToR10 function
  73. Listing 10-1: A C program that generates a table of sines
  74. Listing 11-1: cpuid demonstration program
  75. Listing 11-2: Test for BMI1 and BMI2 instruction sets
  76. Listing 11-3: Aligned memory-access timing code
  77. Listing 11-4: Unaligned memory-access timing code
  78. Listing 11-5: Dynamically selected print procedure
  79. Listing 12-1: Inserting bits where the bit string length and starting position are variables
  80. Listing 12-2: bextr instruction example
  81. Listing 12-3: Simple demonstration of the blsi instruction
  82. Listing 12-4: Extracting and removing the lowest set bit in an operand
  83. Listing 12-5: blsr instruction example
  84. Listing 12-6: blsmsk example
  85. Listing 12-7: Creating a bit mask that doesn’t include the lowest-numbered set bit
  86. Listing 12-8: pext instruction example
  87. Listing 12-9: pdep instruction example
  88. Listing 12-10: Storing the value 7 (111b) into an array of 3-bit elements
  89. Listing 13-1: The CTL “Hello, world!” program
  90. Listing 13-2: while..endm demonstration
  91. Listing 13-3: Program equivalent to the code in Listing 13-2
  92. Listing 13-4: Sample macro function
  93. Listing 13-5: Generating case-conversion tables with the compile-time language
  94. Listing 13-6: opattr operator in a macro
  95. Listing 13-7: Macro call implementation for converting floating-point values to strings
  96. Listing 13-8: Varying arguments’ implementation of print macro
  97. Listing 13-9: Compile-time program with test code for getReal macro
  98. Listing 13-12: putInt macro function test program
  99. Listing 13-13: A macro that writes another pair of macros
  100. Listing 15-1: aoalib.inc header file
  101. Listing 15-2: The print function appearing in an assembly unit
  102. Listing 15-3: The getTitle function as an assembly unit
  103. Listing 15-4: A main program that uses the print and getTitle assembly modules
  104. Listing 15-5: Makefile to build Listing 15-4
  105. Listing 15-6: A clean target example
  106. Listing 16-1: Stand-alone “Hello, world!” program
  107. Listing 16-2: Using the MASM32 64-bit include files
  108. Listing 16-3: A simple dialog box application
  109. Listing 16-4: File I/O demonstration program

Guide

  1. Cover
  2. Front Matter
  3. Dedication
  4. Foreword
  5. Introduction
  6. Part I: Machine ORganization
  7. Chapter 1: Hello, World of Assembly Language
  8. Start Reading
  9. Chapter 2: Computer Data Representation and Operations
  10. Chapter 3: Memory Access and Organization
  11. Chapter 4: Constants, Variables, and Data Types
  12. Part II: Assembly Language Programming
  13. Chapter 5: Procedures
  14. Chapter 6: Arithmetic
  15. Chapter 7: Low-Level Control Structures
  16. Chapter 8: Advanced Arithmetic
  17. Chapter 9: Numeric Conversion
  18. Chapter 10: Table Lookups
  19. Chapter 11: SIMD Instructions
  20. Chapter 12: Bit Manipulation
  21. Chapter 13: Macros and the MASM Compile-Time Language
  22. Chapter 14: The String Instructions
  23. Chapter 15: Managing Complex Projects
  24. Chapter 16: Stand-Alone Assembly Language Programs
  25. Part III: Reference material
  26. Appendix A: ASCII Character Set
  27. Appendix B: Glossary
  28. Appendix C: Installing and Using Visual Studio
  29. Appendix D: The Windows Command Line Interpreter
  30. Appendix E: Answers to Questions
  31. Index

Pages

  1. iii
  2. iv
  3. v
  4. vii
  5. xxiii
  6. xxiv
  7. xxv
  8. xxvii
  9. xxviii
  10. xxix
  11. xxx
  12. 1
  13. 3
  14. 4
  15. 5
  16. 6
  17. 7
  18. 8
  19. 9
  20. 10
  21. 11
  22. 12
  23. 13
  24. 14
  25. 15
  26. 16
  27. 17
  28. 18
  29. 19
  30. 20
  31. 21
  32. 22
  33. 23
  34. 24
  35. 25
  36. 26
  37. 27
  38. 28
  39. 29
  40. 30
  41. 31
  42. 32
  43. 33
  44. 34
  45. 35
  46. 36
  47. 37
  48. 38
  49. 39
  50. 40
  51. 41
  52. 43
  53. 44
  54. 45
  55. 46
  56. 47
  57. 48
  58. 49
  59. 50
  60. 51
  61. 52
  62. 53
  63. 54
  64. 55
  65. 56
  66. 57
  67. 58
  68. 59
  69. 60
  70. 61
  71. 62
  72. 63
  73. 64
  74. 65
  75. 66
  76. 67
  77. 68
  78. 69
  79. 70
  80. 71
  81. 72
  82. 73
  83. 74
  84. 75
  85. 76
  86. 77
  87. 78
  88. 79
  89. 80
  90. 81
  91. 82
  92. 83
  93. 84
  94. 85
  95. 86
  96. 87
  97. 88
  98. 89
  99. 90
  100. 91
  101. 92
  102. 93
  103. 94
  104. 95
  105. 96
  106. 97
  107. 98
  108. 99
  109. 100
  110. 101
  111. 102
  112. 103
  113. 105
  114. 106
  115. 107
  116. 108
  117. 109
  118. 110
  119. 111
  120. 112
  121. 113
  122. 114
  123. 115
  124. 116
  125. 117
  126. 118
  127. 119
  128. 120
  129. 121
  130. 122
  131. 123
  132. 124
  133. 125
  134. 126
  135. 127
  136. 128
  137. 129
  138. 130
  139. 131
  140. 132
  141. 133
  142. 134
  143. 135
  144. 136
  145. 137
  146. 138
  147. 139
  148. 140
  149. 141
  150. 142
  151. 143
  152. 144
  153. 145
  154. 146
  155. 147
  156. 148
  157. 149
  158. 150
  159. 151
  160. 152
  161. 153
  162. 154
  163. 155
  164. 156
  165. 157
  166. 158
  167. 159
  168. 160
  169. 161
  170. 162
  171. 163
  172. 164
  173. 165
  174. 166
  175. 167
  176. 168
  177. 169
  178. 170
  179. 171
  180. 172
  181. 173
  182. 174
  183. 175
  184. 176
  185. 177
  186. 178
  187. 179
  188. 180
  189. 181
  190. 182
  191. 183
  192. 184
  193. 185
  194. 186
  195. 187
  196. 188
  197. 189
  198. 190
  199. 191
  200. 192
  201. 193
  202. 194
  203. 195
  204. 196
  205. 197
  206. 198
  207. 199
  208. 200
  209. 201
  210. 202
  211. 203
  212. 204
  213. 205
  214. 206
  215. 207
  216. 208
  217. 209
  218. 210
  219. 211
  220. 212
  221. 213
  222. 215
  223. 216
  224. 217
  225. 218
  226. 219
  227. 220
  228. 221
  229. 222
  230. 223
  231. 224
  232. 225
  233. 226
  234. 227
  235. 228
  236. 229
  237. 230
  238. 231
  239. 232
  240. 233
  241. 234
  242. 235
  243. 236
  244. 237
  245. 238
  246. 239
  247. 240
  248. 241
  249. 242
  250. 243
  251. 244
  252. 245
  253. 246
  254. 247
  255. 248
  256. 249
  257. 250
  258. 251
  259. 252
  260. 253
  261. 254
  262. 255
  263. 256
  264. 257
  265. 258
  266. 259
  267. 260
  268. 261
  269. 262
  270. 263
  271. 264
  272. 265
  273. 266
  274. 267
  275. 268
  276. 269
  277. 270
  278. 271
  279. 272
  280. 273
  281. 274
  282. 275
  283. 276
  284. 277
  285. 278
  286. 279
  287. 280
  288. 281
  289. 282
  290. 283
  291. 284
  292. 285
  293. 286
  294. 287
  295. 288
  296. 289
  297. 290
  298. 291
  299. 292
  300. 293
  301. 294
  302. 295
  303. 296
  304. 297
  305. 298
  306. 299
  307. 300
  308. 301
  309. 302
  310. 303
  311. 304
  312. 305
  313. 306
  314. 307
  315. 308
  316. 309
  317. 310
  318. 311
  319. 312
  320. 313
  321. 314
  322. 315
  323. 316
  324. 317
  325. 318
  326. 319
  327. 320
  328. 321
  329. 322
  330. 323
  331. 324
  332. 325
  333. 326
  334. 327
  335. 328
  336. 329
  337. 330
  338. 331
  339. 332
  340. 333
  341. 334
  342. 335
  343. 336
  344. 337
  345. 338
  346. 339
  347. 340
  348. 341
  349. 342
  350. 343
  351. 344
  352. 345
  353. 346
  354. 347
  355. 348
  356. 349
  357. 350
  358. 351
  359. 352
  360. 353
  361. 354
  362. 355
  363. 356
  364. 357
  365. 358
  366. 359
  367. 360
  368. 361
  369. 362
  370. 363
  371. 364
  372. 365
  373. 366
  374. 367
  375. 368
  376. 369
  377. 370
  378. 371
  379. 372
  380. 373
  381. 374
  382. 375
  383. 376
  384. 377
  385. 378
  386. 379
  387. 380
  388. 381
  389. 382
  390. 383
  391. 384
  392. 385
  393. 386
  394. 387
  395. 388
  396. 389
  397. 390
  398. 391
  399. 392
  400. 393
  401. 394
  402. 395
  403. 396
  404. 397
  405. 398
  406. 399
  407. 400
  408. 401
  409. 402
  410. 403
  411. 404
  412. 405
  413. 406
  414. 407
  415. 408
  416. 409
  417. 410
  418. 411
  419. 412
  420. 413
  421. 414
  422. 415
  423. 416
  424. 417
  425. 418
  426. 419
  427. 420
  428. 421
  429. 422
  430. 423
  431. 424
  432. 425
  433. 426
  434. 427
  435. 428
  436. 429
  437. 430
  438. 431
  439. 432
  440. 433
  441. 434
  442. 435
  443. 436
  444. 437
  445. 438
  446. 439
  447. 440
  448. 441
  449. 442
  450. 443
  451. 444
  452. 445
  453. 446
  454. 447
  455. 448
  456. 449
  457. 450
  458. 451
  459. 452
  460. 453
  461. 454
  462. 455
  463. 456
  464. 457
  465. 458
  466. 459
  467. 460
  468. 461
  469. 462
  470. 463
  471. 464
  472. 465
  473. 466
  474. 467
  475. 468
  476. 469
  477. 470
  478. 471
  479. 472
  480. 473
  481. 474
  482. 475
  483. 476
  484. 477
  485. 478
  486. 479
  487. 480
  488. 481
  489. 482
  490. 483
  491. 484
  492. 485
  493. 486
  494. 487
  495. 488
  496. 489
  497. 490
  498. 491
  499. 492
  500. 493
  501. 494
  502. 495
  503. 496
  504. 497
  505. 498
  506. 499
  507. 500
  508. 501
  509. 502
  510. 503
  511. 504
  512. 505
  513. 506
  514. 507
  515. 508
  516. 509
  517. 510
  518. 511
  519. 512
  520. 513
  521. 514
  522. 515
  523. 516
  524. 517
  525. 518
  526. 519
  527. 520
  528. 521
  529. 522
  530. 523
  531. 524
  532. 525
  533. 526
  534. 527
  535. 528
  536. 529
  537. 530
  538. 531
  539. 532
  540. 533
  541. 534
  542. 535
  543. 536
  544. 537
  545. 538
  546. 539
  547. 540
  548. 541
  549. 542
  550. 543
  551. 544
  552. 545
  553. 546
  554. 547
  555. 548
  556. 549
  557. 550
  558. 551
  559. 552
  560. 553
  561. 554
  562. 555
  563. 556
  564. 557
  565. 558
  566. 559
  567. 560
  568. 561
  569. 562
  570. 563
  571. 564
  572. 565
  573. 566
  574. 567
  575. 568
  576. 569
  577. 570
  578. 571
  579. 572
  580. 573
  581. 574
  582. 575
  583. 576
  584. 577
  585. 578
  586. 579
  587. 580
  588. 581
  589. 583
  590. 584
  591. 585
  592. 586
  593. 587
  594. 588
  595. 589
  596. 590
  597. 591
  598. 592
  599. 593
  600. 595
  601. 596
  602. 597
  603. 598
  604. 599
  605. 600
  606. 601
  607. 602
  608. 603
  609. 604
  610. 605
  611. 606
  612. 607
  613. 608
  614. 609
  615. 610
  616. 611
  617. 612
  618. 613
  619. 614
  620. 615
  621. 616
  622. 617
  623. 618
  624. 619
  625. 620
  626. 621
  627. 622
  628. 623
  629. 624
  630. 625
  631. 626
  632. 627
  633. 628
  634. 629
  635. 630
  636. 631
  637. 632
  638. 633
  639. 634
  640. 635
  641. 636
  642. 637
  643. 638
  644. 639
  645. 640
  646. 641
  647. 642
  648. 643
  649. 644
  650. 645
  651. 646
  652. 647
  653. 648
  654. 649
  655. 650
  656. 651
  657. 652
  658. 653
  659. 654
  660. 655
  661. 656
  662. 657
  663. 658
  664. 659
  665. 660
  666. 661
  667. 662
  668. 663
  669. 664
  670. 665
  671. 666
  672. 667
  673. 668
  674. 669
  675. 670
  676. 671
  677. 672
  678. 673
  679. 674
  680. 675
  681. 676
  682. 677
  683. 678
  684. 679
  685. 680
  686. 681
  687. 682
  688. 683
  689. 684
  690. 685
  691. 686
  692. 687
  693. 688
  694. 689
  695. 690
  696. 691
  697. 692
  698. 693
  699. 694
  700. 695
  701. 696
  702. 697
  703. 698
  704. 699
  705. 700
  706. 701
  707. 702
  708. 703
  709. 704
  710. 705
  711. 706
  712. 707
  713. 708
  714. 709
  715. 710
  716. 711
  717. 712
  718. 713
  719. 714
  720. 715
  721. 716
  722. 717
  723. 718
  724. 719
  725. 720
  726. 721
  727. 722
  728. 723
  729. 724
  730. 725
  731. 726
  732. 727
  733. 728
  734. 729
  735. 730
  736. 731
  737. 732
  738. 733
  739. 734
  740. 735
  741. 736
  742. 737
  743. 738
  744. 739
  745. 740
  746. 741
  747. 742
  748. 743
  749. 744
  750. 745
  751. 747
  752. 748
  753. 749
  754. 750
  755. 751
  756. 752
  757. 753
  758. 754
  759. 755
  760. 756
  761. 757
  762. 758
  763. 759
  764. 760
  765. 761
  766. 762
  767. 763
  768. 764
  769. 765
  770. 766
  771. 767
  772. 768
  773. 769
  774. 770
  775. 771
  776. 772
  777. 773
  778. 774
  779. 775
  780. 776
  781. 777
  782. 778
  783. 779
  784. 780
  785. 781
  786. 782
  787. 783
  788. 784
  789. 785
  790. 786
  791. 787
  792. 788
  793. 789
  794. 790
  795. 791
  796. 792
  797. 793
  798. 794
  799. 795
  800. 796
  801. 797
  802. 798
  803. 799
  804. 800
  805. 801
  806. 802
  807. 803
  808. 804
  809. 805
  810. 806
  811. 807
  812. 808
  813. 809
  814. 810
  815. 811
  816. 812
  817. 813
  818. 814
  819. 815
  820. 816
  821. 817
  822. 818
  823. 819
  824. 820
  825. 821
  826. 822
  827. 823
  828. 825
  829. 826
  830. 827
  831. 828
  832. 829
  833. 830
  834. 831
  835. 832
  836. 833
  837. 834
  838. 835
  839. 836
  840. 837
  841. 838
  842. 839
  843. 840
  844. 841
  845. 842
  846. 843
  847. 844
  848. 845
  849. 846
  850. 847
  851. 848
  852. 849
  853. 850
  854. 851
  855. 852
  856. 853
  857. 854
  858. 855
  859. 856
  860. 857
  861. 858
  862. 859
  863. 860
  864. 861
  865. 862
  866. 863
  867. 864
  868. 865
  869. 866
  870. 867
  871. 868
  872. 869
  873. 870
  874. 871
  875. 872
  876. 873
  877. 874
  878. 875
  879. 876
  880. 877
  881. 878
  882. 879
  883. 880
  884. 881
  885. 882
  886. 883
  887. 884
  888. 885
  889. 886
  890. 887
  891. 888
  892. 889
  893. 890
  894. 891
  895. 892
  896. 893
  897. 894
  898. 895
  899. 896
  900. 897
  901. 898
  902. 899
  903. 901
  904. 902
  905. 903
  906. 904
  907. 905
  908. 906
  909. 907
  910. 908
  911. 909
  912. 910
  913. 911
  914. 912
  915. 913
  916. 914
  917. 915
  918. 916
  919. 917
  920. 919
  921. 920
  922. 921
  923. 922
  924. 923
  925. 924
  926. 925
  927. 926
  928. 927
  929. 928
  930. 929
  931. 930
  932. 931
  933. 932
  934. 933
  935. 934
  936. 935
  937. 936
  938. 937
  939. 938
  940. 939
  941. 940
  942. 941
  943. 942
  944. 943
  945. 944
  946. 945
  947. 946
  948. 947
  949. 948
  950. 949
  951. 950
  952. 951
  953. 952
  954. 953
  955. 954
  956. 955
  957. 956
  958. 957
  959. 958
  960. 959
  961. 960
  962. 961
  963. 962
  964. 963
  965. 964
  966. 965
  967. 966
  968. 967
  969. 968
  970. 969
  971. 970
  972. 971
  973. 972
  974. 973
  975. 974
  976. 975
  977. 976
  978. 977
  979. 978
  980. 979
  981. 980
  982. 981
  983. 982
  984. 983
  985. 984
  986. 985
  987. 986
  988. 987
  989. 988
  990. 989
  991. 990
  992. 991
  993. 992
  994. 993
  995. 994
  996. 995
  997. 996
  998. 997
  999. 998
  1000. 999
  1001. 1000
  1002. 1001