Assembly Language for x86 Processors (6th Edition)

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Assembly Language for x86 Processors, 6/e is ideal for undergraduate courses in assembly language programming and introductory courses in computer systems and computer architecture.   Written specifically for the Intel/Windows/DOS platform, this complete and fully updated study of assembly language teaches students to write and debug programs at the machine level. Based on the Intel processor family, the text simplifies and demystifies concepts that students need to grasp before they can go on to more advanced computer architecture and operating systems courses. Students put theory into practice through writing software at the machine level, creating a memorable experience that gives them the confidence to work in any OS/machine-oriented environment. Proficiency in one other programming language, preferably Java, C, or C++, is recommended.

Author(s): Kip Irvine
Edition: 6th
Publisher: Prentice Hall
Year: 2010

Language: English
Pages: 747
Tags: Информатика и вычислительная техника;Информатика (программирование);Программирование на ASSEMBLER;

Cover......Page 1
Assembly Language for x86 Processors (Sixth edition)......Page 2
9780136022121......Page 3
Contents......Page 6
Preface......Page 20
About the Author......Page 28
1.1 Welcome to Assembly Language......Page 30
1.1.1 Good Questions to Ask......Page 31
1.1.2 Assembly Language Applications......Page 34
1.1.3 Section Review......Page 35
1.2 Virtual Machine Concept......Page 36
1.3.1 Binary Integers......Page 38
1.3.2 Binary Addition......Page 40
1.3.3 Integer Storage Sizes......Page 41
1.3.4 Hexadecimal Integers......Page 42
1.3.5 Signed Integers......Page 44
1.3.6 Character Storage......Page 46
1.3.7 Section Review......Page 48
1.4 Boolean Operations......Page 51
1.4.1 Truth Tables for Boolean Functions......Page 53
1.5 Chapter Summary......Page 55
1.6.2 Nonprogramming Tasks......Page 56
2.1 General Concepts......Page 58
2.1.1 Basic Microcomputer Design......Page 59
2.1.2 Instruction Execution Cycle......Page 60
2.1.3 Reading from Memory......Page 62
2.1.4 How Programs Run......Page 63
2.1.5 Section Review......Page 64
2.2.2 Basic Execution Environment......Page 65
2.2.4 Overview of Intel Microprocessors......Page 68
2.2.5 Section Review......Page 71
2.3.1 Real-Address Mode......Page 72
2.3.2 Protected Mode......Page 74
2.3.3 Section Review......Page 76
2.4.1 Motherboard......Page 77
2.4.4 Input-Output Ports and Device Interfaces......Page 79
2.5.1 Levels of I/O Access......Page 81
2.6 Chapter Summary......Page 84
2.7 Chapter Exercises......Page 86
3.1 Basic Elements of Assembly Language......Page 87
3.1.1 Integer Constants......Page 88
3.1.2 Integer Expressions......Page 89
3.1.5 String Constants......Page 90
3.1.8 Directives......Page 91
3.1.9 Instructions......Page 92
3.1.10 The NOP (No Operation) Instruction......Page 94
3.2 Example: Adding and Subtracting Integers......Page 95
3.2.1 Alternative Version of AddSub......Page 98
3.2.3 Section Review......Page 99
3.3.1 The Assemble-Link-Execute Cycle......Page 100
3.4.2 Data Definition Statement......Page 106
3.4.3 Defining BYTE and SBYTE Data......Page 107
3.4.4 Defining WORD and SWORD Data......Page 109
3.4.6 Defining QWORD Data......Page 110
3.4.7 Defining Packed Binary Coded Decimal (TBYTE) Data......Page 111
3.4.9 Little Endian Order......Page 112
3.4.10 Adding Variables to the AddSub Program......Page 113
3.4.12 Section Review......Page 114
3.5.1 Equal-Sign Directive......Page 115
3.5.2 Calculating the Sizes of Arrays and Strings......Page 116
3.5.3 EQU Directive......Page 117
3.5.4 TEXTEQU Directive......Page 118
3.6.1 Basic Changes......Page 119
3.7 Chapter Summary......Page 120
3.8 Programming Exercises......Page 121
4.1.1 Introduction......Page 123
4.1.2 Operand Types......Page 124
4.1.4 MOV Instruction......Page 125
4.1.5 Zero/Sign Extension of Integers......Page 127
4.1.7 XCHG Instruction......Page 129
4.1.8 Direct-Offset Operands......Page 130
4.1.9 Example Program (Moves)......Page 131
4.1.10 Section Review......Page 132
4.2.2 ADD Instruction......Page 133
4.2.4 NEG Instruction......Page 134
4.2.6 Flags Affected by Addition and Subtraction......Page 135
4.2.7 Example Program (AddSub3)......Page 139
4.2.8 Section Review......Page 140
4.3.1 OFFSET Operator......Page 141
4.3.2 ALIGN Directive......Page 142
4.3.3 PTR Operator......Page 143
4.3.5 LENGTHOF Operator......Page 144
4.3.7 LABEL Directive......Page 145
4.4 Indirect Addressing......Page 146
4.4.1 Indirect Operands......Page 147
4.4.2 Arrays......Page 148
4.4.3 Indexed Operands......Page 149
4.4.4 Pointers......Page 150
4.4.5 Section Review......Page 152
4.5.2 LOOP Instruction......Page 153
4.5.4 Copying a String......Page 155
4.5.5 Section Review......Page 156
4.6 Chapter Summary......Page 157
4.7 Programming Exercises......Page 158
5.2 Linking to an External Library......Page 161
5.2.1 Background Information......Page 162
5.3 The Book’s Link Library......Page 163
5.3.1 Overview......Page 165
5.3.2 Individual Procedure Descriptions......Page 166
5.3.3 Library Test Programs......Page 178
5.4 Stack Operations......Page 186
5.4.1 Runtime Stack......Page 187
5.4.2 PUSH and POP Instructions......Page 189
5.4.3 Section Review......Page 191
5.5.1 PROC Directive......Page 192
5.5.2 CALL and RET Instructions......Page 194
5.5.3 Example: Summing an Integer Array......Page 197
5.5.4 Flowcharts......Page 198
5.5.5 Saving and Restoring Registers......Page 199
5.5.6 Section Review......Page 200
5.6 Program Design Using Procedures......Page 201
5.6.1 Integer Summation Program (Design)......Page 202
5.6.2 Integer Summation Implementation......Page 204
5.7 Chapter Summary......Page 206
5.8 Programming Exercises......Page 207
6.1 Introduction......Page 209
6.2 Boolean and Comparison Instructions......Page 210
6.2.2 AND Instruction......Page 211
6.2.3 OR Instruction......Page 212
6.2.4 Bit-Mapped Sets......Page 213
6.2.5 XOR Instruction......Page 215
6.2.7 TEST Instruction......Page 216
6.2.8 CMP Instruction......Page 217
6.2.10 Section Review......Page 218
6.3.1 Conditional Structures......Page 219
6.3.2 Jcond Instruction......Page 220
6.3.3 Types of Conditional Jump Instructions......Page 221
6.3.4 Conditional Jump Applications......Page 224
6.3.5 Section Review......Page 228
6.4.1 LOOPZ and LOOPE Instructions......Page 229
6.4.3 Section Review......Page 230
6.5.1 Block-Structured IF Statements......Page 231
6.5.2 Compound Expressions......Page 233
6.5.3 WHILE Loops......Page 235
6.5.4 Table-Driven Selection......Page 237
6.5.5 Section Review......Page 239
6.6.1 Validating an Input String......Page 240
6.6.2 Validating a Signed Integer......Page 241
6.6.3 Section Review......Page 245
6.7 Conditional Control Flow Directives......Page 246
6.7.1 Creating IF Statements......Page 247
6.7.2 Signed and Unsigned Comparisons......Page 248
6.7.3 Compound Expressions......Page 249
6.7.4 Creating Loops with .REPEAT and .WHILE......Page 252
6.8 Chapter Summary......Page 253
6.9 Programming Exercises......Page 254
7.1 Introduction......Page 258
7.2.1 Logical Shifts and Arithmetic Shifts......Page 259
7.2.2 SHL Instruction......Page 260
7.2.3 SHR Instruction......Page 261
7.2.4 SAL and SAR Instructions......Page 262
7.2.5 ROL Instruction......Page 263
7.2.7 RCL and RCR Instructions......Page 264
7.2.9 SHLD/SHRD Instructions......Page 265
7.2.10 Section Review......Page 267
7.3 Shift and Rotate Applications......Page 268
7.3.1 Shifting Multiple Doublewords......Page 269
7.3.2 Binary Multiplication......Page 270
7.3.4 Isolating MS-DOS File Date Fields......Page 271
7.4.1 MUL Instruction......Page 272
7.4.2 IMUL Instruction......Page 274
7.4.3 Measuring Program Execution Times......Page 276
7.4.4 DIV Instruction......Page 278
7.4.5 Signed Integer Division......Page 279
7.4.6 Implementing Arithmetic Expressions......Page 282
7.4.7 Section Review......Page 284
7.5.1 ADC Instruction......Page 285
7.5.2 Extended Addition Example......Page 286
7.5.3 SBB Instruction......Page 287
7.5.4 Section Review......Page 288
7.6 ASCII and Unpacked Decimal Arithmetic......Page 289
7.6.1 AAA Instruction......Page 290
7.6.2 AAS Instruction......Page 291
7.6.4 AAD Instruction......Page 292
7.7.1 DAA Instruction......Page 293
7.8 Chapter Summary......Page 295
7.9 Programming Exercises......Page 296
8.1 Introduction......Page 299
8.2 Stack Frames......Page 300
8.2.1 Stack Parameters......Page 301
8.2.2 Accessing Stack Parameters......Page 302
8.2.3 Local Variables......Page 310
8.2.4 ENTER and LEAVE Instructions......Page 314
8.2.5 LOCAL Directive......Page 315
8.2.6 Section Review......Page 318
8.3 Recursion......Page 319
8.3.1 Recursively Calculating a Sum......Page 320
8.3.2 Calculating a Factorial......Page 321
8.3.3 Section Review......Page 327
8.4.1 INVOKE Directive......Page 328
8.4.2 ADDR Operator......Page 329
8.4.3 PROC Directive......Page 330
8.4.4 PROTO Directive......Page 333
8.4.6 Example: Exchanging Two Integers......Page 336
8.4.7 Debugging Tips......Page 337
8.4.8 WriteStackFrame Procedure......Page 338
8.4.9 Section Review......Page 339
8.5.1 Hiding and Exporting Procedure Names......Page 340
8.5.2 Calling External Procedures......Page 341
8.5.3 Using Variables and Symbols across Module Boundaries......Page 342
8.5.5 Creating the Modules Using Extern......Page 343
8.5.6 Creating the Modules Using INVOKE and PROTO......Page 347
8.6.1 Java Virtual Machine......Page 350
8.6.2 Instruction Set......Page 351
8.6.3 Java Disassembly Examples......Page 352
8.7 Chapter Summary......Page 357
8.8 Programming Exercises......Page 358
9.1 Introduction......Page 361
9.2 String Primitive Instructions......Page 362
9.2.1 MOVSB, MOVSW, and MOVSD......Page 363
9.2.2 CMPSB, CMPSW, and CMPSD......Page 364
9.2.4 STOSB, STOSW, and STOSD......Page 365
9.2.6 Section Review......Page 366
9.3.1 Str_compare Procedure......Page 367
9.3.2 Str_length Procedure......Page 368
9.3.4 Str_trim Procedure......Page 369
9.3.5 Str_ucase Procedure......Page 372
9.3.6 String Library Demo Program......Page 373
9.4.1 Ordering of Rows and Columns......Page 375
9.4.2 Base-Index Operands......Page 376
9.4.3 Base-Index-Displacement Operands......Page 378
9.5.1 Bubble Sort......Page 379
9.5.2 Binary Search......Page 381
9.6 Java Bytecodes: String Processing......Page 388
9.7 Chapter Summary......Page 389
9.8 Programming Exercises......Page 390
10.1 Structures......Page 395
10.1.1 Defining Structures......Page 396
10.1.2 Declaring Structure Variables......Page 397
10.1.3 Referencing Structure Variables......Page 399
10.1.4 Example: Displaying the System Time......Page 401
10.1.6 Example: Drunkard’s Walk......Page 404
10.1.7 Declaring and Using Unions......Page 407
10.1.8 Section Review......Page 410
10.2.2 Defining Macros......Page 411
10.2.3 Invoking Macros......Page 412
10.2.4 Additional Macro Features......Page 413
10.2.5 Using the Book’s Macro Library......Page 417
10.2.6 Example Program: Wrappers......Page 423
10.2.7 Section Review......Page 424
10.3 Conditional-Assembly Directives......Page 425
10.3.1 Checking for Missing Arguments......Page 426
10.3.2 Default Argument Initializers......Page 427
10.3.4 IF, ELSE, and ENDIF Directives......Page 428
10.3.5 The IFIDN and IFIDNI Directives......Page 429
10.3.6 Example: Summing a Matrix Row......Page 430
10.3.7 Special Operators......Page 433
10.3.8 Macro Functions......Page 436
10.3.9 Section Review......Page 438
10.4.2 REPEAT Directive......Page 439
10.4.3 FOR Directive......Page 440
10.4.5 Example: Linked List......Page 441
10.4.6 Section Review......Page 443
10.5 Chapter Summary......Page 444
10.6 Programming Exercises......Page 445
11.1 Win32 Console Programming......Page 448
11.1.1 Background Information......Page 449
11.1.2 Win32 Console Functions......Page 453
11.1.3 Displaying a Message Box......Page 455
11.1.4 Console Input......Page 458
11.1.5 Console Output......Page 464
11.1.6 Reading and Writing Files......Page 466
11.1.7 File I/O in the Irvine32 Library......Page 471
11.1.8 Testing the File I/O Procedures......Page 473
11.1.9 Console Window Manipulation......Page 476
11.1.10 Controlling the Cursor......Page 479
11.1.11 Controlling the Text Color......Page 480
11.1.12 Time and Date Functions......Page 482
11.1.13 Section Review......Page 485
11.2 Writing a Graphical Windows Application......Page 486
11.2.1 Necessary Structures......Page 487
11.2.2 The MessageBox Function......Page 488
11.2.4 The WinProc Procedure......Page 489
11.2.6 Program Listing......Page 490
11.2.7 Section Review......Page 494
11.3 Dynamic Memory Allocation......Page 495
11.3.1 HeapTest Programs......Page 498
11.4.1 Linear Addresses......Page 502
11.4.2 Page Translation......Page 506
11.5 Chapter Summary......Page 508
11.6 Programming Exercises......Page 510
12.1 Floating-Point Binary Representation......Page 512
12.1.1 IEEE Binary Floating-Point Representation......Page 513
12.1.2 The Exponent......Page 514
12.1.4 Creating the IEEE Representation......Page 515
12.1.5 Converting Decimal Fractions to Binary Reals......Page 517
12.2 Floating-Point Unit......Page 519
12.2.1 FPU Register Stack......Page 520
12.2.2 Rounding......Page 522
12.2.4 Floating-Point Instruction Set......Page 524
12.2.5 Arithmetic Instructions......Page 527
12.2.6 Comparing Floating-Point Values......Page 531
12.2.7 Reading and Writing Floating-Point Values......Page 533
12.2.8 Exception Synchronization......Page 535
12.2.9 Code Examples......Page 536
12.2.10 Mixed-Mode Arithmetic......Page 537
12.2.11 Masking and Unmasking Exceptions......Page 538
12.2.12 Section Review......Page 540
12.3.1 Instruction Format......Page 541
12.3.2 Single-Byte Instructions......Page 542
12.3.4 Register-Mode Instructions......Page 543
12.3.5 Processor Operand-Size Prefix......Page 544
12.3.6 Memory-Mode Instructions......Page 545
12.3.7 Section Review......Page 548
12.4 Chapter Summary......Page 549
12.5 Programming Exercises......Page 550
13.1 Introduction......Page 554
13.1.1 General Conventions......Page 555
13.1.2 .MODEL Directive......Page 556
13.2.1 __asm Directive in Microsoft Visual C++......Page 558
13.2.2 File Encryption Example......Page 561
13.3 Linking to C/C++ in Protected Mode......Page 564
13.3.1 Using Assembly Language to Optimize C++ Code......Page 565
13.3.2 Calling C and C++ Functions......Page 571
13.3.3 Multiplication Table Example......Page 573
13.3.4 Calling C Library Functions......Page 576
13.3.5 Directory Listing Program......Page 579
13.4 Linking to C/C++ in Real-Address Mode......Page 581
13.4.1 Linking to Borland C++......Page 582
13.4.2 ReadSector Example......Page 583
13.4.3 Example: Large Random Integers......Page 587
13.4.4 Section Review......Page 588
13.6 Programming Exercises......Page 589
14.1 MS-DOS and the IBM-PC......Page 591
14.1.1 Memory Organization......Page 592
14.1.2 Redirecting Input-Output......Page 593
14.1.4 INT Instruction......Page 594
14.1.5 Coding for 16-Bit Programs......Page 596
14.2 MS-DOS Function Calls (INT 21h)......Page 597
14.2.1 Selected Output Functions......Page 599
14.2.2 Hello World Program Example......Page 601
14.2.3 Selected Input Functions......Page 602
14.2.4 Date/Time Functions......Page 606
14.3 Standard MS-DOS File I/O Services......Page 610
14.3.1 Create or Open File (716Ch)......Page 612
14.3.3 Move File Pointer (42h)......Page 613
14.3.5 Selected Library Procedures......Page 614
14.3.6 Example: Read and Copy a Text File......Page 615
14.3.7 Reading the MS-DOS Command Tail......Page 617
14.3.8 Example: Creating a Binary File......Page 620
14.4 Chapter Summary......Page 623
14.5 Programming Exercises......Page 625
Appendix A MASM Reference......Page 627
Appendix B The x86 Instruction Set......Page 649
Appendix C Answers to Review Questions......Page 684
Index......Page 728