Art of Assembly Language - The Art of Assembly Language The...

This preview shows page 1 out of 1426 pages.

Unformatted text preview: The Art of Assembly Language The Art of Assembly Language (Brief Contents) Forward Why Would Anyone Learn This Stuff? ................................................................ 1 Section One: ...................................................................................................................... 9 Chapter One Data Representation ..................................................................................... 11 Chapter Two Boolean Algebra .......................................................................................... 43 Chapter Three System Organization .................................................................................. 83 Chapter Four Memory Layout and Access ......................................................................... 145 Section Two: ...................................................................................................................... 193 Chapter Five Variables and Data Structures ...................................................................... 195 Chapter Six The 80x86 Instruction Set ............................................................................... 243 Chapter Seven The UCR Standard Library ......................................................................... 333 Chapter Eight MASM: Directives & Pseudo-Opcodes ....................................................... 355 Chapter Nine Arithmetic and Logical Operations ............................................................. 459 Chapter 10 Control Structures ............................................................................................ 521 Chapter 11 Procedures and Functions ............................................................................... 565 Section Three: .................................................................................................................... 637 Chapter 12 Procedures: Advanced Topics ......................................................................... 639 Chapter 13 MS-DOS, PC-BIOS, and File I/O ..................................................................... 699 Chapter 14 Floating Point Arithmetic ................................................................................. 771 Chapter 15 Strings and Character Sets ............................................................................... 819 Chapter 16 Pattern Matching .............................................................................................. 883 Section Four: ...................................................................................................................... 993 Chapter 17 Interrupts, Traps, and Exceptions ................................................................... 995 Chapter 18 Resident Programs ........................................................................................... 1025 Chapter 19 Processes, Coroutines, and Concurrency ....................................................... 1065 Section Five: ...................................................................................................................... 1151 Chapter 20 The PC Keyboard ............................................................................................. 1153 Chapter 21 The PC Parallel Ports ....................................................................................... 1199 Chapter 22 The PC Serial Ports .......................................................................................... 1223 Chapter 23 The PC Video Display ..................................................................................... 1247 Chapter 24 The PC Game Adapter ..................................................................................... 1255 Section Six: ........................................................................................................................ 1309 Chapter 25 Optimizing Your Programs ............................................................................. 1311 Section Seven: ................................................................................................................... 1343 Appendix A: ASCII/IBM Character Set ............................................................................... 1345 Appendix B: Annotated Bibliography ............................................................................... 1347 Page i Thi d t t d ith F M k 402 Appendix C: Keyboard Scan Codes ................................................................................... 1351 Appendix D: Instruction Set Reference .............................................................................. 1361 Page ii The Art of Assembly Language The Art of Assembly Language (Full Contents) Forward Why Would Anyone Learn This Stuff? .............................................................. 1 1 What’s Wrong With Assembly Language ............................................................................ 1 2 What’s Right With Assembly Language? ............................................................................. 4 3 Organization of This Text and Pedagogical Concerns ....................................................... 5 4 Obtaining Program Source Listings and Other Materials in This Text ............................... 7 Section One: ................................................................................................................... 9 Machine Organization ........................................................................................................... 9 Chapter One Data Representation ................................................................................ 11 1.0 Chapter Overview ............................................................................................................ 11 1.1 Numbering Systems .......................................................................................................... 11 1.1.1 A Review of the Decimal System ........................................................................... 11 1.1.2 The Binary Numbering System ............................................................................. 12 1.1.3 Binary Formats ....................................................................................................... 13 1.2 Data Organization ............................................................................................................ 13 1.2.1 Bits .......................................................................................................................... 14 1.2.2 Nibbles ................................................................................................................... 14 1.2.3 Bytes ....................................................................................................................... 14 1.2.4 Words ..................................................................................................................... 15 1.2.5 Double Words ........................................................................................................ 16 1.3 The Hexadecimal Numbering System .............................................................................. 17 1.4 Arithmetic Operations on Binary and Hexadecimal Numbers ........................................ 19 1.5 Logical Operations on Bits ............................................................................................... 20 1.6 Logical Operations on Binary Numbers and Bit Strings ................................................. 22 1.7 Signed and Unsigned Numbers ........................................................................................ 23 1.8 Sign and Zero Extension .................................................................................................. 25 1.9 Shifts and Rotates .............................................................................................................. 26 1.10 Bit Fields and Packed Data ............................................................................................. 28 1.11 The ASCII Character Set .................................................................................................. 28 1.12 Summary ......................................................................................................................... 31 1.13 Laboratory Exercises ....................................................................................................... 33 1.13.1 Installing the Software ......................................................................................... 33 1.13.2 Data Conversion Exercises .................................................................................. 34 1.13.3 Logical Operations Exercises ............................................................................... 35 1.13.4 Sign and Zero Extension Exercises ..................................................................... 36 1.13.5 Packed Data Exercises ......................................................................................... 37 1.14 Questions ........................................................................................................................ 38 1.15 Programming Projects .................................................................................................... 41 Chapter Two Boolean Algebra ...................................................................................... 43 2.0 Chapter Overview ............................................................................................................ 43 2.1 Boolean Algebra ............................................................................................................... 43 Page iii Thi d t t d ith F M k 402 2.2 Boolean Functions and Truth Tables ................................................................................45 2.3 Algebraic Manipulation of Boolean Expressions .............................................................48 2.4 Canonical Forms ................................................................................................................49 2.5 Simplification of Boolean Functions .................................................................................52 2.6 What Does This Have To Do With Computers, Anyway? ................................................59 2.6.1 Correspondence Between Electronic Circuits and Boolean Functions ................59 2.6.2 Combinatorial Circuits ............................................................................................60 2.6.3 Sequential and Clocked Logic ................................................................................62 2.7 Okay, What Does It Have To Do With Programming, Then? ..........................................64 2.8 Generic Boolean Functions ..............................................................................................65 2.9 Laboratory Exercises .........................................................................................................69 2.9.1 Truth Tables and Logic Equations Exercises .........................................................70 2.9.2 Canonical Logic Equations Exercises .....................................................................71 2.9.3 Optimization Exercises ...........................................................................................72 2.9.4 Logic Evaluation Exercises .....................................................................................72 2.10 Programming Projects .....................................................................................................77 2.11 Summary ..........................................................................................................................78 2.12 Questions .........................................................................................................................80 Chapter Three System Organization .............................................................................. 83 3.0 Chapter Overview .............................................................................................................83 3.1 The Basic System Components .........................................................................................83 3.1.1 The System Bus ......................................................................................................84 3.1.1.1 The Data Bus ................................................................................................ 84 3.1.1.2 The Address Bus ........................................................................................... 86 3.1.1.3 The Control Bus ............................................................................................ 86 3.1.2 The Memory Subsystem .........................................................................................87 3.1.3 The I/O Subsystem .................................................................................................92 3.2 System Timing ...................................................................................................................92 3.2.1 The System Clock ...................................................................................................92 3.2.2 Memory Access and the System Clock ...................................................................93 3.2.3 Wait States ...............................................................................................................95 3.2.4 Cache Memory ........................................................................................................96 3.3 The 886, 8286, 8486, and 8686 “Hypothetical” Processors ..............................................99 3.3.1 CPU Registers ..........................................................................................................99 3.3.2 The Arithmetic & Logical Unit ................................................................................100 3.3.3 The Bus Interface Unit ............................................................................................100 3.3.4 The Control Unit and Instruction Sets ....................................................................100 3.3.5 The x86 Instruction Set ...........................................................................................102 3.3.6 Addressing Modes on the x86 ................................................................................103 3.3.7 Encoding x86 Instructions ......................................................................................104 3.3.8 Step-by-Step Instruction Execution ........................................................................107 3.3.9 The Differences Between the x86 Processors .......................................................109 3.3.10 The 886 Processor ................................................................................................110 3.3.11 The 8286 Processor ...............................................................................................110 3.3.12 The 8486 Processor ...............................................................................................116 3.3.12.1 The 8486 Pipeline ....................................................................................... 117 3.3.12.2 Stalls in a Pipeline ....................................................................................... 118 3.3.12.3 Cache, the Prefetch Queue, and the 8486 .................................................. 119 Page iv The Art of Assembly Language 3.3.12.4 Hazards on the 8486 .................................................................................. 122 3.3.13 The 8686 Processor .............................................................................................. 123 3.4 I/O (Input/Output) ........................................................................................................... 124 3.5 Interrupts and Polled I/O ................................................................................................. 126 3.6 Laboratory Exercises ......................................................................................................... 128 3.6.1 The SIMx86 Program – Some Simple x86 Programs ............................................. 128 3.6.2 Simple I/O-Mapped Input/Output Operations ..................................................... 131 3.6.3 Memory Mapped I/O ............................................................................................. 132 3.6.4 DMA Exercises ....................................................................................................... 133 3.6.5 Interrupt Driven I/O Exercises .............................................................................. 134 3.6.6 Machine Language Programming & Instruction Encoding Exercises ................... 135 3.6.7 Self Modifying Code Exercises .............................................................................. 136 3.7 Programming Projects ...................................................................................................... 138 3.8 Summary ........................................................................................................................... 139 3.9 Questions .......................................................................................................................... 142 Chapter Four Memory Layout and Access .................................................................. 145 4.0 Chapter Overview ............................................................................................................ 145 4.1 The 80x86 CPUs:A Programmer’s View ........................................................................... 145 4.1.1 8086 General Purpose Registers ............................................................................ 146 4.1.2 8086 Segment Registers ......................................................................................... 147 4.1.3 8086 Special Purpose Registers ............................................................................. 148 4.1.4 80286 Registers ...................................................................................................... 148 4.1.5 80386/80486 Registers ........................................................................................... 149 4.2 80x86 Physical Memory Organization ............................................................................. 150 4.3 Segments on the 80x86 ..................................................................................................... 151 4.4 Normalized Addresses on the 80x86 ................................................................................ 154 4.5 Segment Registers on the 80x86 ....................................................................................... 155 4.6 The 80x86 Addressing Modes .......................................................................................... 155 4.6.1 8086 Register Addressing Modes ........................................................................... 156 4.6.2 8086 Memory Addressing Modes .......................................................................... 156 4.6.2.1 The Displacement Only Addressing Mode ................................................. 156 4.6.2.2 The Register Indirect Addressing Modes ..................................................... 158 4.6.2.3 Indexed Addressing Modes ......................................................................... 159 4.6.2.4 Based Indexed Addressing Modes .............................................................. 160 4.6.2.5 Based Indexed Plus Displacement Addressing Mode ................................ 160 4.6.2.6 An Easy Way to Remember the 8086 Memory Addressing Modes ............. 162 4.6.2.7 Some Final Comments About 8086 Addressing Modes .............................. 162 4.6.3 8...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture