The Art of Assembly Language
Total Page:16
File Type:pdf, Size:1020Kb
Hello, World of Assembly Language The Art of Assembly Language (Full Contents) “The Art of Assembly Language Programming” is going hard. In early 2003 this text will be available in published form from “No Starch Press” (http://www.nostarchpress.com). Please check out their website for more details. 1.1 Foreword to the HLA Version of “The Art of Assembly...” ................... 3 1.2 Intended Audience ................................................................................... 6 1.3 Teaching From This Text ........................................................................ 6 1.4 Copyright Notice ..................................................................................... 7 1.5 How to Get a Hard Copy of This Text .................................................... 8 1.6 Obtaining Program Source Listings and Other Materials in This Text ... 8 1.7 Where to Get Help ................................................................................... 8 1.8 Other Materials You Will Need (Windows Version) .............................. 8 1.9 Other Materials You Will Need (Linux Version) .................................... 9 2.1 Chapter Overview .................................................................................... 11 2.2 Installing the HLA Distribution Package ................................................ 11 2.2.1 Installation Under Windows .......................................................... 12 2.2.2 Installation Under Linux ................................................................ 15 2.2.3 Installing “Art of Assembly” Related Files ................................... 18 2.3 The Anatomy of an HLA Program .......................................................... 19 2.4 Some Basic HLA Data Declarations ....................................................... 21 2.5 Boolean Values ........................................................................................ 23 2.6 Character Values ...................................................................................... 23 2.7 An Introduction to the Intel 80x86 CPU Family ..................................... 23 2.8 Some Basic Machine Instructions ........................................................... 26 2.9 Some Basic HLA Control Structures ....................................................... 29 2.9.1 Boolean Expressions in HLA Statements ...................................... 30 2.9.2 The HLA IF..THEN..ELSEIF..ELSE..ENDIF Statement .............. 32 2.9.3 The WHILE..ENDWHILE Statement ........................................... 33 2.9.4 The FOR..ENDFOR Statement ...................................................... 34 2.9.5 The REPEAT..UNTIL Statement .................................................. 35 2.9.6 The BREAK and BREAKIF Statements ....................................... 36 2.9.7 The FOREVER..ENDFOR Statement ........................................... 36 2.9.8 The TRY..EXCEPTION..ENDTRY Statement ............................ 37 2.10 Introduction to the HLA Standard Library ............................................ 38 2.10.1 Predefined Constants in the STDIO Module ............................... 40 2.10.2 Standard In and Standard Out ...................................................... 40 2.10.3 The stdout.newln Routine ............................................................ 41 Beta Draft - Do not distribute © 2001, By Randall Hyde Page 1 AoATOC.fm 2.10.4 The stdout.putiX Routines ........................................................... 41 2.10.5 The stdout.putiXSize Routines ..................................................... 41 2.10.6 The stdout.put Routine ................................................................. 42 2.10.7 The stdin.getc Routine. ................................................................ 43 2.10.8 The stdin.getiX Routines .............................................................. 44 2.10.9 The stdin.readLn and stdin.flushInput Routines .......................... 46 2.10.10 The stdin.get Macro ................................................................... 46 2.11 Putting It All Together ........................................................................... 47 2.12 Sample Programs ................................................................................... 47 2.12.1 Powers of Two Table Generation ................................................ 47 2.12.2 Checkerboard Program ................................................................. 48 2.12.3 Fibonacci Number Generation ..................................................... 50 3.1 Chapter Overview .................................................................................... 53 3.2 Numbering Systems ................................................................................. 53 3.2.1 A Review of the Decimal System .................................................. 53 3.2.2 The Binary Numbering System ..................................................... 54 3.2.3 Binary Formats ............................................................................... 55 3.3 Data Organization .................................................................................... 56 3.3.1 Bits ................................................................................................. 56 3.3.2 Nibbles ........................................................................................... 56 3.3.3 Bytes ............................................................................................... 57 3.3.4 Words ............................................................................................. 58 3.3.5 Double Words ................................................................................ 59 3.4 The Hexadecimal Numbering System ..................................................... 60 3.5 Arithmetic Operations on Binary and Hexadecimal Numbers ................ 62 3.6 A Note About Numbers vs. Representation ............................................ 63 3.7 Logical Operations on Bits ...................................................................... 65 3.8 Logical Operations on Binary Numbers and Bit Strings ........................ 68 3.9 Signed and Unsigned Numbers ............................................................... 69 3.10 Sign Extension, Zero Extension, Contraction, and Saturation ............ 73 3.11 Shifts and Rotates .................................................................................. 76 3.12 Bit Fields and Packed Data .................................................................... 81 3.13 Putting It All Together ........................................................................... 85 4.1 Chapter Overview .................................................................................... 87 4.2 An Introduction to Floating Point Arithmetic ......................................... 87 4.2.1 IEEE Floating Point Formats ......................................................... 90 4.2.2 HLA Support for Floating Point Values ........................................ 93 4.3 Binary Coded Decimal (BCD) Representation ........................................ 95 4.4 Characters ................................................................................................ 96 4.4.1 The ASCII Character Encoding ..................................................... 97 4.4.2 HLA Support for ASCII Characters ............................................... 100 4.4.3 The ASCII Character Set ............................................................... 104 4.5 The UNICODE Character Set ................................................................. 108 4.6 Other Data Representations ..................................................................... 109 Page 2 © 2001, By Randall Hyde Beta Draft - Do not distribute Hello, World of Assembly Language 4.6.1 Representing Colors on a Video Display ....................................... 109 4.6.2 Representing Audio Information ................................................... 111 4.6.3 Representing Musical Information ................................................. 114 4.6.4 Representing Video Information .................................................... 115 4.6.5 Where to Get More Information About Data Types ...................... 115 4.7 Putting It All Together ............................................................................. 116 5.1 Questions ................................................................................................. 119 5.2 Programming Projects for Chapter Two .................................................. 124 5.3 Programming Projects for Chapter Three ................................................ 124 5.4 Programming Projects for Chapter Four ................................................. 125 5.5 Laboratory Exercises for Chapter Two ................................................... 126 5.5.1 A Short Note on Laboratory Exercises and Lab Reports ............... 126 5.5.2 Compiling Your First Program ...................................................... 127 5.5.3 Compiling Other Programs Appearing in this Chapter .................. 128 5.5.4 Creating and Modifying HLA Programs ....................................... 129 5.5.5 Writing a New Program ................................................................. 129 5.5.6 Correcting Errors in an HLA Program ........................................... 130 5.5.7 Write Your Own Sample Program ................................................. 131 5.6 Laboratory Exercises for