Professional Assembly Language
Häftad, Engelska, 2005
Av Richard Blum
429 kr
Produktinformation
- Utgivningsdatum2005-02-11
- Mått185 x 234 x 31 mm
- Vikt930 g
- SpråkEngelska
- Antal sidor576
- FörlagJohn Wiley & Sons Inc
- EAN9780764579011
Tillhör följande kategorier
Richard Blum has worked for a large U.S. government organization for more than 15 years. During that time, he has had the opportunity to program utilities in various programming languages: C, C++, Java, and Microsoft VB.NET and C#. With this experience, Rich has often found the benefit of reviewing assembly language code generated by compilers and utilizing assembly language routines to speed up higher-level language programs.Rich has a bachelor of science degree in electrical engineering from Purdue University, where he worked on many assembly language projects. (Of course, this was back in the eight-bit processor days.) He also has a master of science degree in management from Purdue University, specializing in Management Information Systems.
- Acknowledgments xiContents xiiiIntroduction xxiiiChapter 1: What Is Assembly Language? 1Processor Instructions 1Instruction code handling 2Instruction code format 3High-Level Languages 6Types of high-level languages 7High-level language features 9Assembly Language 10Opcode mnemonics 11Defining data 12Directives 14Summary 15Chapter 2: The IA-32 Platform 17Core Parts of an IA-32 Processor 17Control unit 19Execution unit 24Registers 25Flags 29Advanced IA-32 Features 32The x87 floating-point unit 32Multimedia extensions (MMX) 33Streaming SIMD extensions (SSE) 33Hyperthreading 34The IA-32 Processor Family 34Intel processors 35Non-Intel processors 36Summary 37Chapter 3: The Tools of the Trade 39The Development Tools 39The Assembler 40The Linker 42The Debugger 43The Compiler 44The object code disassembler 44The Profiler 44The GNU Assembler 45Installing the assembler 45Using the assembler 47A word about opcode syntax 49The GNU Linker 50The GNU Compiler 53Downloading and installing gcc 53Using gcc 54The GNU Debugger Program 56Downloading and installing gdb 56Using gdb 57The KDE Debugger 60Downloading and installing kdbg 60Using kdbg 60The GNU Objdump Program 62Using objdump 63An objdump example 64The GNU Profiler Program 65Using the profiler 65A profile example 68A Complete Assembly Development System 69The basics of Linux 69Downloading and running MEPIS 70Your new development system 71Summary 72Chapter 4: A Sample Assembly Language Program 73The Parts of a Program 73Defining sections 74Defining the starting point 74Creating a Simple Program 75The CPUID instruction 76The sample program 77Building the executable 80Running the executable 80Assembling using a compiler 80Debugging the Program 81Using gdb 81Using C Library Functions in Assembly 86Using printf 87Linking with C library functions 88Summary 90Chapter 5: Moving Data 91Defining Data Elements 91The data section 91Defining static symbols 94The bss section 95Moving Data Elements 97The MOV instruction formats 97Moving immediate data to registers and memory 98Moving data between registers 99Moving data between memory and registers 99Conditional Move Instructions 106The CMOV instructions 107Using CMOV instructions 109Exchanging Data 110The data exchange instructions 111Using the data exchange instruction 116The Stack 119How the stack works 119PUSHing and POPing data 120PUSHing and POPing all the registers 123Manually using the ESP and EBP registers 123Optimizing Memory Access 123Summary 124Chapter 6: Controlling Execution Flow 127The Instruction Pointer 127Unconditional Branches 129Jumps 129Calls 132Interrupts 135Conditional Branches 136Conditional jump instructions 136The compare instruction 138Examples of using the flag bits 140Loops 144The loop instructions 144A loop example 145Preventing LOOP catastrophes 145Duplicating High-Level Conditional Branches 146if statements 147for loops 150Optimizing Branch Instructions 153Branch prediction 153Optimizing tips 155Summary 158Chapter 7: Using Numbers 161Numeric Data Types 161Integers 162Standard integer sizes 162Unsigned integers 164Signed integers 166Using signed integers 168Extending integers 169Defining integers in GAS 172SIMD Integers 173MMX integers 173Moving MMX integers 174SSE integers 176Moving SSE integers 177Binary Coded Decimal 178What is BCD? 178FPU BCD values 179Moving BCD values 180Floating-Point Numbers 182What are floating-point numbers? 182Standard floating-point data types 184IA-32 floating-point values 186Defining floating-point values in GAS 187Moving floating-point values 187Using preset floating-point values 189SSE floating-point data types 190Moving SSE floating-point values 191Conversions 196Conversion instructions 196A conversion example 198Summary 199Chapter 8: Basic Math Functions 201Integer Arithmetic 201Addition 201Subtraction 210Incrementing and decrementing 215Multiplication 216Division 221Shift Instructions 223Multiply by shifting 224Dividing by shifting 225Rotating bits 226Decimal Arithmetic 227Unpacked BCD arithmetic 227Packed BCD arithmetic 229Logical Operations 231Boolean logic 231Bit testing 232Summary 233Chapter 9: Advanced Math Functions 235The FPU Environment 235The FPU register stack 236The FPU status, control, and tag registers 237Using the FPU stack 242Basic Floating-Point Math 245Advanced Floating-Point Math 249Floating-point functions 249Partial remainders 252Trigonometric functions 254Logarithmic functions 257Floating-Point Conditional Branches 259The FCOM instruction family 260The FCOMI instruction family 262The FCMOV instruction family 263Saving and Restoring the FPU State 265Saving and restoring the FPU environment 265Saving and restoring the FPU state 266Waiting versus Nonwaiting Instructions 269Optimizing Floating-Point Calculations 270Summary 270Chapter 10: Working with Strings 273Moving Strings 273The MOVS instruction 274The REP prefix 278Other REP instructions 283Storing and Loading Strings 283The LODS instruction 283The STOS instruction 284Building your own string functions 285Comparing Strings 286The CMPS instruction 286Using REP with CMPS 288String inequality 289Scanning Strings 291The SCAS instruction 292Scanning for multiple characters 293Finding a string length 295Summary 296Chapter 11: Using Functions 297Defining Functions 297Assembly Functions 299Writing functions 299Accessing functions 302Function placement 304Using registers 304Using global data 304Passing Data Values in C Style 306Revisiting the stack 306Passing function parameters on the stack 306Function prologue and epilogue 308Defining local function data 309Cleaning out the stack 312An example 312Watching the stack in action 314Using Separate Function Files 317Creating a separate function file 317Creating the executable file 318Debugging separate function files 319Using Command-Line Parameters 320The anatomy of a program 320Analyzing the stack 321Viewing command-line parameters 323Viewing environment variables 325An example using command-line parameters 326Summary 328Chapter 12: Using Linux System Calls 329The Linux Kernel 329Parts of the kernel 330Linux kernel version 336System Calls 337Finding system calls 337Finding system call definitions 338Common system calls 339Using System Calls 341The system call format 341Advanced System Call Return Values 346The sysinfo system call 346Using the return structure 347Viewing the results 348Tracing System Calls 349The strace program 349Advanced strace parameters 350Watching program system calls 351Attaching to a running program 353System Calls versus C Libraries 355The C libraries 356Tracing C functions 357Comparing system calls and C libraries 358Summary 359Chapter 13: Using Inline Assembly 361What Is Inline Assembly? 361Basic Inline Assembly Code 365The asm format 365Using global C variables 367Using the volatile modifier 369Using an alternate keyword 369Extended ASM 370Extended ASM format 370Specifying input and output values 370Using registers 372Using placeholders 373Referencing placeholders 376Alternative placeholders 377Changed registers list 377Using memory locations 379Using floating-point values 380Handling jumps 382Using Inline Assembly Code 384What are macros? 384C macro functions 384Creating inline assembly macro functions 386Summary 387Chapter 14: Calling Assembly Libraries 389Creating Assembly Functions 389Compiling the C and Assembly Programs 391Compiling assembly source code files 392Using assembly object code files 392The executable file 393Using Assembly Functions in C Programs 395Using integer return values 396Using string return values 397Using floating-point return values 400Using multiple input values 401Using mixed data type input values 403Using Assembly Functions in C++ Programs 407Creating Static Libraries 408What is a static library? 408The ar command 409Creating a static library file 410Compiling with static libraries 412Using Shared Libraries 412What are shared libraries? 412Creating a shared library 414Compiling with a shared library 414Running programs that use shared libraries 415Debugging Assembly Functions 417Debugging C programs 417Debugging assembly functions 418Summary 420Chapter 15: Optimizing Routines 421Optimized Compiler Code 421Compiler optimization level 1 422Compiler optimization level 2 423Compiler optimization level 3 425Creating Optimized Code 425Generating the assembly language code 425Viewing optimized code 429Recompiling the optimized code 429Optimization Tricks 430Optimizing calculations 430Optimizing variables 433Optimizing loops 437Optimizing conditional branches 442Common subexpression elimination 447Summary 450Chapter 16: Using Files 453The File-Handling Sequence 453Opening and Closing Files 454Access types 455UNIX permissions 456Open file code 458Open error return codes 459Closing files 460Writing to Files 460A simple write example 460Changing file access modes 462Handling file errors 462Reading Files 463A simple read example 464A more complicated read example 465Reading, Processing, and Writing Data 467Memory-Mapped Files 470What are memory-mapped files? 470The mmap system call 471mmap assembly language format 473An mmap example 475Summary 479Chapter 17: Using Advanced IA-32 Features 481A Brief Review of SIMD 481MMX 482SSE 483SSE2 483Detecting Supported SIMD Operations 483Detecting support 484SIMD feature program 485Using MMX Instructions 487Loading and retrieving packed integer values 487Performing MMX operations 488Using SSE Instructions 497Moving data 498Processing data 499Using SSE2 Instructions 504Moving data 505Processing data 505SSE3 Instructions 508Summary 508Index 511