资源大小: 4.01MB
发布时间: 2013-01-16
文件格式: pdf
下载次数: 1
分享到:

下载地址:

下载地址1
(本站为飞网专业下载站,域名:down.cfei.net)

资源简介:

中文名: 一步一步学习linux汇编语言程序设计原名: Assembly Language Step-by-Step - Programming with Linux,作者: Jeff Duntemann资源格式: PDF版本: 第三版出版社: Wiley Publishing,Inc书号: 978-0-470-49702-9发行时间: 2009年10月地区: 美国语言: 英文简介: Jeff Duntemann "Assembly Language Step-by-Step: Programming with Linux, 3rd Edition"October 2009 | English | ISBN-13: 978-0-470-49702-9 | 645 Pages | PDF | 6.65 MB这本大家期待已久的畅销书的新版本是介绍x86汇编语言的书籍The eagerly anticipated new edition of the bestselling introduction to x86 assembly language这本大家等待已久的新版本的介绍汇编语言的畅销书已经完成,它被重写并且集中于32位的保护模式linux 和自由的NASM汇编语言编辑器。汇编语言是起人类的思想和纯硅头脑的计算机沟通的桥梁,并且很受欢迎的作者jeff dunteman仍然保留这他那独特的令人愉悦的写作风格并呈现在一步一步接近这最难懂的技术规则。The long-awaited third edition of thjis bestselling introduction to assembly language has been completely rewritten to focus on 32-bit protected-mode Linux and the free NASM assembler. Assembly is the fundamental language bridging human ideas and the pure silicon hearts of computers, and popular author Jeff Dunteman retains his distinctive lighthearted style as he presents a step-by-step approach to this difficult technical discipline.作者开篇,从最编程基础开始介绍:2进制和16进制系统,英特尔x86计算机构架,和linux下的软件开发过程。在刺激初上他系统地介绍了x86指令集,内存编址,编程过程,宏,和linux之上的 c 语言库接口He starts at the very beginning, explaining the basic ideas of programmable computing, the binary and hexadecimal number systems, the Intel x86 computer architecture, and the process of software development under Linux. From that foundation he systematically treats the x86 instruction set, memory addressing, procedures, macros, and interface to the C-language code libraries upon which Linux itself is built.遵从于介绍x86汇编概念的想法,着眼于从理解cpu运作来学习汇编语言Serves as an ideal introduction to x86 computing concepts, as demonstrated by the only language directly understood by the CPU itself使用易于理解,谈话式的风格来面向假设读者没有任何语言经验的人讲解。Uses an approachable, conversational style that assumes no prior experience in programming of any kindPresents x86 architecture and assembly concepts through a cumulative tutorial approach that is ideal for self-paced instructionFocuses entirely on free, open-source software, including Ubuntu Linux, the NASM assembler, the Kate editor, and the Gdb/Insight debugger.Includes an x86 instruction set reference for the most common machine instructions, specifically tailored for use by programming beginnersWoven into the presentation are plenty of assembly code examples, plus practical tips on software design, coding, testing, and debugging, all using free, open-source software that may be downloaded without charge from the Internet.Assembly Language Step-by-Step: Programming with Linux, 3rd Edition 目录: ContentsIntroduction: ‘‘Why Would You Want to Do That?’’ xxviiChapter 1 Another Pleasant Valley Saturday 1It’s All in the Plan 1Steps and Tests 2More Than Two Ways? 3Computers Think Like Us 4Had This Been the Real Thing . . . 4Do Not Pass Go 5The Game of Big Bux 6Playing Big Bux 8Assembly Language Programming As a Board Game 9Code and Data 10Addresses 11Metaphor Check! 12Chapter 2 Alien Bases 15The Return of the New Math Monster 15Counting in Martian 16Dissecting a Martian Number 18The Essence of a Number Base 20Octal: How the Grinch Stole Eight and Nine 20Who Stole Eight and Nine? 21Hexadecimal: Solving the Digit Shortage 24From Hex to Decimal and from Decimal to Hex 28From Hex to Decimal 28From Decimal to Hex 29Practice. Practice! PRACTICE! 31xvxvi ContentsArithmetic in Hex 32Columns and Carries 35Subtraction and Borrows 35Borrows across Multiple Columns 37What’s the Point? 38Binary 38Values in Binary 40Why Binary? 42Hexadecimal As Shorthand for Binary 43Prepare to Compute 44Chapter 3 Lifting the Hood 45RAXie, We Hardly Knew Ye . . . 45Gus to the Rescue 46Switches, Transistors, and Memory 47One If by Land . . . 48Transistor Switches 48The Incredible Shrinking Bit 50Random Access 52Memory Access Time 53Bytes, Words, Double Words, and Quad Words 54Pretty Chips All in a Row 55The Shop Foreman and the Assembly Line 57Talking to Memory 58Riding the Data Bus 59The Foreman’s Pockets 60The Assembly Line 61The Box That Follows a Plan 61Fetch and Execute 63The Foreman’s Innards 64Changing Course 65What vs. How: Architecture and Microarchitecture 66Evolving Architectures 67The Secret Machinery in the Basement 68Enter the Plant Manager 70Operating Systems: The Corner Office 70BIOS: Software, Just Not as Soft 71Multitasking Magic 71Promotion to Kernel 73The Core Explosion 73The Plan 74Contents xviiChapter 4 Location, Location, Location 77The Joy of Memory Models 7716 Bits’ll Buy You 64K 79The Nature of a Megabyte 82Backward Compatibility and Virtual 86 Mode 8316-Bit Blinders 83The Nature of Segments 85A Horizon, Not a Place 88Making 20-Bit Addresses out of 16-Bit Registers 8816-Bit and 32-Bit Registers 90General-Purpose Registers 91Register Halves 93The Instruction Pointer 95The Flags Register 96The Three Major Assembly Programming Models 96Real Mode Flat Model 97Real Mode Segmented Model 99Protected Mode Flat Model 101What Protected Mode Won’t Let Us Do Anymore 104Memory-Mapped Video 104Direct Access to Port Hardware 105Direct Calls into the BIOS 106Looking Ahead: 64-Bit ‘‘Long Mode’’ 10664-Bit Memory: What May Be Possible Someday vs.What We Can Do Now 107Chapter 5 The Right to Assemble 109Files and What’s Inside Them 110Binary Files vs. Text Files 111Looking at File Internals with the Bless Editor 112Interpreting Raw Data 116‘‘Endianness’’ 117Text In, Code Out 121Assembly Language 121Comments 124Beware ‘‘Write-Only’’ Source Code! 124Object Code and Linkers 125Relocatability 128The Assembly Language Development Process 128The Discipline of Working Directories 129Editing the Source Code File 131xviii ContentsAssembling the Source Code File 131Assembler Errors 132Back to the Editor 133Assembler Warnings 134Linking the Object Code File 135Linker Errors 136Testing the .EXE File 136Errors versus Bugs 137Are We There Yet? 138Debuggers and Debugging 138Taking a Trip Down Assembly Lane 139Installing the Software 139Step 1: Edit the Program in an Editor 142Step 2: Assemble the Program with NASM 143Step 3: Link the Program with LD 146Step 4: Test the Executable File 147Step 5: Watch It Run in the Debugger 147Ready to Get Serious? 153Chapter 6 A Place to Stand, with Access to Tools 155The Kate Editor 157Installing Kate 157Launching Kate 158Configuration 160Kate Sessions 162Creating a New Session 162Opening an Existing Session 163Deleting or Renaming Sessions 163Kate’s File Management 164Filesystem Browser Navigation 165Adding a File to the Current Session 165Dropping a File from the Current Session 166Switching Between Session Files in the Editor 166Creating a Brand-New File 166Creating a Brand-New Folder on Disk 166Deleting a File from Disk (Move File to Trash) 166Reloading a File from Disk 167Saving All Unsaved Changes in Session Files 167Printing the File in the Editor Window 167Exporting a File As HTML 167Adding Items to the Toolbar 167Kate’s Editing Controls 168Cursor Movement 169Bookmarks 169Selecting Text 170Contents xixSearching the Text 171Using Search and Replace 172Using Kate While Programming 172Creating and Using Project Directories 173Focus! 175Linux and Terminals 176The Linux Console 176Character Encoding in Konsole 177The Three Standard Unix Files 178I/O Redirection 180Simple Text Filters 182Terminal Control with Escape Sequences 183So Why Not GUI Apps? 185Using Linux Make 186Dependencies 187When a File Is Up to Date 189Chains of Dependencies 189Invoking Make from Inside Kate 191Using Touch to Force a Build 193The Insight Debugger 194Running Insight 195Insight’s Many Windows 195A Quick Insight Run-Through 197Pick Up Your Tools . . . 200Chapter 7 Following Your Instructions 201Build Yourself a Sandbox 201A Minimal NASM Program 202Instructions and Their Operands 204Source and Destination Operands 204Immediate Data 205Register Data 207Memory Data 209Confusing Data and Its Address 210The Size of Memory Data 211The Bad Old Days 211Rally Round the Flags, Boys! 212Flag Etiquette 215Adding and Subtracting One with INC and DEC 215Watching Flags from Insight 216How Flags Change Program Execution 218Signed and Unsigned Values 221Two’s Complement and NEG 221Sign Extension and MOVSX 224xx ContentsImplicit Operands and MUL 225MUL and the Carry Flag 227Unsigned Division with DIV 228The x86 Slowpokes 229Reading and Using an Assembly Language Reference 230Memory Joggers for Complex Memories 230An Assembly Language Reference for Beginners 231Flags 232NEG: Negate (Two’s Complement; i.e., Multiply by -1) 233Flags affected 233Legal forms 233Examples 233Notes 233Legal Forms 234Operand Symbols 234Examples 235235NotesWhat’s Not Here . . . 235Chapter 8 Our Object All Sublime 237The Bones of an Assembly Language Program 237The Initial Comment Block 239The .data Section 240The .bss Section 240The .text Section 241Labels 241Variables for Initialized Data 242String Variables 242244Deriving String Length with EQU and $Last In, First Out via the Stack 246Five Hundred Plates per Hour 246Stacking Things Upside Down 248Push-y Instructions 249POP Goes the Opcode 251Storage for the Short Term 253Using Linux Kernel Services Through INT80 254An Interrupt That Doesn’t Interrupt Anything 254Getting Home Again 259Exiting a Program via INT 80h 260Software Interrupts versus Hardware Interrupts 261INT 80h and the Portability Fetish 262Designing a Non-Trivial Program 264Defining the Problem 264Starting with Pseudo-code 265Contents xxiSuccessive Refinement 266Those Inevitable ‘‘Whoops!’’ Moments 270Scanning a Buffer 271‘‘Off By One’’ Errors 273Going Further 277Chapter 9 Bits, Flags, Branches, and Tables 279Bits Is Bits (and Bytes Is Bits) 279Bit Numbering 280‘‘It’s the Logical Thing to Do, Jim. . .’’ 280The AND Instruction 281Masking Out Bits 282The OR Instruction 283The XOR Instruction 284The NOT Instruction 285Segment Registers Don’t Respond to Logic! 285Shifting Bits 286Shift By What? 286How Bit Shifting Works 287Bumping Bits into the Carry Flag 287The Rotate Instructions 288Setting a Known Value into the Carry Flag 289Bit-Bashing in Action 289Splitting a Byte into Two Nybbles 292Shifting the High Nybble into the Low Nybble 293Using a Lookup Table 293Multiplying by Shifting and Adding 295Flags, Tests, and Branches 298Unconditional Jumps 298Conditional Jumps 299Jumping on the Absence of a Condition 300Flags 301Comparisons with CMP 301A Jungle of Jump Instructions 302‘‘Greater Than‘‘ Versus ’’Above’’ 303Looking for 1-Bits with TEST 304306Looking for 0 Bits with BTProtected Mode Memory Addressing in Detail 307Effective Address Calculations 308Displacements 309Base + Displacement Addressing 310Base + Index Addressing 310Index × Scale + Displacement Addressing 312Other Addressing Schemes 313xxii ContentsLEA: The Top-Secret Math Machine 315The Burden of 16-Bit Registers 317Character Table Translation 318Translation Tables 318Translating with MOV or XLAT 320Tables Instead of Calculations 325Chapter 10 Dividing and Conquering 327Boxes within Boxes 328Procedures As Boxes for Code 329Calling and Returning 336Calls within Calls 338The Dangers of Accidental Recursion 340A Flag Etiquette Bug to Beware Of 341Procedures and the Data They Need 342Saving the Caller’s Registers 343Local Data 346More Table Tricks 347Placing Constant Data in Procedure Definitions 349Local Labels and the Lengths of Jumps 350’’Forcing’’ Local Label Access 353Short, Near, and Far Jumps 354Building External Procedure Libraries 355Global and External Declarations 356The Mechanics of Globals and Externals 357Linking Libraries into Your Programs 365The Dangers of Too Many Procedures and Too ManyLibraries 366The Art of Crafting Procedures 367Maintainability and Reuse 367Deciding What Should Be a Procedure 368Use Comment Headers! 370Simple Cursor Control in the Linux Console 371Console Control Cautions 377Creating and Using Macros 378The Mechanics of Macro Definition 379Defining Macros with Parameters 385The Mechanics of Invoking Macros 386Local Labels Within Macros 387Macro Libraries As Include Files 388Macros versus Procedures: Pros and Cons 389Contents xxiiiChapter 11 Strings and Things 393The Notion of an Assembly Language String 393Turning Your ‘‘String Sense’’ Inside-Out 394Source Strings and Destination Strings 395A Text Display Virtual Screen 395REP STOSB, the Software Machine Gun 402Machine-Gunning the Virtual Display 403Executing the STOSB Instruction 404STOSB and the Direction Flag (DF) 405Defining Lines in the Display Buffer 406Sending the Buffer to the Linux Console 406The Semiautomatic Weapon: STOSB without REP 407Who Decrements ECX? 407The LOOP Instructions 408Displaying a Ruler on the Screen 409MUL Is Not IMUL 410Adding ASCII Digits 411Adjusting AAA’s Adjustments 413Ruler’s Lessons 41416-bit and 32-bit Versions of STOS 414MOVSB: Fast Block Copies 414DF and Overlapping Block Moves 416Single-Stepping REP String Instructions with Insight 418Storing Data to Discontinuous Strings 419Displaying an ASCII Table 419Nested Instruction Loops 420Jumping When ECX Goes to 0 421Closing the Inner Loop 421Closing the Outer Loop 422Showchar Recap 423Command-Line Arguments and Examining the Stack 424Virtual Memory in Two Chunks 424Anatomy of the Linux Stack 427Why Stack Addresses Aren’t Predictable 429Setting Command-Line Arguments with Insight 429Examining the Stack with Insight’s Memory View 430String Searches with SCASB 432REPNE vs. REPE 435Pop the Stack or Address It? 436For Extra Credit . . . 438xxiv ContentsChapter 12 Heading Out to C 439What’s GNU? 440The Swiss Army Compiler 441Building Code the GNU Way 441How to Use gcc in Assembly Work 443Why Not gas? 444Linking to the Standard C Library 445C Calling Conventions 446A Framework to Build On 447Saving and Restoring Registers 447Setting Up a Stack Frame 448Destroying a Stack Frame 450Characters Out via puts() 451Formatted Text Output with printf() 452Passing Parameters to printf() 454Data In with fgets() and scanf() 456Using scanf() for Entry of Numeric Values 458Be a Time Lord 462The C Library’s Time Machine 462Fetching time_t Values from the System Clock 464Converting a time_t Value to a Formatted String 464Generating Separate Local Time Values 465Making a Copy of glibc’s tm Struct with MOVSD 466Understanding AT&T Instruction Mnemonics 470AT&T Mnemonic Conventions 470Examining gas Source Files Created by gcc 471AT&T Memory Reference Syntax 474Generating Random Numbers 475Seeding the Generator with srand() 476Generating Pseudorandom Numbers 477Some Bits Are More Random Than Others 482Calls to Addresses in Registers 483How C Sees Command-Line Arguments 484Simple File I/O 487Converting Strings into Numbers with sscanf() 487Creating and Opening Files 489Reading Text from Files with fgets() 490Writing Text to Files with fprintf() 493Notes on Gathering Your Procedures into Libraries 494Conclusion: Not the End, But Only the Beginning 503Where to Now? 504Stepping off Square One 506Contents xxvAppenix A Partial x86 Instruction Set Reference 507Notes on the Instruction Set Reference 510AAA: Adjust AL after BCD Addition 512ADC: Arithmetic Addition with Carry 513ADD: Arithmetic Addition 515AND: Logical AND 517BT: Bit Test 519CALL: Call Procedure 521CLC: Clear Carry Flag (CF) 523CLD: Clear Direction Flag (DF) 524CMP: Arithmetic Comparison 525DEC: Decrement Operand 527DIV: Unsigned Integer Division 528INC: Increment Operand 529INT: Software Interrupt 530531IRET: Return from InterruptJ?: Jump on Condition 532JCXZ: Jump If CX=0 534JECXZ: Jump If ECX=0 535536JMP: Unconditional JumpLEA: Load Effective Address 537LOOP: Loop until CX/ECX=0 538LOOPNZ/LOOPNE: Loop While CX/ECX > 0 and ZF=0 540LOOPZ/LOOPE: Loop While CX/ECX > 0 and ZF=1 541MOV: Move (Copy) Right Operand into Left Operand 542544MOVS: Move StringMOVSX: Move (Copy) with Sign Extension 546MUL: Unsigned Integer Multiplication 547NEG: Negate (Two’s Complement; i.e., Multiply by -1) 549NOP: No Operation 550NOT: Logical NOT (One’s Complement) 551OR: Logical OR 552POP: Pop Top of Stack into Operand 554POPA/POPAD: Pop All GP Registers 555POPF: Pop Top of Stack into 16-Bit Flags 556POPFD: Pop Top of Stack into EFlags 557PUSH: Push Operand onto Top of Stack 558PUSHA: Push All 16-Bit GP Registers 559PUSHAD: Push All 32-Bit GP Registers 560PUSHF: Push 16-Bit Flags onto Stack 561PUSHFD: Push 32-Bit EFlags onto Stack 562RET: Return from Procedure 563ROL: Rotate Left 564xxvi ContentsROR: Rotate Right 566SBB: Arithmetic Subtraction with Borrow 568SHL: Shift Left 570SHR: Shift Right 572STC: Set Carry Flag (CF) 574STD: Set Direction Flag (DF) 575STOS: Store String 576SUB: Arithmetic Subtraction 577XCHG: Exchange Operands 579XLAT: Translate Byte via Table 580XOR: Exclusive Or 581Appendix B Character Set Charts 583Index 587


飞网下载站,免费下载共享资料,内容涉及教育资源、专业资料、IT资源、娱乐生活、经济管理、办公文书、游戏资料等。