1 HELLO,WORLD OF ASSEMBLY LANGUAGE
1.1 Chapter Overview
1.2 The Anatomy of an HLA Program
1.3 Running Your First HLA Program
1.4 Some Basic HLA Data Declarations
1.5 Boolean Values
1.6 Character Values
1.7 An Introduction to Ifle Intel 80x86 CPU Family
1.7.1 The Memory Subsystem
1.8 Some Basic Machine Instructions
1.9 Some Basic HLA Control Structures
1.9.1 Boolean Expressions in HLA Statements
1.9.2 The HLA IF..THEN..ELSEIF..ELSE..ENDIF Statement
1.9.3 Conjunction, Disjunction, and Negation in Boolean Expressions
1.9.4 The WHILE..ENDWHILE Statement
1.9.5 The FOR..ENDFOR Statement
1.9.6 The REPEAT..UNTIL Statement
1.9.7 The BREAK and BREAKIF Statements
1.9.8 The FOREVER..ENDFOR Statement
1.9.9 The TRY..EXCEPTION..ENDTRY Statement
1.10 Introduction fo tfle HLA Sfandard Library
1.1O.1 Predefined Constanfs in the STDIo Module
1.1O.2 Sfandard In and Sfandard OUt
1.1O.3 The sfdOUt.newln ROUtine
1.1O.4 The sfdOUt.putiX ROUtines
1.1O.5 The sfdOUt.putiXSize Routines
1.1O.6 The sfdOUt.put ROUtine
1.1O.7 The sfd.n.gefc ROUtine
1.1O.8 The sfd.n.getiX ROUtines
1.1O.9 The sfd.n.teadLn and sfd.n.fIushlnput ROUtines
1.1O.1 O The sfdin.get ROUtine
1.11 AdditionaI Defails AbOUt TRY..ENDTRY
1.11.1 Nesting TRY..ENDTRY Sfafements
1.11.2 The UNPRoTECTED CIause in a TRY..ENDTRY Sfatement
1.11.3 The ANYEXCEPTIoN CIause in a TRY..ENDTRY SIafement
1.11.4 Regisfers and t11e TRY..ENDTRY Stafement
1.12 High LeveI AssembIy Language vs.Low Level AssembIy
1.13 For More Information
2 DATA REPRESENTATIoN
2.1 Chapter Overview
2.2 Numbering Systems
2.2.1 A Review of the Decimal System
2.2.2 The Binary Numbering System
2.2.3 Binary Formats
2.3 The Hexadecimal Numbering System
2.4 Data Organization
2.4.1 Bits
2.4.2 Nibbles
2.4.3 Bytes
2.4.4 Words
2.4.5 Double Words
2.4.6 Quad Words and Long Words
2.5 Arithmetic Operations on Binary and Hexadecimal Numbers
2.6 A Note About Numbers vs. Representation
2.7 Logical Operations on Bits
2.8 Logical Operations on Binary Numbers and Bit Strings
2.9 Signed and Unsigned Numbers
2.10 Sign Extension, Zero Extension, Contraction, and Saturation
2.11 Shifts and Rotates
2.12 Bit Fields and Packed Data
2.13 An Introduction to Floating Point Arithmetic
2.13.1 IEEE Floating Point Formats
2.13.2 HLA Support for Floating Point Values
2.14 Binary Coded Decimal (BCD) Representation
2.15 Characters
2.15.1 The ASCII Character Encoding
2.15.2 HLA Support for ASCII Characters
2.16 The Unicode Character Set
2.17 For More Information
3
MEMoRY ACCESS AND oRGANIZATIoN
3.1 Chaloter OvervieW
3.2 111e 80x86 Addlessing Modes
3.2.1 80x86 Reftister Addtessinfl Modes
3.2.2 80x86 32.Bit Memory Addressing Modes.
3.3 Run.Time Memory Orflanization
3.3.1 The Code Section
3.3.2 The Stat‘ic Sections
3.3.3 The Read-OnIy Data Section
3.3.4 The Stomge Section
3.3.5 The@NoSToRAGE Attribute
3.3.6 The Var Section
3.3.7 Orflanization of DecIaration Sections Within Your Programs
3.4 HOW HLA AIIocafes Memory for VariabIes
3.5 HLA Support for Dafa AIignment
3.6 Address Expressions
3.7 Type Coercion
3.8 Regjster Type Coercion
3.9 The Sfack Segment and the PUSH and POP Instructions
3.9.1 The Basic PUSH Instruction
3.9.2 The Basic POP lnstruction
3.9.3 Preserving Reftistes with the PUSH and PoP lnstructions
3.9.4 The Sfack ls a LIFo Data Structure
3.9.5 Otller PUSH and PoP Instructions
3.9.6 Removing Dafa from the Stack WithoUt POPOing It
3.9.7 Accessjng Dafa You've Pushed on t}1e Stack WithOUt POPlOjn lt
3.10 Dynamic Memory A¨Ocatlon and the Heao Seflment
3.11 The INC and DEC Instructions
3.12 Obtaing the Address of a Memorv obiect
3.13 For More Information
4 CONSTANTS,VARIAB LES,AN D DATA TYPES
4.1 Chapter Overview
4.2 Some Additional Instructions: INTMUL, BOUND, INTO
4.3 The "I'BYTE Data Types
4.4 HLA Constant and Value Declarations
4.4.1 Constant Types
4.4.2 String and Character Literal Constants
4.4.3 String and Text Constants in the CONST Section
4.4.4 Constant Expressions
4.4.5 Multiple CONST Sections and Their Order in an HLA Program
4.4.6 The HLA VAL Section
4.4.7 Modifying VAL Objects at Arbitrary Points in Your Programs
4.5 The HLA TYPE Section
4.6 ENUM and HLA Enumerated Data Types
4.7 Pointer Data Types
4.7.1 Using Pointers in Assembly Language
4.7.2 Declaring Pointers in HLA
4.7.3 Pointer Constants and Pointer Constant Expressions
4.7.4 Pointer Variables and Dynamic Memory Allocation
4.7.5 Common Pointer Problems
4.8 The HLA Standard Library CHARS.HHF Module
4.9 Composite Data Types
4.10 Character Strings
4.11 HLA Strings
4.12 Accessing the Characters Within a String
4.13 The HLA String Module and Other String-Related Routines
4.14 In-Memory Conversions
4.15 Character Sets
4.16 Character Set Implementation in HLA
4.17 HLA Character Set Constants and Character Set Expressions
4.18 The IN Operator in HLA HLL Boolean Expressions
4.19 Character Set Support in the HLA Standard Library
4.20 Using Character Sets in Your HLA Programs
4.21 Arrays
4.22 Declaring Arrays in Your HLA Programs
4.23 HLA Array Constants
4.24 Accessing Elements of a Single Dimension Array
4.24.1 Sorting an Array of Values
4.25 Multidimensional Arrays
4.25.1 Row Major Ordering
4.25.2 Column Major Ordering
4.26 Allocating Storage For Multidimensional Arrays
4.27 Accessing Multidimensional Array Elements in Assembly Language
4.28 Large Arrays and MASM (Windows Programmers Only)
4.29 Records
4.30 Record Constants
4.31 Arrays of Records
4.32 Arrays/Records as Record Fields
4.33 Controlling Field Offsets Within a Record :
4.34 Aligning Fields Within a Record
4.35 Pointers to Records ~
4.36 Unions
4.37 Anonymous Unions
4.38 Variant Types
4.39 Union Constants
4.40 Namespaces
4.41 Dynamic Arrays in Assembly Language
4.42 HLA Standard Library Array Support
4.43 For More Information
$
PROCEDURES AND UNITS
5.1 Chapter Overview
5.2 Procedures
5.3 Saving the State of the Machine
5.4 Prematurely Returning from a Procedure
5.5 Local Variables ~
5.6 Other Local and Global Symbol Types
5.7 Parameters
5.7.1 Pass by Value
5.7.2 Pass by Reference
5.8 Functions and Function Results
5.8.1 Returning Function Results
5.8.2 Instruction Composition in HLA
5.8.3 The HLA @RETURNS Option in Procedures
5.9 Recursion
5.10 Forward Procedures
5.11 Low Level Procedures and the CALL Instruction
5.12 Procedures and the Stack
5.13 Activation Records
5.14 The Standard Entv/Sequence
5.15 The Standard Exit Sequence
5.16 Low Level Implementation of Automatic (Local) Variables
5.17 Low Level Parameter Implementation
5.17.1 Passing Parameters in Registers
5.17.2 Passing Parameters in the Code Stream
5.17.3 Passing Parameters on the Stack
5.18 Procedure Pointers
5.19 Procedure Parameters
5.20 Untyped Reference Parameters
5.21 Managing Large Programs
5.22 The #INCLUDE Directive
5.23 Ignoring Duplicate #INCLUDE Operations
5.24 UNITs and the EXTERNAL Directive
5.24.1 Behavior of the EXTERNAL Directive
5.24.2 Header Files in HLA
5.25 Namespace Pollution
5.26 For More Information
6
ARITi.I,~fTI~
6.1 Chapter Overview
6.2 80x86 Integer Arithmetic Instructions
6.2.1 The MUL and IMUL Instructions
6.2.2 The DIV and IDIV Instructions
6.2.3 The CMP Instruction
6.2.4 The SETcc Instructions
6.2.5 The TEST Instruction
6.3 Arithmetic Expressions
6.3.1 Simple Assignments
6.3.2 Simple Expressions '
6.3.3 Complex Expressions
6.3.4 Commutative Operators
6.4 Logical (Boolean) Expressions
6.5 Machine and Arithmetic Idioms
6.5.1 Multiplying Without MUL, IMUL, or INTMUL
6.5.2 Division Without DIV or IDIV
6.5.3 Implementing Modulo-N Counters with AND
6.5.4 Careless Use of Machine Idioms
6.6 Floating Point Arithmetic
6.6.1 FPU Registers
6.6.2 FPU Data Types
6.6.3 The FPU Instruction Set
6.6.4 FPU Data Movement Instructions
6.6.5 Conversions
6.6.6 Arithmetic Instructions
6.6.7 Comparison Instructions
6.6.8 Constant Instructions
6.6.9 Transcendental Instructions
6.6.10 Miscellaneous Instructions
6.6.11 Integer Operations
6.7 Converting Floating Point Expressions to Assembly Language
6.7. I Converting Arithmetic Expressions to Postfix Notation
6.7.2 Converting Postfix Notation to Assembly Language
6.8 HLA Standard Library Support for Floating Point Arithmetic
6.8. I The stdin.getf and fileio.getf Functions
6.8.2 Trigonometric Functions in the HI.A Math Library
6.8.3 Exponential and Logarithmic Functions in the HLA Math Library
6.9 Puffing It All Together
7
LOW LEVEL CONTROL STRUCTURES
7.1 Chapter Overview
7.2 Low Level Control Structures
7.3 Statement Labels
7.4 Unconditional Transfer of Control (,IMP)
7.5 The Conditional Jump Instructions
7.6 "Medium Level" Control Structures: JT and JF
7.7 Implementing Common Control Structures in Assembly Language
7.8 Introduction to Decisions
7.8.1 IF..THEN..ELSE Sequences
7.8.2 Translating HLA IF Statements into Pur.e. Assembly Language
7.8.3 Implamenting Complex IF Statements Using
Complete Boolean Evaluation
7.8.4 Short-Circuit Boolean Evaluation
7.8.5 Short-Circuit vs. Complete Boolean Evaluation
7.8.6 Efficient Implementation of IF Statements in Assembly Language
7.8.7 SWITCH/CASE Statements
7.9 State Machines and Indirect Jumps
7.10 Spaghetti Code
7.11 Loops
7.11.1 WHILE Loops
7.11.2 REPEAT..UNTIL Loops
7.11.3 FOREVER..ENDFOR Loops
7.11.4 FOR Loops
7.11.5 The BREAK and CONTINUE Statements
7.11.6 Register Usage and Loops
7.12 performance Improvements
7.12.1 Moving the Termination Condition to the End of a Loop
7.12.2 Executing the Loop Backward
7.12.3 Loop Invariant Computations
7.12.4 Unraveling Loops
7.12.5 Induction Variables
7.13 Hybrid Control Structures in HLA
7.14 For More Information
8
FILES
8.1 Chapter Overview
8.2 File Organization
8.2.1 Files as Lists of Records
8.2.2 Binary vs. Text Files
8.3 Sequential Files
8.4 Random Access Files
8.5 ISAM (Indexed Sequential Access Method) Files
8.6 Truncating a File
8.7 For More Information
9
ADVANCED ARITHMETIC
9.1 Chapter Overview
9.2 Multiprecision Operations
9.2.1 HLA Standard Library Support for Extended Precision Operations
9.2.2 Multiprecision Addition Operations
9.2.3 Multiprecision Subtraction Operations
9.2.4 Extended Precision Comparisons
9.2.5 Extended Precision Multiplication
9.2.6 Extended Precision Division
9.2.7 Extended Precision NEG Operations
9.2.8 Extended Precision AND Operations
9.2.9 Extended Precision OR Operations
9.2.10 Extended Precision XOR Operations
9.2.11 Extended Precision NOT Operations
9.2.12 Extended Precision Shift Operations
9.2.13 Extended Precision Rotate Operations
9.2.14 Extended Precision I/O
9.3 Operating on Different-Sized Operands
9.4 Decimal Arithmetic
9.4.1 Literal BCD Constants
9.4.2 The 80x86 DAA and DAS Instructions
9.4.3 The 80x86 AAA, AAS, AAM, and AAD Instructions
9.4.4 Packed Decimal Arithmetic Using the FPU
9.5 Tables
9.5.1 Function Computation via Table Look-Up
9.5.2 Domain Conditioning
9.5.3 Generating Tables
9.5.4 Table Look-Up Performance
9.6 For More Information
1O
MACRoS AN D TH E H LA CoMPI LE TIME LANGUAGE
10.1 Chapter Overview
10.2 Introduction to the Compile Time Language (CTL)
10.3 The #PRINT and #ERROR Statements
10.4 Compile Time Constants and Variables
10.5 Compile Time Expressions and Operators
10.6 Compile Time Functions
10.6.1 Type Conversion Compile Time Functions
10.6.2 Numeric Compile Time Functions
10.6.3 Character Classification Compile Time Functions
10.6.4 Compile Time String Functions
10.6.5 Compile Time Pattern Matching Functions
10.6.6 Compile Time Symbol Information
10.6.7 Miscellaneous Compile Time Functions
10.6.8 Compile Time Type Conversions of TEXT Objects ..
10.7 Conditional Compilation (Compile Time Decisions)
10.8 Repetitive Compilation (Compile Time Loops)
10.9 Macros (Compile Time Procedures)
10.9.1 Standard Macros
10.9.2 Macro Parameters
10.9.3 Local Symbols in a Macro
10.9.4 Macros as Compile Time Procedures
10.9.5 Simulating Function Overloading with Macros
10.10 Writing Compile Time "Programs"
10.10.1 Constructing Data Tables at Compile Time
10.10.2 Unrolling Loops
10.11 Using Macros in Different Source Files
10.12 For More Information
11
BIT MANIPULATION
11.1 Chapter Overview
11.2 What Is Bit Data, Anyway?
11.3 Instructions That Manipulate Bits
11.4 The Carry Flag as a Bit Accumulator
11.5 Packing and Unpacking Bit Strings
11.6 Coalescing Bit Sets and Distributing Bit Strings
11.7 Packed Arrays of Bit Strings
11.8 Searching for a Bit
11.9 Counting Bits
11.10 Reversing a Bit String
11.11 Merging Bit Strings
11.12 Extracting Bit Strings
11.13 Searching for a Bit Pattern
11.14 The HLA Standard Library Bits Module
11.15 For More Information
14.6 Overriding
14.7 Virtual Methods vs. Static Procedures
14.8 Writing Class Methods and Procedures
14.9 Object Implementation
14.9.1 Virtual Method Tables
14.9.2 Object Representation with Inheritance
14.10 Constructors and Object Initialization
14.10.1 Dynamic Object Allocation Within the Constructor
14.10.2 Constructors and Inheritance
14.10.3 Constructor Parameters and Procedure Overloading
14.11 Destructors
14.12 HLA's "_initialize_" and "_finalize_" Strings
14.13 Abstract Methods
14.14 Run-Time Type Information (RTTI)
14.15 Calling Base Class Methods
14.16 For More Information
15
MIXED LANGUAGE PROGRAMMING
15.1 Chapter Overview
15.2 Mixing HLA and h~SM/Gas Code in the Same Program
15.2.1 In-Line (MASM/Gas) Assembly Code in Your HI.~ Programs
15.2.2 Linking MASM/Gas-Assembled Modules with HL~ Modules
15.3 Programming in Delpl~i/l(ylix and HI.~
15.3.1 Linking HLA Modules with Delpl~i/l(ylix Programs
15.3.2 Register Preservation
15.3.3 Function Results
15.3.4 Calling Conventions
15.3.5 Pass by Value, Reference, CONST, and OUT in Kylix
15.3.6 Scalar Data Type Correspondence Between Delphi/Kylix and H~
15.3.7 Passing String Data Between Delphi/Kylix and HLA Code
15.3.8 Passing Record Data Between HLA and Kylix
15.3.9 Passing Set Data Between Delphi/Kylix and HLA
15.3.10 Passing Array Data Between HLA and Delphi/Kylix
15.3.11 Referencing Delphi/Kylix Objects from HLA Code
15.4 Programming in C/C++ and HLA
15.4.1 Linking HLA Modules with C/C++ Programs
15.4.2 Register Preservation
15.4.3 Function Results
15.4.4 Calling Conventions
15.4.5 Pass by Value and Reference in C/C++ .
15.4.6 Scalar Data Type Correspondence Between C/C++ and HLA
15.4.7 Passing String Data Between C/C++ and HLA Code
15.4.8 Passing Record/Structure Data Between HLA and C/C++
15.4.9 Passing Array Data Between HLA and C/C++
15.5 For More Information
A
ASCII CHARACTER SET
B
THE 80X86 INSTRUCTION SET