| Acknowledgments |
|
xix | |
|
Hello, World of Assembly Language |
|
|
1 | (52) |
|
The Anatomy of an HLA Program |
|
|
2 | (2) |
|
Running Your First HLA Program |
|
|
4 | (1) |
|
Some Basic HLA Data Declarations |
|
|
5 | (2) |
|
|
|
7 | (1) |
|
|
|
8 | (1) |
|
An Introduction to the Intel 80x86 CPU Family |
|
|
8 | (3) |
|
|
|
11 | (3) |
|
Some Basic Machine Instructions |
|
|
14 | (3) |
|
Some Basic HLA Control Structures |
|
|
17 | (15) |
|
Boolean Expressions in HLA Statements |
|
|
18 | (2) |
|
The HLA if..then..elseif..else..endif Statement |
|
|
20 | (2) |
|
Conjunction, Disjunction, and Negation in Boolean Expressions |
|
|
22 | (2) |
|
The while..endwhile Statement |
|
|
24 | (1) |
|
The for..endfor Statement |
|
|
25 | (1) |
|
The repeat..until Statement |
|
|
26 | (1) |
|
The break and breakif Statements |
|
|
27 | (1) |
|
The forever..endfor Statement |
|
|
28 | (1) |
|
The try..exception..endtry Statement |
|
|
28 | (4) |
|
Introduction to the HLA Standard Library |
|
|
32 | (10) |
|
Predefined Constants in the stdio Module |
|
|
33 | (1) |
|
Standard In and Standard Out |
|
|
34 | (1) |
|
|
|
35 | (1) |
|
The stdout.puti X Routines |
|
|
35 | (1) |
|
The stdout.puti XSize Routines |
|
|
35 | (2) |
|
|
|
37 | (1) |
|
|
|
38 | (1) |
|
The stdin.geti X Routines |
|
|
39 | (1) |
|
The stdin.readLn and stdin.flushinput Routines |
|
|
40 | (1) |
|
|
|
41 | (1) |
|
Additional Details About try..endtry |
|
|
42 | (8) |
|
Nesting try..endtry Statements |
|
|
43 | (2) |
|
The unprotected Clause in a try..endtry Statement |
|
|
45 | (3) |
|
The anyexception Clause in a try..endtry Statement |
|
|
48 | (1) |
|
Registers and the try..endtry Statement |
|
|
48 | (2) |
|
High-Level Assembly Language vs. Low-Level Assembly Language |
|
|
50 | (1) |
|
|
|
51 | (2) |
|
|
|
53 | (58) |
|
|
|
54 | (2) |
|
A Review of the Decimal System |
|
|
54 | (1) |
|
The Binary Numbering System |
|
|
54 | (1) |
|
|
|
55 | (1) |
|
The Hexadecimal Numbering System |
|
|
56 | (2) |
|
|
|
58 | (6) |
|
|
|
58 | (1) |
|
|
|
59 | (1) |
|
|
|
60 | (1) |
|
|
|
61 | (1) |
|
|
|
62 | (1) |
|
Quad Words and Long Words |
|
|
63 | (1) |
|
Arithmetic Operations on Binary and Hexadecimal Numbers |
|
|
64 | (1) |
|
A Note About Numbers vs. Representation |
|
|
65 | (2) |
|
Logical Operations on Bits |
|
|
67 | (3) |
|
Logical Operations on Binary Numbers and Bit Strings |
|
|
70 | (2) |
|
Signed and Unsigned Numbers |
|
|
72 | (4) |
|
Sign Extension, Zero Extension, Contraction, and Saturation |
|
|
76 | (4) |
|
|
|
80 | (5) |
|
Bit Fields and Packed Data |
|
|
85 | (4) |
|
An Introduction to Floating-Point Arithmetic |
|
|
89 | (11) |
|
IEEE Floating-Point Formats |
|
|
93 | (3) |
|
HLA Support for Floating-Point Values |
|
|
96 | (4) |
|
Binary-Coded Decimal Representation |
|
|
100 | (1) |
|
|
|
101 | (8) |
|
The ASCII Character Encoding |
|
|
101 | (4) |
|
HLA Support for ASCII Characters |
|
|
105 | (4) |
|
The Unicode Character Set |
|
|
109 | (1) |
|
|
|
110 | (1) |
|
Memory Access and Organization |
|
|
111 | (44) |
|
The 80x86 Addressing Modes |
|
|
112 | (8) |
|
80x86 32-Bit Memory Addressing Modes |
|
|
113 | (6) |
|
Runtime Memory Organization |
|
|
119 | (1) |
|
|
|
120 | (7) |
|
|
|
122 | (1) |
|
The readonly Data Section |
|
|
123 | (1) |
|
|
|
123 | (1) |
|
|
|
124 | (1) |
|
|
|
125 | (1) |
|
Organization of Declaration Sections Within Your Programs |
|
|
126 | (1) |
|
How HLA Allocates Memory for Variables |
|
|
127 | (1) |
|
HLA Support for Data Alignment |
|
|
128 | (3) |
|
|
|
131 | (2) |
|
|
|
133 | (3) |
|
|
|
136 | (1) |
|
The stack Segment and the push and pop Instructions |
|
|
137 | (3) |
|
The Basic push Instruction |
|
|
137 | (1) |
|
The Basic pop Instruction |
|
|
138 | (2) |
|
Preserving Registers with the push and pop Instructions |
|
|
140 | (1) |
|
The Stack Is a LIFO Data Structure |
|
|
140 | (6) |
|
Other push and pop Instructions |
|
|
143 | |
|
Removing Data from the Stack Without Popping It |
|
|
140 | (6) |
|
Accessing Data You've Pushed onto the Stack Without Popping It |
|
|
146 | (1) |
|
Dynamic Memory Allocation and the Heap Segment |
|
|
147 | (5) |
|
The inc and dec Instructions |
|
|
152 | (1) |
|
Obtaining the Address of a Memory Object |
|
|
152 | (1) |
|
|
|
153 | (2) |
|
Constants, Variables, and Data Types |
|
|
155 | (100) |
|
Some Additional Instructions: intmul, bound, into |
|
|
156 | (4) |
|
HLA Constant and Value Declarations |
|
|
160 | (13) |
|
|
|
164 | (1) |
|
String and Character Literal Constants |
|
|
165 | (2) |
|
String and Text Constants in the const Section |
|
|
167 | (2) |
|
|
|
169 | (2) |
|
Multiple const Sections and Their Order in an HLA Program |
|
|
171 | (1) |
|
|
|
172 | (1) |
|
Modifying val Objects at Arbitrary Points in Your Programs |
|
|
173 | (1) |
|
|
|
173 | (1) |
|
enum and HLA Enumerated Data Types |
|
|
174 | (1) |
|
|
|
175 | (10) |
|
Using Pointers in Assembly Language |
|
|
177 | (1) |
|
Declaring Pointers in HLA |
|
|
178 | (1) |
|
Pointer Constants and Pointer Constant Expressions |
|
|
179 | (1) |
|
Pointer Variables and Dynamic Memory Allocation |
|
|
180 | (1) |
|
|
|
180 | (5) |
|
|
|
185 | (1) |
|
|
|
185 | (3) |
|
|
|
188 | (6) |
|
Accessing the Characters Within a String |
|
|
194 | (2) |
|
The HLA String Module and Other String-Related Routines |
|
|
196 | (12) |
|
|
|
208 | (1) |
|
|
|
209 | (1) |
|
Character Set Implementation in HLA |
|
|
210 | (2) |
|
HLA Character Set Constants and Character Set Expressions |
|
|
212 | (1) |
|
Character Set Support in the HLA Standard Library |
|
|
213 | (4) |
|
Using Character Sets in Your HLA Programs |
|
|
217 | (1) |
|
|
|
218 | (1) |
|
Declaring Arrays in Your HLA Programs |
|
|
219 | (1) |
|
|
|
220 | (1) |
|
Accessing Elements of a Single-Dimensional Array |
|
|
221 | (3) |
|
Sorting an Array of Values |
|
|
224 | (1) |
|
|
|
224 | (5) |
|
|
|
225 | (3) |
|
|
|
228 | (1) |
|
Allocating Storage for Multidimensional Arrays |
|
|
229 | (2) |
|
Accessing Multidimensional Array Elements in Assembly Language |
|
|
231 | (2) |
|
|
|
233 | (2) |
|
|
|
235 | (1) |
|
|
|
236 | (1) |
|
Arrays/Records as Record Fields |
|
|
237 | (4) |
|
Aligning Fields Within a Record |
|
|
241 | (1) |
|
|
|
242 | (1) |
|
|
|
243 | (3) |
|
|
|
246 | (1) |
|
|
|
247 | (1) |
|
|
|
248 | (3) |
|
Dynamic Arrays in Assembly Language |
|
|
251 | (3) |
|
|
|
254 | (1) |
|
|
|
255 | (96) |
|
|
|
255 | (3) |
|
Saving the State of the Machine |
|
|
258 | (4) |
|
Prematurely Returning from a Procedure |
|
|
262 | (1) |
|
|
|
262 | (6) |
|
Other Local and Global Symbol Types |
|
|
268 | (1) |
|
|
|
268 | (7) |
|
|
|
269 | (4) |
|
|
|
273 | (2) |
|
Functions and Function Results |
|
|
275 | (7) |
|
Returning Function Results |
|
|
276 | (1) |
|
Instruction Composition in HLA |
|
|
277 | (3) |
|
The HLA returns Option in Procedures |
|
|
280 | (2) |
|
|
|
282 | (4) |
|
|
|
286 | (1) |
|
HLA v2.0 Procedures Declarations |
|
|
287 | (1) |
|
Low-Level Procedures and the call Instruction |
|
|
288 | (2) |
|
|
|
290 | (3) |
|
|
|
293 | (3) |
|
The Standard Entry Sequence |
|
|
296 | (2) |
|
The Standard Exit Sequence |
|
|
298 | (1) |
|
Low-Level Implementation of Automatic (Local) Variables |
|
|
299 | (2) |
|
Low-Level Parameter Implementation |
|
|
301 | (28) |
|
Passing Parameters in Registers |
|
|
301 | (3) |
|
Passing Parameters in the Code Stream |
|
|
304 | (3) |
|
Passing Parameters on the Stack |
|
|
307 | (22) |
|
|
|
329 | (4) |
|
|
|
333 | (1) |
|
Untyped Reference Parameters |
|
|
334 | (1) |
|
|
|
335 | (1) |
|
|
|
336 | (1) |
|
Ignoring Duplicate #include Operations |
|
|
337 | (1) |
|
Units and the external Directive |
|
|
338 | (7) |
|
Behavior of the external Directive |
|
|
343 | (1) |
|
|
|
344 | (1) |
|
|
|
345 | (3) |
|
|
|
348 | (3) |
|
|
|
351 | (62) |
|
80x86 Integer Arithmetic Instructions |
|
|
351 | (14) |
|
The mul and imul Instructions |
|
|
352 | (3) |
|
The div and idiv Instructions |
|
|
355 | (2) |
|
|
|
357 | (5) |
|
|
|
362 | (2) |
|
|
|
364 | (1) |
|
|
|
365 | (10) |
|
|
|
366 | (1) |
|
|
|
366 | (3) |
|
|
|
369 | (5) |
|
|
|
374 | (1) |
|
Logical (Boolean) Expressions |
|
|
375 | (2) |
|
Machine and Arithmetic Idioms |
|
|
377 | (3) |
|
Multiplying without mul, imul, or intmul |
|
|
378 | (1) |
|
Division Without div or idiv |
|
|
379 | (1) |
|
Implementing Modulo-N Counters with and |
|
|
380 | (1) |
|
Floating-Point Arithmetic |
|
|
380 | (26) |
|
|
|
380 | (7) |
|
|
|
387 | (2) |
|
|
|
389 | (1) |
|
FPU Data Movement Instructions |
|
|
389 | (2) |
|
|
|
391 | (3) |
|
|
|
394 | (5) |
|
|
|
399 | (3) |
|
|
|
402 | (1) |
|
Transcendental Instructions |
|
|
402 | (2) |
|
Miscellaneous Instructions |
|
|
404 | (1) |
|
|
|
405 | (1) |
|
Converting Floating-Point Expressions to Assembly Language |
|
|
406 | (5) |
|
Converting Arithmetic Expressions to Postfix Notation |
|
|
407 | (2) |
|
Converting Postfix Notation to Assembly Language |
|
|
409 | (2) |
|
HLA Standard Library Support for Floating-Point Arithmetic |
|
|
411 | (1) |
|
|
|
411 | (2) |
|
Low-Level Control Structures |
|
|
413 | (64) |
|
Low-Level Control Structures |
|
|
414 | (1) |
|
|
|
414 | (2) |
|
Unconditional Transfer of Control (imp) |
|
|
416 | (2) |
|
The Conditional Jump Instructions |
|
|
418 | (3) |
|
``Medium-Level'' Control Structures: it and if |
|
|
421 | (1) |
|
Implementing Common Control Structures in Assembly Language |
|
|
422 | (1) |
|
Introduction to Decisions |
|
|
422 | (30) |
|
|
|
424 | (3) |
|
Translating HLA if Statements into Pure Assembly Language |
|
|
427 | (5) |
|
Implementing Complex if Statements Using Complete Boolean Evaluation |
|
|
432 | (1) |
|
Short-Circuit Boolean Evaluation |
|
|
433 | (2) |
|
Short-Circuit vs. Complete Boolean Evaluation |
|
|
435 | (2) |
|
Efficient Implementation of if Statements in Assembly Language |
|
|
437 | (5) |
|
|
|
442 | (10) |
|
State Machines and Indirect Jumps |
|
|
452 | (3) |
|
|
|
455 | (1) |
|
|
|
456 | (10) |
|
|
|
457 | (1) |
|
|
|
458 | (1) |
|
|
|
459 | (1) |
|
|
|
460 | (1) |
|
The break and continue Statements |
|
|
461 | (4) |
|
|
|
465 | (1) |
|
|
|
466 | (7) |
|
Moving the Termination Condition to the End of a Loop |
|
|
466 | (3) |
|
Executing the Loop Backwards |
|
|
469 | (1) |
|
Loop-Invariant Computations |
|
|
470 | (1) |
|
|
|
471 | (1) |
|
|
|
472 | (1) |
|
Hybrid Control Structures in HLA |
|
|
473 | (3) |
|
|
|
476 | (1) |
|
|
|
477 | (74) |
|
Multiprecision Operations |
|
|
478 | (52) |
|
HLA Standard Library Support for Extended-Precision Operations |
|
|
478 | (2) |
|
Multiprecision Addition Operations |
|
|
480 | (3) |
|
Multiprecision Subtraction Operations |
|
|
483 | (2) |
|
Extended-Precision Comparisons |
|
|
485 | (3) |
|
Extended-Precision Multiplication |
|
|
488 | (4) |
|
Extended-Precision Division |
|
|
492 | (9) |
|
Extended-Precision neg Operations |
|
|
501 | (2) |
|
Extended-Precision and Operations |
|
|
503 | (1) |
|
Extended-Precision or Operations |
|
|
503 | (1) |
|
Extended-Precision xor Operations |
|
|
504 | (1) |
|
Extended-Precision not Operations |
|
|
504 | (1) |
|
Extended-Precision Shift Operations |
|
|
504 | (4) |
|
Extended-Precision Rotate Operations |
|
|
508 | (1) |
|
|
|
509 | (21) |
|
Operating on Different-Size Operands |
|
|
530 | (2) |
|
|
|
532 | (7) |
|
|
|
533 | (1) |
|
The 80x86 daa and das Instructions |
|
|
534 | (1) |
|
The 80x86 aaa, aas, aam, and aad Instructions |
|
|
535 | (2) |
|
Packed Decimal Arithmetic Using the FPU |
|
|
537 | (2) |
|
|
|
539 | (10) |
|
Function Computation via Table Lookup |
|
|
539 | (5) |
|
|
|
544 | (1) |
|
|
|
545 | (3) |
|
|
|
548 | (1) |
|
|
|
549 | (2) |
|
Macros and The HLA Compile-Time Language |
|
|
551 | (48) |
|
Introduction to the Compile-Time Language (CTL) |
|
|
551 | (2) |
|
The #print and #error Statements |
|
|
553 | (2) |
|
Compile-Time Constants and Variables |
|
|
555 | (1) |
|
Compile-Time Expressions and Operators |
|
|
555 | (3) |
|
|
|
558 | (7) |
|
Type-Conversion Compile-Time Functions |
|
|
559 | (2) |
|
Numeric Compile Time Functions |
|
|
561 | (1) |
|
Character-Classification Compile-Time Functions |
|
|
561 | (1) |
|
Compile-Time String Functions |
|
|
561 | (1) |
|
Compile-Time Symbol Information |
|
|
562 | (1) |
|
Miscellaneous Compile-Time Functions |
|
|
563 | (1) |
|
Compile-Time Type Conversions of Text Objects |
|
|
564 | (1) |
|
Conditional Compilation (Compile-Time Decisions) |
|
|
565 | (5) |
|
Repetitive Compilation (Compile-Time Loops) |
|
|
570 | (3) |
|
Macros (Compile-Time Procedures) |
|
|
573 | (19) |
|
|
|
574 | (2) |
|
|
|
576 | (6) |
|
|
|
582 | (3) |
|
Macros as Compile-Time Procedures |
|
|
585 | (1) |
|
Simulating Function Overloading with Macros |
|
|
586 | (6) |
|
Writing Compile-Time ``Programs'' |
|
|
592 | (6) |
|
Constructing Data Tables at Compile Time |
|
|
592 | (4) |
|
|
|
596 | (2) |
|
Using Macros in Different Source Files |
|
|
598 | (1) |
|
|
|
598 | (1) |
|
|
|
599 | (34) |
|
What Is Bit Data, Anyway? |
|
|
600 | (1) |
|
Instructions That Manipulate Bits |
|
|
601 | (8) |
|
The Carry Flag as a Bit Accumulator |
|
|
609 | (1) |
|
Packing and Unpacking Bit Strings |
|
|
609 | (3) |
|
Coalescing Bit Sets and Distributing Bit Strings |
|
|
612 | (3) |
|
Packed Arrays of Bit Strings |
|
|
615 | (2) |
|
|
|
617 | (3) |
|
|
|
620 | (3) |
|
|
|
623 | (2) |
|
|
|
625 | (1) |
|
|
|
626 | (1) |
|
Searching for a Bit Pattern |
|
|
627 | (1) |
|
The HLA Standard Library Bits Module |
|
|
628 | (3) |
|
|
|
631 | (2) |
|
|
|
633 | (18) |
|
The 80x86 String Instructions |
|
|
634 | (16) |
|
How the String Instructions Operate |
|
|
634 | (1) |
|
The rep/repe/repz and repnz/repne Prefixes |
|
|
635 | (1) |
|
|
|
636 | (2) |
|
|
|
638 | (9) |
|
|
|
647 | (1) |
|
|
|
647 | (1) |
|
|
|
648 | (1) |
|
|
|
648 | (1) |
|
Building Complex String Functions from lods and stos |
|
|
649 | (1) |
|
Performance of the 80x86 String Instructions |
|
|
650 | (1) |
|
|
|
650 | (1) |
|
|
|
651 | (50) |
|
|
|
652 | (2) |
|
|
|
654 | (3) |
|
|
|
657 | (2) |
|
|
|
659 | (1) |
|
|
|
660 | (1) |
|
Virtual Methods vs. Static Procedures |
|
|
661 | (2) |
|
Writing Class Methods and Procedures |
|
|
663 | (5) |
|
|
|
668 | (9) |
|
|
|
671 | (2) |
|
Object Representation with Inheritance |
|
|
673 | (4) |
|
Constructors and Object Initialization |
|
|
677 | (9) |
|
Dynamic Object Allocation Within the Constructor |
|
|
679 | (2) |
|
Constructors and Inheritance |
|
|
681 | (4) |
|
Constructor Parameters and Procedure Overloading |
|
|
685 | (1) |
|
|
|
686 | (1) |
|
HLA's_initialize_and_finalize_Strings |
|
|
687 | (6) |
|
|
|
693 | (3) |
|
|
|
696 | (2) |
|
Calling Base Class Methods |
|
|
698 | (1) |
|
|
|
699 | (2) |
| Appendix ASCII Character Set |
|
701 | (4) |
| Index |
|
705 | |