وبلاگ بلیان

Professional Assembly Language (Programmer to Programmer)

معرفی کتاب «Professional Assembly Language (Programmer to Programmer)» نوشتهٔ Richard Blum.، منتشرشده توسط نشر John Wiley & Sons در سال 2005. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است. «Professional Assembly Language (Programmer to Programmer)» در دستهٔ بدون دسته‌بندی قرار دارد.

What You Need to Use This Book All of the examples in this book are coded to be assembled and run on the Linux operating system, running on an Intel processor platform. The Open Source GNU compiler (gcc), assembler (gas), linker (ld), and debugger (gdb) are used extensively throughout the book to demonstrate the assembly language features. Chapter 4,'A Sample Assembly Language Program, discusses specifically how to use these tools on a Linux platform to create, assemble, link, and debug an assembly language program. If you do not have an installed Linux platform available, Chapter 4 demonstrates how to use a Linux distribution that can be booted directly from CD, without modifying the workstation hard drive. All of the GNU development tools used in this book are available without installing Linux on the workstation. Содержание Chapter 1,'What Is Assembly Language? Chapter 2,'The IA-32 Platform Chapter 3,'The Tools of the Trade Chapter 4,'A Sample Assembly Language Program Chapter 5,'Moving Data Chapter 6,'Controlling Execution Flow Chapter 7,'Using Numbers Chapter 8,'Basic Math Functions Chapter 9,'Advanced Math Functions Chapter 10,'Working with Strings Chapter 11,'Using Functions Chapter 12,'Using Linux System Calls Chapter 13,'Using Inline Assembly Chapter 14,'Calling Assembly Libraries Chapter 15,'Optimizing Routines Chapter 16,'Using Files Chapter 17,'Using Advanced IA-32 Features метки темы ассемблер Team DDU Professional assembly language 1 Cover 1 Acknowledgments 14 Contents 16 Contents 16 Introduction 26 Chapter 1: What Is Assembly Language? 32 Processor Instructions 32 Instruction code handling 33 Instruction code format 34 High-Level Languages 37 Types of high-level languages 38 High-level language features 40 Assembly Language 41 Opcode mnemonics 42 Defining data 43 Directives 45 Summary 46 Chapter 2: The IA-32 Platform 48 Core Parts of an IA-32 Processor 48 Control unit 50 Execution unit 55 Registers 56 Flags 60 Advanced IA-32 Features 63 The x87 floating-point unit 63 Multimedia extensions (MMX) 64 Streaming SIMD extensions (SSE) 64 Hyperthreading 65 The IA-32 Processor Family 65 Intel processors 66 Non-Intel processors 67 Summary 68 Chapter 3: The Tools of the Trade 70 The Development Tools 70 The Assembler 71 The Linker 73 The Debugger 74 The Compiler 75 The object code disassembler 75 The Profiler 75 The GNU Assembler 76 Installing the assembler 76 Using the assembler 78 A word about opcode syntax 80 The GNU Linker 81 The GNU Compiler 84 Downloading and installing gcc 84 Using gcc 85 The GNU Debugger Program 87 Downloading and installing gdb 87 Using gdb 88 The KDE Debugger 91 Downloading and installing kdbg 91 Using kdbg 91 The GNU Objdump Program 93 Using objdump 94 An objdump example 95 The GNU Profiler Program 96 Using the profiler 96 A profile example 99 A Complete Assembly Development System 100 The basics of Linux 100 Downloading and running MEPIS 101 Your new development system 102 Summary 103 Chapter 4: A Sample Assembly Language Program 104 The Parts of a Program 104 Defining sections 105 Defining the starting point 105 Creating a Simple Program 106 The CPUID instruction 107 The sample program 108 Building the executable 111 Running the executable 111 Assembling using a compiler 111 Debugging the Program 112 Using gdb 112 Using C Library Functions in Assembly 117 Using printf 118 Linking with C library functions 119 Summary 121 Chapter 5: Moving Data 122 Defining Data Elements 122 The data section 122 Defining static symbols 125 The bss section 126 Moving Data Elements 128 The MOV instruction formats 128 Moving immediate data to registers and memory 129 Moving data between registers 130 Moving data between memory and registers 130 Conditional Move Instructions 137 The CMOV instructions 138 Using CMOV instructions 140 Exchanging Data 141 The data exchange instructions 142 Using the data exchange instruction 147 The Stack 150 How the stack works 150 PUSHing and POPing data 151 PUSHing and POPing all the registers 154 Manually using the ESP and EBP registers 154 Optimizing Memory Access 154 Summary 155 Chapter 6: Controlling Execution Flow 158 The Instruction Pointer 158 Unconditional Branches 160 Jumps 160 Calls 163 Interrupts 166 Conditional Branches 167 Conditional jump instructions 167 The compare instruction 169 Examples of using the flag bits 171 Loops 175 The loop instructions 175 A loop example 176 Preventing LOOP catastrophes 176 Duplicating High-Level Conditional Branches 177 if statements 178 for loops 181 Optimizing Branch Instructions 184 Branch prediction 184 Optimizing tips 186 Summary 189 Chapter 7: Using Numbers 192 Numeric Data Types 192 Integers 193 Standard integer sizes 193 Unsigned integers 195 Signed integers 197 Using signed integers 199 Extending integers 200 Defining integers in GAS 203 SIMD Integers 204 MMX integers 204 Moving MMX integers 205 SSE integers 207 Moving SSE integers 208 Binary Coded Decimal 209 What is BCD? 209 FPU BCD values 210 Moving BCD values 211 Floating-Point Numbers 213 What are floating-point numbers? 213 Standard floating-point data types 215 IA-32 floating-point values 217 Defining floating-point values in GAS 218 Moving floating-point values 218 Using preset floating-point values 220 SSE floating-point data types 221 Moving SSE floating-point values 222 Conversions 227 Conversion instructions 227 A conversion example 229 Summary 230 Chapter 8: Basic Math Functions 232 Integer Arithmetic 232 Addition 232 Subtraction 241 Incrementing and decrementing 246 Multiplication 247 Division 252 Shift Instructions 254 Multiply by shifting 255 Dividing by shifting 256 Rotating bits 257 Decimal Arithmetic 258 Unpacked BCD arithmetic 258 Packed BCD arithmetic 260 Logical Operations 262 Boolean logic 262 Bit testing 263 Summary 264 Chapter 9: Advanced Math Functions 266 The FPU Environment 266 The FPU register stack 267 The FPU status, control, and tag registers 268 Using the FPU stack 273 Basic Floating-Point Math 276 Advanced Floating-Point Math 280 Floating-point functions 280 Partial remainders 283 Trigonometric functions 285 Logarithmic functions 288 Floating-Point Conditional Branches 290 The FCOM instruction family 291 The FCOMI instruction family 293 The FCMOV instruction family 294 Saving and Restoring the FPU State 296 Saving and restoring the FPU environment 296 Saving and restoring the FPU state 297 Waiting versus Nonwaiting Instructions 300 Optimizing Floating-Point Calculations 301 Summary 301 Chapter 10: Working with Strings 304 Moving Strings 304 The MOVS instruction 305 The REP prefix 309 Other REP instructions 314 Storing and Loading Strings 314 The LODS instruction 314 The STOS instruction 315 Building your own string functions 316 Comparing Strings 317 The CMPS instruction 317 Using REP with CMPS 319 String inequality 320 Scanning Strings 322 The SCAS instruction 323 Scanning for multiple characters 324 Finding a string length 326 Summary 327 Chapter 11: Using Functions 328 Defining Functions 328 Assembly Functions 330 Writing functions 330 Accessing functions 333 Function placement 335 Using registers 335 Using global data 335 Passing Data Values in C Style 337 Revisiting the stack 337 Passing function parameters on the stack 337 Function prologue and epilogue 339 Defining local function data 340 Cleaning out the stack 343 An example 343 Watching the stack in action 345 Using Separate Function Files 348 Creating a separate function file 348 Creating the executable file 349 Debugging separate function files 350 Using Command-Line Parameters 351 The anatomy of a program 351 Analyzing the stack 352 Viewing command-line parameters 354 Viewing environment variables 356 An example using command-line parameters 357 Summary 359 Chapter 12: Using Linux System Calls 360 The Linux Kernel 360 Parts of the kernel 361 Linux kernel version 367 System Calls 368 Finding system calls 368 Finding system call definitions 369 Common system calls 370 Using System Calls 372 The system call format 372 Advanced System Call Return Values 377 The sysinfo system call 377 Using the return structure 378 Viewing the results 379 Tracing System Calls 380 The strace program 380 Advanced strace parameters 381 Watching program system calls 382 Attaching to a running program 384 System Calls versus C Libraries 386 The C libraries 387 Tracing C functions 388 Comparing system calls and C libraries 389 Summary 390 Chapter 13: Using Inline Assembly 392 What Is Inline Assembly? 392 Basic Inline Assembly Code 396 The asm format 396 Using global C variables 398 Using the volatile modifier 400 Using an alternate keyword 400 Extended ASM 401 Extended ASM format 401 Specifying input and output values 401 Using registers 403 Using placeholders 404 Referencing placeholders 407 Alternative placeholders 408 Changed registers list 408 Using memory locations 410 Using floating-point values 411 Handling jumps 413 Using Inline Assembly Code 415 What are macros? 415 C macro functions 415 Creating inline assembly macro functions 417 Summary 418 Chapter 14: Calling Assembly Libraries 420 Creating Assembly Functions 420 Compiling the C and Assembly Programs 422 Compiling assembly source code files 423 Using assembly object code files 423 The executable file 424 Using Assembly Functions in C Programs 426 Using integer return values 427 Using string return values 428 Using floating-point return values 431 Using multiple input values 432 Using mixed data type input values 434 Using Assembly Functions in C++ Programs 438 Creating Static Libraries 439 What is a static library? 439 The ar command 440 Creating a static library file 441 Compiling with static libraries 443 Using Shared Libraries 443 What are shared libraries? 443 Creating a shared library 445 Compiling with a shared library 445 Running programs that use shared libraries 446 Debugging Assembly Functions 448 Debugging C programs 448 Debugging assembly functions 449 Summary 451 Chapter 15: Optimizing Routines 452 Optimized Compiler Code 452 Compiler optimization level 1 453 Compiler optimization level 2 454 Compiler optimization level 3 456 Creating Optimized Code 456 Generating the assembly language code 456 Viewing optimized code 460 Recompiling the optimized code 460 Optimization Tricks 461 Optimizing calculations 461 Optimizing variables 464 Optimizing loops 468 Optimizing conditional branches 473 Common subexpression elimination 478 Summary 481 Chapter 16: Using Files 484 The File-Handling Sequence 484 Opening and Closing Files 485 Access types 486 UNIX permissions 487 Open file code 489 Open error return codes 490 Closing files 491 Writing to Files 491 A simple write example 491 Changing file access modes 493 Handling file errors 493 Reading Files 494 A simple read example 495 A more complicated read example 496 Reading, Processing, and Writing Data 498 Memory-Mapped Files 501 What are memory-mapped files? 501 The mmap system call 502 mmap assembly language format 504 An mmap example 506 Summary 510 Chapter 17: Using Advanced IA-32 Features 512 A Brief Review of SIMD 512 MMX 513 SSE 514 SSE2 514 Detecting Supported SIMD Operations 514 Detecting support 515 SIMD feature program 516 Using MMX Instructions 518 Loading and retrieving packed integer values 518 Performing MMX operations 519 Using SSE Instructions 528 Moving data 529 Processing data 530 Using SSE2 Instructions 535 Moving data 536 Processing data 536 SSE3 Instructions 539 Summary 539 Index 542 Team DDU 1 Team DDU......Page 1 Acknowledgments......Page 14 Contents......Page 16 Introduction......Page 26 Processor Instructions......Page 32 Instruction code handling......Page 33 Instruction code format......Page 34 High-Level Languages......Page 37 Types of high-level languages......Page 38 High-level language features......Page 40 Assembly Language......Page 41 Opcode mnemonics......Page 42 Defining data......Page 43 Directives......Page 45 Summary......Page 46 Core Parts of an IA-32 Processor......Page 48 Control unit......Page 50 Execution unit......Page 55 Registers......Page 56 Flags......Page 60 The x87 floating-point unit......Page 63 Streaming SIMD extensions (SSE)......Page 64 The IA-32 Processor Family......Page 65 Intel processors......Page 66 Non-Intel processors......Page 67 Summary......Page 68 The Development Tools......Page 70 The Assembler......Page 71 The Linker......Page 73 The Debugger......Page 74 The Profiler......Page 75 Installing the assembler......Page 76 Using the assembler......Page 78 A word about opcode syntax......Page 80 The GNU Linker......Page 81 Downloading and installing gcc......Page 84 Using gcc......Page 85 Downloading and installing gdb......Page 87 Using gdb......Page 88 Using kdbg......Page 91 The GNU Objdump Program......Page 93 Using objdump......Page 94 An objdump example......Page 95 Using the profiler......Page 96 A profile example......Page 99 The basics of Linux......Page 100 Downloading and running MEPIS......Page 101 Your new development system......Page 102 Summary......Page 103 The Parts of a Program......Page 104 Defining the starting point......Page 105 Creating a Simple Program......Page 106 The CPUID instruction......Page 107 The sample program......Page 108 Assembling using a compiler......Page 111 Using gdb......Page 112 Using C Library Functions in Assembly......Page 117 Using printf......Page 118 Linking with C library functions......Page 119 Summary......Page 121 The data section......Page 122 Defining static symbols......Page 125 The bss section......Page 126 The MOV instruction formats......Page 128 Moving immediate data to registers and memory......Page 129 Moving data between memory and registers......Page 130 Conditional Move Instructions......Page 137 The CMOV instructions......Page 138 Using CMOV instructions......Page 140 Exchanging Data......Page 141 The data exchange instructions......Page 142 Using the data exchange instruction......Page 147 How the stack works......Page 150 PUSHing and POPing data......Page 151 Optimizing Memory Access......Page 154 Summary......Page 155 The Instruction Pointer......Page 158 Jumps......Page 160 Calls......Page 163 Interrupts......Page 166 Conditional jump instructions......Page 167 The compare instruction......Page 169 Examples of using the flag bits......Page 171 The loop instructions......Page 175 Preventing LOOP catastrophes......Page 176 Duplicating High-Level Conditional Branches......Page 177 if statements......Page 178 for loops......Page 181 Branch prediction......Page 184 Optimizing tips......Page 186 Summary......Page 189 Numeric Data Types......Page 192 Standard integer sizes......Page 193 Unsigned integers......Page 195 Signed integers......Page 197 Using signed integers......Page 199 Extending integers......Page 200 Defining integers in GAS......Page 203 MMX integers......Page 204 Moving MMX integers......Page 205 SSE integers......Page 207 Moving SSE integers......Page 208 What is BCD?......Page 209 FPU BCD values......Page 210 Moving BCD values......Page 211 What are floating-point numbers?......Page 213 Standard floating-point data types......Page 215 IA-32 floating-point values......Page 217 Moving floating-point values......Page 218 Using preset floating-point values......Page 220 SSE floating-point data types......Page 221 Moving SSE floating-point values......Page 222 Conversion instructions......Page 227 A conversion example......Page 229 Summary......Page 230 Addition......Page 232 Subtraction......Page 241 Incrementing and decrementing......Page 246 Multiplication......Page 247 Division......Page 252 Shift Instructions......Page 254 Multiply by shifting......Page 255 Dividing by shifting......Page 256 Rotating bits......Page 257 Unpacked BCD arithmetic......Page 258 Packed BCD arithmetic......Page 260 Boolean logic......Page 262 Bit testing......Page 263 Summary......Page 264 The FPU Environment......Page 266 The FPU register stack......Page 267 The FPU status, control, and tag registers......Page 268 Using the FPU stack......Page 273 Basic Floating-Point Math......Page 276 Floating-point functions......Page 280 Partial remainders......Page 283 Trigonometric functions......Page 285 Logarithmic functions......Page 288 Floating-Point Conditional Branches......Page 290 The FCOM instruction family......Page 291 The FCOMI instruction family......Page 293 The FCMOV instruction family......Page 294 Saving and restoring the FPU environment......Page 296 Saving and restoring the FPU state......Page 297 Waiting versus Nonwaiting Instructions......Page 300 Summary......Page 301 Moving Strings......Page 304 The MOVS instruction......Page 305 The REP prefix......Page 309 The LODS instruction......Page 314 The STOS instruction......Page 315 Building your own string functions......Page 316 The CMPS instruction......Page 317 Using REP with CMPS......Page 319 String inequality......Page 320 Scanning Strings......Page 322 The SCAS instruction......Page 323 Scanning for multiple characters......Page 324 Finding a string length......Page 326 Summary......Page 327 Defining Functions......Page 328 Writing functions......Page 330 Accessing functions......Page 333 Using global data......Page 335 Passing function parameters on the stack......Page 337 Function prologue and epilogue......Page 339 Defining local function data......Page 340 An example......Page 343 Watching the stack in action......Page 345 Creating a separate function file......Page 348 Creating the executable file......Page 349 Debugging separate function files......Page 350 The anatomy of a program......Page 351 Analyzing the stack......Page 352 Viewing command-line parameters......Page 354 Viewing environment variables......Page 356 An example using command-line parameters......Page 357 Summary......Page 359 The Linux Kernel......Page 360 Parts of the kernel......Page 361 Linux kernel version......Page 367 Finding system calls......Page 368 Finding system call definitions......Page 369 Common system calls......Page 370 The system call format......Page 372 The sysinfo system call......Page 377 Using the return structure......Page 378 Viewing the results......Page 379 The strace program......Page 380 Advanced strace parameters......Page 381 Watching program system calls......Page 382 Attaching to a running program......Page 384 System Calls versus C Libraries......Page 386 The C libraries......Page 387 Tracing C functions......Page 388 Comparing system calls and C libraries......Page 389 Summary......Page 390 What Is Inline Assembly?......Page 392 The asm format......Page 396 Using global C variables......Page 398 Using an alternate keyword......Page 400 Specifying input and output values......Page 401 Using registers......Page 403 Using placeholders......Page 404 Referencing placeholders......Page 407 Changed registers list......Page 408 Using memory locations......Page 410 Using floating-point values......Page 411 Handling jumps......Page 413 C macro functions......Page 415 Creating inline assembly macro functions......Page 417 Summary......Page 418 Creating Assembly Functions......Page 420 Compiling the C and Assembly Programs......Page 422 Using assembly object code files......Page 423 The executable file......Page 424 Using Assembly Functions in C Programs......Page 426 Using integer return values......Page 427 Using string return values......Page 428 Using floating-point return values......Page 431 Using multiple input values......Page 432 Using mixed data type input values......Page 434 Using Assembly Functions in C++ Programs......Page 438 What is a static library?......Page 439 The ar command......Page 440 Creating a static library file......Page 441 What are shared libraries?......Page 443 Compiling with a shared library......Page 445 Running programs that use shared libraries......Page 446 Debugging C programs......Page 448 Debugging assembly functions......Page 449 Summary......Page 451 Optimized Compiler Code......Page 452 Compiler optimization level 1......Page 453 Compiler optimization level 2......Page 454 Generating the assembly language code......Page 456 Recompiling the optimized code......Page 460 Optimizing calculations......Page 461 Optimizing variables......Page 464 Optimizing loops......Page 468 Optimizing conditional branches......Page 473 Common subexpression elimination......Page 478 Summary......Page 481 The File-Handling Sequence......Page 484 Opening and Closing Files......Page 485 Access types......Page 486 UNIX permissions......Page 487 Open file code......Page 489 Open error return codes......Page 490 A simple write example......Page 491 Handling file errors......Page 493 Reading Files......Page 494 A simple read example......Page 495 A more complicated read example......Page 496 Reading, Processing, and Writing Data......Page 498 What are memory-mapped files?......Page 501 The mmap system call......Page 502 mmap assembly language format......Page 504 An mmap example......Page 506 Summary......Page 510 A Brief Review of SIMD......Page 512 MMX......Page 513 Detecting Supported SIMD Operations......Page 514 Detecting support......Page 515 SIMD feature program......Page 516 Loading and retrieving packed integer values......Page 518 Performing MMX operations......Page 519 Using SSE Instructions......Page 528 Moving data......Page 529 Processing data......Page 530 Using SSE2 Instructions......Page 535 Processing data......Page 536 Summary......Page 539 Index......Page 542 Annotation Professional Assembly LanguageEvery high level language program (such as C and C++) is converted by a compiler into assembly language before it is linked into an executable program. This book shows you how to view the assembly language code generated by the compiler and understand how it is created. With that knowledge you can tweak the assembly language code generated by the compiler or create your own assembly language routines. This code-intensive guide is divided into three sections - basics of the assembly language program development environment, assembly language programming, and advanced assembly language techniques. It shows how to decipher the compiler-generated assembly language code, and how to make functions in your programs faster and more efficient to increase the performance of an application. What you will learn from this book:The benefits of examining the assembly language code generated from your high-level language programHow to create stand-alone assembly language programs for the Linux Pentium environmentWays to incorporate advanced functions and libraries in assembly language programsHow to incorporate assembly language routines in your C and C++ applicationsWays to use Linux system calls in your assembly language programsHow to utilize Pentium MMX and SSE functions in your applications
  • Unlike high-level languages such as Java and C++, assembly language is much closer to the machine code that actually runs computers; it's used to create programs or modules that are very fast and efficient, as well as in hacking exploits and reverse engineering
  • Covering assembly language in the Pentium microprocessor environment, this code-intensive guide shows programmers how to create stand-alone assembly language programs as well as how to incorporate assembly language libraries or routines into existing high-level applications
  • Demonstrates how to manipulate data, incorporate advanced functions and libraries, and maximize application performance
  • Examples use C as a high-level language, Linux as the development environment, and GNU tools for assembling, compiling, linking, and debugging
دانلود کتاب Professional Assembly Language (Programmer to Programmer)