logo资料库

Assembly Language Succinctly Syncfusion 2013.pdf

第1页 / 共132页
第2页 / 共132页
第3页 / 共132页
第4页 / 共132页
第5页 / 共132页
第6页 / 共132页
第7页 / 共132页
第8页 / 共132页
资料共132页,剩余部分请下载后查看
The Story behind the Succinctly Series of Books
About the Author
Introduction
Assembly Language
Why Learn Assembly?
Intended Audience
Chapter 1 Assembly in Visual Studio
Inline Assembly in 32-Bit Applications
Native Assembly Files in C++
Additional Steps for x64
64-bit Code Example
Chapter 2 Fundamentals
Skeleton of an x64 Assembly File
Skeleton of an x32 Assembly File
Comments
Destination and Source Operands
Segments
Labels
Anonymous Labels
Data Types
Little and Big Endian
Two’s and One’s Complement
Chapter 3 Memory Spaces
Registers
16-Bit Register Set
32-Bit Register Set
64-bit Register Set
Chapter 4 Addressing Modes
Registers Addressing Mode
Immediate Addressing Mode
Implied Addressing Mode
Memory Addressing Mode
Chapter 5 Data Segment
Scalar Data
Arrays
Arrays Declared with Commas
Duplicate Syntax for Larger Arrays
Getting Information about an Array
Defining Strings
Typedef
Structures and Unions
Structures of Structures
Unions
Records
Constants Using Equates To
Macros
Chapter 6 C Calling Convention
The Stack
Scratch versus Non-Scratch Registers
Passing Parameters
Shadow Space
Chapter 7 Instruction Reference
CISC Instruction Sets
Parameter Format
Flags Register
Prefixes
Repeat Prefixes
Lock Prefix
x86 Data Movement Instructions
Move
Conditional Moves
Nontemporal Move
Move and Zero Extend
Move and Sign Extend
Move and Sign Extend Dword to Qword
Exchange
Translate Table
Sign Extend AL, AX, and EAX
Copy Sign of RAX across RDX
Push to Data to Stack
Pop Data from Stack
Push Flags Register
Pop Flags Register
Load Effective Address
Byte Swap
x86 Arithmetic Instructions
Addition and Subtraction
Add with Carry and Subtract with Borrow
Increment and Decrement
Negate
Compare
Multiply
Signed and Unsigned Division
x86 Boolean Instructions
Boolean And, Or, Xor
Boolean Not (Flip Every Bit)
Test Bits
Shift Right and Left
Rotate Left and Right
Rotate Left and Right Through the Carry Flag
Shift Double Left or Right
Bit Test
Bit Scan Forward and Reverse
Conditional Byte Set
Set and Clear the Carry or Direction Flags
Jumps
Call a Function
Return from Function
x86 String Instructions
Load String
Store String
Move String
Scan String
Compare String
x86 Miscellaneous Instructions
No Operation
Pause
Read Time Stamp Counter
Loop
CPUID
Chapter 8 SIMD Instruction Sets
SIMD Concepts
Saturating Arithmetic versus Wraparound Arithmetic
Packed/SIMD versus Scalar
MMX
Registers
Referencing Memory
Exit Multimedia State
Moving Data into MMX Registers
Move Quad-Word
Move Dword
Boolean Instructions
Shifting Bits
Arithmetic Instructions
Multiplication
Comparisons
Creating the Remaining Comparison Operators
Packing
Unpacking
SSE Instruction Sets
Introduction
AVX
Data Moving Instructions
Move Aligned Packed Doubles/Singles
Move Unaligned Packed Doubles/Singles
Arithmetic Instructions
Adding Floating Point Values
Subtracting Floating Point Values
Dividing Floating Point Values
Multiplying Floating Point Values
Square Root of Floating Point Values
Reciprocal of Single-Precision Floats
Reciprocal of Square Root of Single-Precision Floats
Boolean Operations
AND NOT Packed Doubles/Singles
AND Packed Doubles/Singles
OR Packed Doubles/Singles
XOR Packed Doubles/Singles
Comparison Instructions
Comparing Packed Doubles and Singles
Comparing Scalar Doubles and Singles
Comparing and Setting rFlags
Converting Data Types/Casting
Conversion Instructions
Selecting the Rounding Function
Conclusion
Recommended Reading
By Christopher Rose Foreword by Daniel Jebaraj 2
Copyright © 2013 by Syncfusion Inc. 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA All rights reserved. I mportant licensing information. Please read. This book is available for free download from www.syncfusion.com on completion of a registration form. If you obtained this book from any other source, please register and download a free copy from www.syncfusion.com. This book is licensed for reading only if obtained from www.syncfusion.com. This book is licensed strictly for personal or educational use. Redistribution in any form is prohibited. The authors and copyright holders provide absolutely no warranty for any information provided. The authors and copyright holders shall not be liable for any claim, damages, or any other liability arising from, out of, or in connection with the information in this book. Please do not use this book if the listed terms are unacceptable. Use shall constitute acceptance of the terms listed. SYNCFUSION, SUCCINCTLY, DELIVER INNOVATION WITH EASE, ESSENTIAL, and .NET ESSENTIALS are the registered trademarks of Syncfusion, Inc. Technical Reviewer: Jarred Capellman Copy Editor: Ben Ball Acquisitions Coordinator: Jessica Rightmer, senior marketing strategist, Syncfusion, Inc. Proofreader: Graham High, content producer, Syncfusion, Inc. 3
Table of Contents The Story behind the Succinctly Series of Books ........................................................................... 10 About the Author ................................................................................................................................. 12 Introduction ......................................................................................................................................... 13 Assembly Language ........................................................................................................................ 13 Why Learn Assembly? ..................................................................................................................... 13 Intended Audience ........................................................................................................................... 14 Chapter 1 Assembly in Visual Studio .............................................................................................. 15 Inline Assembly in 32-Bit Applications ............................................................................................. 15 Native Assembly Files in C++ .......................................................................................................... 16 Additional Steps for x64 ................................................................................................................. 20 64-bit Code Example ..................................................................................................................... 24 Chapter 2 Fundamentals ................................................................................................................... 26 Skeleton of an x64 Assembly File .................................................................................................... 26 Skeleton of an x32 Assembly File .................................................................................................... 27 Comments ........................................................................................................................................ 28 Destination and Source Operands ................................................................................................... 29 Segments ......................................................................................................................................... 29 Labels............................................................................................................................................... 30 Anonymous Labels ........................................................................................................................ 30 Data Types ....................................................................................................................................... 31 Little and Big Endian ...................................................................................................................... 32 Two’s and One’s Complement ....................................................................................................... 33 Chapter 3 Memory Spaces ................................................................................................................ 34 Registers .......................................................................................................................................... 35 16-Bit Register Set ......................................................................................................................... 35 32-Bit Register Set ......................................................................................................................... 37 4
64-bit Register Set ......................................................................................................................... 39 Chapter 4 Addressing Modes ........................................................................................................... 41 Registers Addressing Mode ........................................................................................................... 41 Immediate Addressing Mode ......................................................................................................... 41 Implied Addressing Mode .............................................................................................................. 42 Memory Addressing Mode ............................................................................................................. 42 Chapter 5 Data Segment .................................................................................................................... 45 Scalar Data ...................................................................................................................................... 45 Arrays ............................................................................................................................................... 46 Arrays Declared with Commas ...................................................................................................... 46 Duplicate Syntax for Larger Arrays ................................................................................................ 46 Getting Information about an Array................................................................................................ 47 Defining Strings .............................................................................................................................. 48 Typedef ............................................................................................................................................ 49 Structures and Unions ..................................................................................................................... 49 Structures of Structures ................................................................................................................. 52 Unions ............................................................................................................................................ 53 Records .......................................................................................................................................... 53 Constants Using Equates To ........................................................................................................... 55 Macros ............................................................................................................................................. 56 Chapter 6 C Calling Convention ....................................................................................................... 59 The Stack ....................................................................................................................................... 59 Scratch versus Non-Scratch Registers .......................................................................................... 59 Passing Parameters....................................................................................................................... 61 Shadow Space ............................................................................................................................... 62 Chapter 7 Instruction Reference ...................................................................................................... 67 CISC Instruction Sets .................................................................................................................... 67 Parameter Format .......................................................................................................................... 67 Flags Register ................................................................................................................................ 68 5
Prefixes ............................................................................................................................................ 69 Repeat Prefixes ............................................................................................................................. 69 Lock Prefix ..................................................................................................................................... 69 x86 Data Movement Instructions ..................................................................................................... 70 Move .............................................................................................................................................. 70 Conditional Moves ......................................................................................................................... 71 Nontemporal Move......................................................................................................................... 72 Move and Zero Extend .................................................................................................................. 73 Move and Sign Extend ................................................................................................................... 73 Move and Sign Extend Dword to Qword ....................................................................................... 73 Exchange ....................................................................................................................................... 73 Translate Table .............................................................................................................................. 74 Sign Extend AL, AX, and EAX ....................................................................................................... 74 Copy Sign of RAX across RDX ...................................................................................................... 75 Push to Data to Stack .................................................................................................................... 75 Pop Data from Stack ...................................................................................................................... 75 Push Flags Register....................................................................................................................... 76 Pop Flags Register ........................................................................................................................ 76 Load Effective Address .................................................................................................................. 76 Byte Swap ...................................................................................................................................... 77 x86 Arithmetic Instructions ............................................................................................................... 78 Addition and Subtraction ................................................................................................................ 78 Add with Carry and Subtract with Borrow ...................................................................................... 78 Increment and Decrement ............................................................................................................. 79 Negate ........................................................................................................................................... 80 Compare ........................................................................................................................................ 80 Multiply ........................................................................................................................................... 80 Signed and Unsigned Division ....................................................................................................... 82 x86 Boolean Instructions.................................................................................................................. 83 Boolean And, Or, Xor ..................................................................................................................... 83 6
Boolean Not (Flip Every Bit) .......................................................................................................... 84 Test Bits ......................................................................................................................................... 84 Shift Right and Left ........................................................................................................................ 85 Rotate Left and Right ..................................................................................................................... 85 Rotate Left and Right Through the Carry Flag .............................................................................. 86 Shift Double Left or Right ............................................................................................................... 86 Bit Test ........................................................................................................................................... 86 Bit Scan Forward and Reverse ...................................................................................................... 87 Conditional Byte Set ...................................................................................................................... 87 Set and Clear the Carry or Direction Flags .................................................................................... 88 Jumps ............................................................................................................................................ 89 Call a Function ............................................................................................................................... 90 Return from Function ..................................................................................................................... 90 x86 String Instructions ..................................................................................................................... 90 Load String ..................................................................................................................................... 90 Store String .................................................................................................................................... 91 Move String .................................................................................................................................... 92 Scan String .................................................................................................................................... 92 Compare String .............................................................................................................................. 93 x86 Miscellaneous Instructions ........................................................................................................ 94 No Operation .................................................................................................................................. 94 Pause ............................................................................................................................................. 94 Read Time Stamp Counter ............................................................................................................ 94 Loop ............................................................................................................................................... 95 CPUID .............................................................................................................................................. 96 Chapter 8 SIMD Instruction Sets .................................................................................................... 100 SIMD Concepts .............................................................................................................................. 101 Saturating Arithmetic versus Wraparound Arithmetic .................................................................. 101 Packed/SIMD versus Scalar ........................................................................................................ 102 7
MMX ............................................................................................................................................... 102 Registers ...................................................................................................................................... 103 Referencing Memory.................................................................................................................... 103 Exit Multimedia State ................................................................................................................... 104 Moving Data into MMX Registers .................................................................................................. 104 Move Quad-Word......................................................................................................................... 104 Move Dword ................................................................................................................................. 104 Boolean Instructions ...................................................................................................................... 105 Shifting Bits .................................................................................................................................... 105 Arithmetic Instructions .................................................................................................................... 106 Multiplication ................................................................................................................................ 108 Comparisons .................................................................................................................................. 108 Creating the Remaining Comparison Operators ......................................................................... 109 Packing .......................................................................................................................................... 110 Unpacking .................................................................................................................................... 111 SSE Instruction Sets ...................................................................................................................... 113 Introduction .................................................................................................................................. 113 AVX .............................................................................................................................................. 114 Data Moving Instructions ............................................................................................................... 115 Move Aligned Packed Doubles/Singles ....................................................................................... 115 Move Unaligned Packed Doubles/Singles ................................................................................... 115 Arithmetic Instructions .................................................................................................................... 116 Adding Floating Point Values ....................................................................................................... 116 Subtracting Floating Point Values ................................................................................................ 117 Dividing Floating Point Values ..................................................................................................... 118 Multiplying Floating Point Values ................................................................................................. 119 Square Root of Floating Point Values.......................................................................................... 120 Reciprocal of Single-Precision Floats .......................................................................................... 121 Reciprocal of Square Root of Single-Precision Floats................................................................. 122 Boolean Operations ....................................................................................................................... 122 8
分享到:
收藏