The Art of Assembly Language 32-bit Edition.pdf

(6639 KB) Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
The Art of Assembly Language
The Art of Assembly Language
(Brief Contents)
The Art of Assembly Language ................................................................. 1
Volume One: .............................................................................................. 1
Data Representation ................................................................................... 1
Chapter One Foreward ................................................................................ 3
Chapter Two Hello, World of Assembly Language ................................... 11
Chapter Three Data Representation ............................................................ 43
Chapter Four More Data Representation .................................................... 77
Chapter Five ............................................................................................... 109
Chapter Five Questions, Projects, and Lab Exercises ................................. 109
Volume Two: ............................................................................................. 129
Machine Architecture ................................................................................. 129
Chapter One System Organization .............................................................. 131
Chapter Two Memory Access and Organization ........................................ 151
Chapter Three Introduction to Digital Design ............................................ 195
Chapter Four CPU Architecture .................................................................. 225
Chapter Five Instruction Set Architecture .................................................. 261
Chapter Six Memory Architecture .............................................................. 293
Chapter Seven The I/O Subsystem ............................................................. 315
Chapter Eight Questions, Projects, and Labs .............................................. 341
Volume Three: ........................................................................................... 375
Basic Assembly Language ......................................................................... 375
Chapter One Constants, Variables, and Data Types .................................. 377
Chapter Two Introduction to Character Strings .......................................... 401
Chapter Three Characters and Character Sets ............................................ 421
Chapter Four Arrays ................................................................................... 445
Chapter Five Records, Unions, and Name Spaces ...................................... 465
Chapter Six Dates and Times ...................................................................... 481
Chapter Seven Files .................................................................................... 497
Chapter Eight Introduction to Procedures ................................................... 521
Chapter Nine Managing Large Programs ................................................... 549
Chapter Ten Integer Arithmetic .................................................................. 567
Chapter Eleven Real Arithmetic ................................................................. 591
Chapter Twelve Calculation Via Table Lookups ........................................ 625
Chapter Thirteen Questions, Projects, and Labs ......................................... 641
Page 1
Intermediate Assembly Language .............................................................. 703
Chapter One Advanced High Level Control Structures ............................. 705
Chapter Two Low-Level Control Structures .............................................. 729
Chapter Three Intermediate Procedures ...................................................... 781
Chapter Four Advanced Arithmetic ............................................................ 827
Chapter Five Bit Manipulation ................................................................... 881
Chapter Six The String Instructions ........................................................... 907
Chapter Seven The HLA Compile-Time Language ................................... 921
Chapter Eight Macros ................................................................................. 941
Chapter Nine Domain Specific Embedded Languages ............................... 975
Chapter Ten Classes and Objects ................................................................ 1029
Chapter Eleven The MMX Instruction Set ................................................. 1083
Chapter Twelve Mixed Language Programming ........................................ 1119
Chapter Thirteen Questions, Projects, and Labs ......................................... 1163
Section Five ............................................................................................... 1245
Section Five Advanced Assembly Language Programming ...................... 1245
Chapter One Thunks ................................................................................... 1247
Chapter Two Iterators ................................................................................. 1271
Chapter Three Coroutines and Generators .................................................. 1293
Chapter Four Low-level Parameter Implementation .................................. 1305
Chapter Five Lexical Nesting ..................................................................... 1337
Chapter Six Questions, Projects, and Labs ................................................. 1359
Appendix A Answers to Selected Exercises ............................................... 1365
Appendix B Console Graphic Characters ................................................... 1367
Appendix D The 80x86 Instruction Set ...................................................... 1409
Appendix E The HLA Language Reference ............................................... 1437
Appendix F The HLA Standard Library Reference .................................... 1439
Appendix G HLA Exceptions ..................................................................... 1441
Appendix H HLA Compile-Time Functions .............................................. 1447
Appendix I Installing HLA on Your System .............................................. 1477
Appendix J Debugging HLA Programs ...................................................... 1501
Appendix K Comparing HLA and MASM ................................................. 1505
Appendix L HLA Code Generation for HLL Statements ........................... 1507
Index .......................................................................................................... 1
Page 2
Hello, World of Assembly Language
The Art of Assembly Language
(Full Contents)
• Foreward to the HLA Version of “The Art of Assembly...” ....................... 3
• Intended Audience ....................................................................................... 6
• Teaching From This Text ............................................................................ 6
• Copyright Notice ......................................................................................... 7
• How to Get a Hard Copy of This Text ........................................................ 8
• Obtaining Program Source Listings and Other Materials in This Text ....... 8
• Where to Get Help ....................................................................................... 8
• Other Materials You Will Need .................................................................. 9
2.0 Chapter Overview .................................................................................... 11
2.1 The Anatomy of an HLA Program .......................................................... 11
2.2 Some Basic HLA Data Declarations ....................................................... 12
2.3 Boolean Values ........................................................................................ 14
2.4 Character Values ...................................................................................... 15
2.5 An Introduction to the Intel 80x86 CPU Family ..................................... 15
2.6 Some Basic Machine Instructions ........................................................... 18
2.7 Some Basic HLA Control Structures ....................................................... 21
2.7.1 Boolean Expressions in HLA Statements ...................................... 21
2.7.2 The HLA IF..THEN..ELSEIF..ELSE..ENDIF Statement .............. 23
2.7.3 The WHILE..ENDWHILE Statement ........................................... 24
2.7.4 The FOR..ENDFOR Statement ...................................................... 25
2.7.5 The REPEAT..UNTIL Statement .................................................. 26
2.7.6 The BREAK and BREAKIF Statements ....................................... 27
2.7.7 The FOREVER..ENDFOR Statement ........................................... 27
2.7.8 The TRY..EXCEPTION..ENDTRY Statement ............................ 28
2.8 Introduction to the HLA Standard Library .............................................. 29
2.8.1 Predefined Constants in the STDIO Module ................................. 30
2.8.2 Standard In and Standard Out ........................................................ 31
2.8.3 The stdout.newln Routine .............................................................. 31
2.8.4 The stdout.putiX Routines ............................................................. 31
2.8.5 The stdout.putiXSize Routines ...................................................... 32
2.8.6 The stdout.put Routine ................................................................... 33
2.8.7 The stdin.getc Routine. .................................................................. 34
2.8.8 The stdin.getiX Routines ................................................................ 35
2.8.9 The stdin.readLn and stdin.flushInput Routines ............................ 36
2.8.10 The stdin.get Macro ..................................................................... 37
2.9 Putting It All Together ............................................................................. 38
2.10 Sample Programs ................................................................................... 38
2.10.1 Powers of Two Table Generation ................................................ 38
2.10.2 Checkerboard Program ................................................................ 39
Beta Draft - Do not distribute
© 2001, By Randall Hyde
Page 1
AoATOC.fm
2.10.3 Fibonocci Number Generation ..................................................... 41
3.1 Chapter Overview .................................................................................... 43
3.2 Numbering Systems ................................................................................. 43
3.2.1 A Review of the Decimal System .................................................. 43
3.2.2 The Binary Numbering System ..................................................... 44
3.2.3 Binary Formats ............................................................................... 45
3.3 Data Organization .................................................................................... 46
3.3.1 Bits ................................................................................................. 46
3.3.2 Nibbles ........................................................................................... 46
3.3.3 Bytes ............................................................................................... 47
3.3.4 Words ............................................................................................. 48
3.3.5 Double Words ................................................................................ 49
3.4 The Hexadecimal Numbering System ..................................................... 50
3.5 Arithmetic Operations on Binary and Hexadecimal Numbers ................ 52
3.6 A Note About Numbers vs. Representation ............................................ 53
3.7 Logical Operations on Bits ...................................................................... 55
3.8 Logical Operations on Binary Numbers and Bit Strings ........................ 57
3.9 Signed and Unsigned Numbers ............................................................... 59
3.10 Sign Extension, Zero Extension, Contraction, and Saturation ............ 63
3.11 Shifts and Rotates .................................................................................. 66
3.12 Bit Fields and Packed Data .................................................................... 71
3.13 Putting It All Together ........................................................................... 74
4.1 Chapter Overview .................................................................................... 77
4.2 An Introduction to Floating Point Arithmetic ......................................... 77
4.2.1 IEEE Floating Point Formats ......................................................... 80
4.2.2 HLA Support for Floating Point Values ........................................ 83
4.3 Binary Coded Decimal (BCD) Representation ........................................ 85
4.4 Characters ................................................................................................ 86
4.4.1 The ASCII Character Encoding ..................................................... 87
4.4.2 HLA Support for ASCII Characters ............................................... 90
4.4.3 The ASCII Character Set ............................................................... 93
4.5 The UNICODE Character Set ................................................................. 98
4.6 Other Data Representations ..................................................................... 98
4.6.1 Representing Colors on a Video Display ....................................... 98
4.6.2 Representing Audio Information .................................................... 100
4.6.3 Representing Musical Information ................................................. 104
4.6.4 Representing Video Information .................................................... 105
4.6.5 Where to Get More Information About Data Types ...................... 105
4.7 Putting It All Together ............................................................................. 106
5.1 Questions ................................................................................................. 109
5.2 Programming Projects for Chapter Two .................................................. 114
5.5 Laboratory Exercises for Chapter Two .................................................... 117
5.5.1 A Short Note on Laboratory Exercises and Lab Reports ............... 117
5.5.2 Installing the HLA Distribution Package ....................................... 117
Page 2
© 2001, By Randall Hyde
Beta Draft - Do not distribute
Hello, World of Assembly Language
5.5.3 What’s Included in the HLA Distribution Package ....................... 119
5.5.4 Using the HLA Compiler ............................................................... 121
5.5.5 Compiling Your First Program ...................................................... 121
5.5.6 Compiling Other Programs Appearing in this Chapter .................. 123
5.5.7 Creating and Modifying HLA Programs ....................................... 123
5.5.8 Writing a New Program ................................................................. 124
5.5.9 Correcting Errors in an HLA Program ........................................... 125
5.5.10 Write Your Own Sample Program ............................................... 125
5.6 Laboratory Exercises for Chapter Three and Chapter Four .................... 126
5.6.1 Data Conversion Exercises ............................................................ 126
5.6.2 Logical Operations Exercises ......................................................... 127
5.6.3 Sign and Zero Extension Exercises ................................................ 127
5.6.4 Packed Data Exercises ................................................................... 128
5.6.5 Running this Chapter’s Sample Programs ..................................... 128
5.6.6 Write Your Own Sample Program ................................................. 128
1.1 Chapter Overview .................................................................................... 131
1.2 The Basic System Components ............................................................... 131
1.2.1 The System Bus ............................................................................. 132
1.2.1.1 The Data Bus ......................................................................... 132
1.2.1.2 The Address Bus .................................................................... 133
1.2.1.3 The Control Bus .................................................................... 134
1.2.2 The Memory Subsystem ................................................................ 135
1.2.3 The I/O Subsystem ......................................................................... 141
1.3 HLA Support for Data Alignment ........................................................... 141
1.4 System Timing ......................................................................................... 144
1.4.1 The System Clock .......................................................................... 144
1.4.2 Memory Access and the System Clock .......................................... 145
1.4.3 Wait States ..................................................................................... 146
1.4.4 Cache Memory ............................................................................... 147
1.5 Putting It All Together ............................................................................. 150
2.1 Chapter Overview .................................................................................... 151
2.2 The 80x86 Addressing Modes ................................................................. 151
2.2.1 80x86 Register Addressing Modes ................................................ 151
2.2.2 80x86 32-bit Memory Addressing Modes ..................................... 152
2.2.2.1 The Displacement Only Addressing Mode ........................... 152
2.2.2.2 The Register Indirect Addressing Modes .............................. 153
2.2.2.3 Indexed Addressing Modes ................................................... 154
2.2.2.4 Variations on the Indexed Addressing Mode ........................ 155
2.2.2.5 Scaled Indexed Addressing Modes ....................................... 157
2.2.2.6 Addressing Mode Wrap-up ................................................... 158
2.3 Run-Time Memory Organization ............................................................ 158
2.3.1 The Code Section ........................................................................... 159
2.3.2 The Read-Only Data Section ......................................................... 160
2.3.3 The Storage Section ....................................................................... 161
2.3.4 The Static Sections ......................................................................... 161
2.3.5 The NOSTORAGE Attribute ......................................................... 162
2.3.6 The Var Section ............................................................................. 162
2.3.7 Organization of Declaration Sections Within Your Programs ....... 163
Beta Draft - Do not distribute
© 2001, By Randall Hyde
Page 3
Zgłoś jeśli naruszono regulamin