1 Introduction 1
1.1 Introducing Assembly Language 1
Assembly Language Applications 3
Machine Language 3
1.2 Data Representation 4
Binary Numbers 4
Converting Binary to Decimal 7
Hexadecimal Numbers 7
Signed Numbers 8
Character Storage 9
1.3 Assembly Language: An Introduction 10
Assembly Language Instructions 10
A Sample Program 11
DEBUG Commands 13
The PAGE.COM Program 14
1.4 Basic Elements of Assembly Language 15
Constant 15
Statement 17
Name 18
1.5 Sample HELLO Program 19
1.6 Review Questions 20
2 Hardware and Software Architecture 22
2.1 Components of a Microcomputer 22
Video Display 22
Keyboard 23
Disk Drives 23
System Unit 23
Intel Microprocessor Family 25
2.2 System Architecture 26
Central Processing Unit (CPU) 26
Registers 28
Flags 31
Stack 32
Instruction Execution Cycle 35
2.3 System Software and Memory 35
Memory Architecture 35
DOS Initialization 36
Video Display 37
Read-Only Memory (ROM) 38
Address Calculation 38
Memory Addressing Using Registers 39
2.4 Review Questions 39
2.5 Programming Exercises 41
3 Assembly Language Fundamentals 46
3.1 Data Definition Directives 46
Define Byte (DB) 47
Define Word (DW) 49
Define Doubleword (DD) 51
DUP Operator 51
3.2 Data Transfer Instructions 52
MOV Instruction 52
Offsets 53
XCHG Instruction 55
Stack Operations 55
3.3 Arithmetic Instructions 56
INC and DEC Instructions 57
ADD Instruction 57
SUB Instruction 58
Flags Affected by ADD and SUB 58
3.4 Addressing Modes 60
Register Operand 61
Immediate Operand 61
Direct Operand 61
Indirect Operand 62
Based and Indexed Operands 63
Base-Indexed Operand 64
Base-Indexed with Displacement 64
Summing a List of Numbers 65
3.5 Program Structure 66
Memory Models 67
3.6 Review Questions 69
3.7 Programming Exercises 73
4 The Macro Assembler 76
4.1 The Assembly Process 76
A Sample Program 77
Assemble the Program 78
Link and Run the Program 79
4.2 Related Files 80
Listing File 80
Map File 81
Batch Files 82
4.3 Equates 83
The Equal-Sign Directive 83
EQU Directive 84
4.4 Operators and Expressions 85
Arithmetic Operators 85
Boolean Operators 86
OFFSET, PTR, and LABEL 86
Operands with Displacements 88
Other Assembler Operators 89
4.5 Transfer-of-Control Instructions 91
JMP Instruction 91
LOOP Instruction 93
4.6 Using the 80386 Processor 95
4.7 Debugging Workshop 96
Operand Sizes and Addressing Errors 97
4.8 Review Questions 98
4.9 Programming Exercises 103
5 Input-Output Services 106
5.1 Procedures 107
PROC and ENDP Directives 107
Sample Program: SUBS.ASM 107
Near and Far Procedures 108
5.2 Software Interrupts 111
INT Instruction 113
Device Names 115
5.3 DOS Function Calls 116
01h: Console Input With Echo 117
02h: Character Output 117
05h: Printer Output 117
06h: Direct Console Input-Output 118
07h: Direct Console Input 119
08h: Console Input Without Echo 119
09h: String Output 119
OAh: Buffered Console Input 119
OBh: Get Console Input Status 121
OCh: Clear Input Buffer, Invoke Input Function 121
BIOS-Level Keyboard Input (INT 16h) 121
ASCII Control Characters 123
5.4 BIOS-Level Video Control (INT 10h) 123
Displays, Modes, and Attributes 124
127h: Set Video Mode 127
01h: Set Cursor Lines 128
02h: Set Cursor Position 129
03h: Get Cursor Position 130
05h: Set Video Page 130
06h, 07h: Scroll Window Up or Down 131
08h: Read Character and Attribute 132
09h: Write Character and Attribute 133
0Ah: Write Character 133
0Fh: Get Video Mode 133
11h: Load Default ROM Fonts 134
5.5 Review Questions 134
5.6 Programming Exercises 137
6 Conditional Processing 141
6.1 Boolean and Comparison Instructions 141
The Flags Register 141
AND Instruction 142
OR Instruction 144
XOR Instruction 145
NOT Instruction 146
NEG Instruction 146
TEST Instruction 147
CMP Instruction 147
6.2 Conditional Jumps 148
Conditional Jump Instruction 149
Applications Using Conditional Jumps 151
6.3 Conditional Loops 157
LOOPZ (LOOPE) Instruction 157
LOOPNZ (LOOPNE) Instruction 158
6.4 High-Level Logic Structures 159
IF Statement 160
WHILE Structure 161
REPEAT ... UNTIL Structure 163
CASE Structure 164
Offset Table 165
6.5 Review Questions 166
6.6 Programming Exercises 169
7 Arithmetic 172
7.1 Shift and Rotate Instructions 173
SHL Instruction 173
SHR Instruction 175
SAL and SAR Instructions 176
ROL Instruction 176
ROR Instruction 177
RCL and RCR Instructions 178
7.2 Sample Applications 179
Shifting Multiple Bytes 179
Multiplication and Division 180
Display a Number in ASCII Binary 181
Isolate a Bit String 182
7.3 Multiple Addition and Subtraction 183
ADC Instruction 183
SBB Instruction 185
7.4 Signed Arithmetic 186
7.5 Multiplication and Division 187
MUL and IMUL Instructions 187
DIV and IDIV Instructions 189
Divide Overflow 190
7.6 ASCII Arithmetic 191
AAA Instruction 193
AAS Instruction 195
AAM Instruction 196
AAD Instruction 197
7.7 Packed Decimal Arithmetic 197
DAA Instruction 198
DAS Instruction 198
BCD Addition Example 198
7.8 Review Questions 201
7.9 Programming Exercises 204
8 Numeric Conversions and Libraries 208
8.1 Character Translation Using XLAT 209
The XLAT Instruction 209
Character Filtering 210
Character Encoding 210
8.2 Binary to ASCII Conversion 213
The WRITEINT Procedure 214
8.3 ASCII to Binary Conversion 218
The READINT Procedure 218
8.4 Separately Assembled Modules 222
EXTRN Directive 223
PUBLIC Directive 224
Calling DISPLAYSTR from Another Module 224
8.5 Creating External Subroutines 226
Individual Subroutine Descriptions 227
A Test Program 236
More About the Linker 237
8.6 Stack Parameters 238
Recursion 239
8.7 Review Questions 242
8.8 Programmming Exercises 244
9 String Processing 251
9.1 String Storage Methods 252
9.2 String Primitive Instructions 253
MOVS (Move String) 256
CMPS (Compare Strings) 258
SCAS (Scan String) 260
STOS (Store in String) 262
LODS (Load String) 263
9.3 A Library of String Routines 263
READSTRING Procedure 264
STRCHR Procedure 265
STRCOMP Procedure 266
STRCOPY Procedure 267
STRDEL Procedure 268
STRLEN Procedure 269
STRSTR Procedure 270
STRUPR Procedure 271
WRITESTRING Procedure 272
9.4 Creating a Link Library 272
9.5 Application: String Library Demo Program 275
9.6 Review Questions 278
9.7 Programming Exercises 280
10 Macros and Structures 285
10.1 Introduction 285
Declaring and Calling Macros 287
Passing Parameters 288
Nested Macros 290
LOCAL Directive 291
10.2 Special Techniques 292
Macros Calling Procedures 292
Conditional-Assembly Directives 293
EXITM Directive 295
10.3 Macro Operators 297
10.4 A Macro Library 299
10.5 Advanced MACRO Usage 303
Defining Repeat Blocks 303
Additional Tips 307
10.6 Advanced Operators and Directives 313
Type Operators 313
STRUC Directive 314
RECORD Directive 316
10.7 Review Questions 320
10.8 Programming Exercises 323
11 Disk Storage 327
11.1 Disk Storage Fundamentals 328
Physical and Logical Chacteristics 328
Types of Disks 329
Disk Formats 330
Disk Directory 331
Directory Format 332
Sample Disk Directory 334
File Allocation Table (FAT) 335
Reading and Writing Disk Sectors 336
11.2 Application: Sector Display Program 337
11.3 Application: Cluster Display Program 340
11.4 System-Level File Functions 345
DOS Error Codes 345
Displaying DOS Error Messages 346
DOS Error Me sage Handler 347
File Specifications 350
11.5 Reading the DOS Command Tail 350
11.6 Drive and Directory Manipulation 352
Set Default Disk Drive (0Eh) 353
Get Default Disk Drive (19h) 353
Get Disk Free Space (36h) 353
Get Current Directory Path (47h) 354
Set Current Directory (3Bh) 354
Create Subdirectory (39h) 355
Remove Subdirectory (3Ah) 355
Get Device Parameters (44h) 355
11.7 File Manipulation 357
Get/Set File Attribute (43h) 357