x64 Assembly Language Step-by-Step: Programming with Linux [4 ed.] 1394155247, 9781394155248, 9781394155545, 9781394155255

The long-awaited x64 edition of the bestselling introduction to Intel assembly language In the newly revised fourth edit

242 95 13MB

English Pages 640 Year 2023

Report DMCA / Copyright

DOWNLOAD FILE

x64 Assembly Language Step-by-Step: Programming with Linux [4 ed.]
 1394155247, 9781394155248, 9781394155545, 9781394155255

Table of contents :
Cover
Table of Contents
Title Page
Introduction
CHAPTER 1: It's All in the Plan
Another Pleasant Valley Saturday
Had This Been the Real Thing …
Assembly Language Programming As a Square Dance
Assembly Language Programming As a Board Game
CHAPTER 2: Alien Bases
The Return of the New Math Monster
Octal: How the Grinch Stole Eight and Nine
Hexadecimal: Solving the Digit Shortage
From Hex to Decimal and from Decimal to Hex
Practice. Practice! PRACTICE!
Arithmetic in Hex
Binary
Hexadecimal as Shorthand for Binary
Prepare to Compute
CHAPTER 3: Lifting the Hood
RAXie, We Hardly Knew Ye
Switches, Transistors, and Memory
The Shop Supervisor and the Assembly Line
The Box That Follows a Plan
What vs. How: Architecture and Microarchitecture
Enter the Plant Manager
CHAPTER 4: Location, Location, Location
The Joy of Memory Models
The Nature of Segments
Segment Registers
The Four Major Assembly Programming Models
64-Bit Long Mode
CHAPTER 5: The Right to Assemble
The Nine and Sixty Ways to Code
Files and What's Inside Them
Text In, Code Out
The Assembly Language Development Process
Linking the Object Code File
Taking a Trip Down Assembly Lane
CHAPTER 6: A Place to Stand, with Access to Tools
Integrated Development Environments
Introducing SASM
Linux and Terminals
Using Linux Make
Debugging with SASM
CHAPTER 7: Following Your Instructions
Build Yourself a Sandbox
Instructions and Their Operands
Source and Destination Operands
Rally Round the Flags, Boys!
Signed and Unsigned Values
Implicit Operands and MUL
Reading and Using an Assembly Language Reference
NEG Negate (Two's Complement; i.e., Multiply by −1)
CHAPTER 8: Our Object All Sublime
The Bones of an Assembly Language Program
Last In, First Out via the Stack
Using Linux Kernel Services Through Syscall
Designing a Nontrivial Program
Going Further
CHAPTER 9: Bits, Flags, Branches, and Tables
Bits Is Bits (and Bytes Is Bits)
Shifting Bits
Bit-Bashing in Action
Flags, Tests, and Branches
X64 Long Mode Memory Addressing in Detail
Character Table Translation
Tables Instead of Calculations
CHAPTER 10: Dividing and Conquering
Boxes within Boxes
Calling and Returning
Local Labels and the Lengths of Jumps
Building External Procedure Libraries
The Art of Crafting Procedures
Simple Cursor Control in the Linux Console
Creating and Using Macros
CHAPTER 11: Strings and Things
The Notion of an Assembly Language String
REP STOSB, the Software Machine Gun
The Semiautomatic Weapon: STOSB Without REP
MOVSB: Fast Block Copies
Storing Data to Discontinuous Strings
Command-Line Arguments, String Searches, and the Linux Stack
The Stack, Its Structure, and How to Use It
CHAPTER 12: Heading Out to C
What's GNU?
Linking to the Standard C Library
Formatted Text Output with printf()
Data In with fgets() and scanf()
Be a Linux Time Lord
Understanding AT&T Instruction Mnemonics
Generating Random Numbers
How C Sees Command-Line Arguments
Simple File I/O
Conclusion: Not the End, But Only the Beginning
Where to Now?
The Art of 64-bit Assembly by Randall Hyde (No Starch Press, 2022)
Modern x86 Assembly Language Programming by David Kusswurm (Apress, 2018)
Stepping off Square One
APPENDIX A: The Return of the Insight Debugger
Insight's Shortcomings
Opening a Program Under Insight
Setting Command-Line Arguments with Insight
Running and Stepping a Program
The Memory Window
Showing the Stack in Insight's Memory View
Examining the Stack with Insight's Memory View
Learn gdb!
APPENDIX B: Partial x64 Instruction Reference
What's Been Removed from x64
Flag Results
Size Specifiers
Instruction Index
ADC: Arithmetic Addition with Carry
ADD: Arithmetic Addition
AND: Logical AND
BT: Bit Test
CALL: Call Procedure
CLC: Clear Carry Flag (CF)
CLD: Clear Direction Flag (DF)
CMP: Arithmetic Comparison
DEC: Decrement Operand
DIV: Unsigned Integer Division
INC: Increment Operand
J??: Jump If Condition Is Met
JECXZ: Jump if ECX=0
JRCXZ: Jump If RCX=0
JMP: Unconditional Jump
LEA: Load Effective Address
LOOP: Loop Until CX/ECX/RCX=0
LOOPNZ/LOOPNE: Loop Until CX/ECX/RCX=0 and ZF=0
LOOPZ/LOOPE: Loop Until CX/ECX/RCX=0 and ZF=1
MOV: Copy Right Operand into Left Operand
MOVS: Move String
MOVSX: Copy with Sign Extension
MUL: Unsigned Integer Multiplication
NEG: Negate (Two's Complement; i.e., Multiply by −1)
NOP: No Operation
NOT: Logical NOT (One's Complement)
OR: Logical OR
POP: Copy Top of Stack into Operand
POPF/D/Q: Copy Top of Stack into Flags Register
PUSH: Push Operand onto Top of Stack
PUSHF/D/Q: Push Flags Onto the Stack
RET: Return from Procedure
ROL/ROR: Rotate Left/Rotate Right
SBB: Arithmetic Subtraction with Borrow
SHL/SHR: Shift Left/Shift Right
STC: Set Carry Flag (CF)
STD: Set Direction Flag (DF)
STOS/B/W/D/Q: Store String
SUB: Arithmetic Subtraction
SYSCALL: Fast System Call into Linux
XCHG: Exchange Operands
XLAT: Translate Byte Via Table
XOR: Exclusive OR
APPENDIX C: Character Set Charts
Index
Copyright
Dedication
About the Author
About the Technical Editor
Acknowledgments
End User License Agreement

Polecaj historie