Assembly-Language Development System
For MS-DOS® and Windows Operating Systems
Information in this document is subject to change without notice. Companies, names, and data used in examples herein are fictitious unless otherwise noted. No part of this document maybe reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Microsoft Corporation.
©1992 Microsoft Corporation. All rights reserved.
Microsoft, MS, MS-DOS, XENIX, CodeView, and QuickC are registered trademarks and Microsoft QuickBasic, QuickPascal, Windows and Windows NT are trademarks of Microsoft Corporation in the USA and other countries.
Hercules is a registered trademark of Hercules Computer Technology.
IBM, PS/2, and OS/2 are registered trademarks of International Business Machines Corporation.
Intel is a registered trademark of Intel Corporation.
NEC and V25 are registered trademarks and V35 is a trademark of NEC Corporation.
Printed in the United States of America.
New and Extended Features in MASM 6.1 xiii
MASM Features New Since Version 5.1 xiv
MASM Features New Since Version 6.0 xv
Compatibility with Earlier Versions of MASM xvi
A Word About Instruction Timings xvii
Books for Further Reading xviii
Getting Assistance and Reporting Problems xx
Chapter 1 Understanding Global Concepts 1
Integer Constants and Constant Expressions 11
Generating and Running Executable Programs 23
Chapter 2 Organizing Segments 31
Using Simplified Segment Directives 33
Defining Basic Attributes with .MODEL 34
Specifying a Processor and Coprocessor 38
Starting and Ending Code with .STARTUP and .EXIT 41
Using Full Segment Definitions 44
Defining Segments with the SEGMENT Directive 44
Controlling the Segment Order 47
Setting the ASSUME Directive for Segment Registers 49
Chapter 3 Using Addresses and Pointers 53
Programming Segmented Addresses 53
Initializing Default Segment Registers 53
Saving Operands on the Stack 71
Saving Registers on the Stack (80186-80486 Only) 74
Accessing Data with Pointers and Addresses 74
Defining Pointer Types with TYPEDEF 75
Defining Register Types with ASSUME 77
Basic Pointer and Address Operations 78
Chapter 4 Defining and Using Simple Data Types 85
Declaring Integer Variables 85
Allocating Memory for Integer Variables 85
Working with Simple Variables 88
Adding and Subtracting Integers 92
Multiplying and Dividing Integers 95
Manipulating Numbers at the Bit Level 98
Shifting and Rotating Bits 100
Multiplying and Dividing with Shift Instructions 102
Chapter 5 Defining and Using Complex Data Types 105
Declaring and Referencing Arrays 105
Declaring and Initializing Strings 108
Declaring Structure and Union Types 118
Defining Structure and Union Variables 121
Referencing Structures, Unions, and Fields 126
Nested Structures and Unions 128
Chapter 6 Using Floating-Point and Binary Coded Decimal Numbers 135
Using Floating-Point Numbers 136
Declaring Floating-Point Variables and Constants 136
Storing Numbers in Floating-Point Format 138
Instruction and Operand Formats 141
Coordinating Memory Access 145
Using Coprocessor Instructions 146
Using Binary Coded Decimal Numbers 156
Defining BCD Constants and Variables 157
BCD Calculations on a Coprocessor 157
BCD Calculations on the Main Processor 158
Chapter 7 Controlling Program Flow 161
Loop-Generating Directives 173
Passing Arguments on the Stack 182
Declaring Parameters with the PROC Directive 184
Creating Local Variables Automatically 190
Declaring Procedure Prototypes 193
Calling Procedures with INVOKE 194
Generating Prologue and Epilogue Code 198
Calling MS-DOS and ROM-BIOS Interrupts 204
Replacing an Interrupt Routine 206
Chapter 8 Sharing Data and Procedures Among Modules and Libraries 211
Selecting Data-Sharing Methods 211
Sharing Symbols with Include Files 212
Declaring Symbols Public and External 214
Positioning External Declarations 228
Using Alternatives to Include Files 219
Associating Libraries with Modules 222
Using EXTERN with Library Routines 223
Passing Arguments to Macros 228
Specifying Required and Default Parameters 229
Defining Local Symbols in Macros 232
Assembly-Time Variables and Macro Operators 233
Text Delimiters and the Literal-Character Operator 234
Defining Repeat Blocks with Loop Directives 239
FOR Loops and Variable-Length Parameters 242
String Directives and Predefined Functions 245
Returning Values with Macro Functions 248
Returning Values with EXITM 248
Using Macro Functions with Variable-Length Parameter Lists 249
Expansion Operator in Macro Functions 251
Defining Macros within Macros 251
Testing for Argument Type and Environment 252
Chapter 10 Writing a Dynamic-Link Library For Windows 257
Chapter 11 Writing Memory-Resident Software 273
Terminate-and-Stay-Resident Programs 273
Interrupt Handlers in Active TSRs 275
Auditing Hardware Events for TSR Requests 275
Determining Whether to Invoke the TSR 279
Example of a Simple TSR: ALARM 279
Using MS-DOS in Active TSRs 285
Understanding MS-DOS Stacks 285
Determining MS-DOS Activity 285
Interrupting MS-DOS Functions 286
Monitoring the Critical Error Flag 287
Preserving an Existing Condition 289
Communicating Through the Multiplex Interrupt 290
Using the Multiplex Interrupt Under MS-DOS Version 2.x 292
Example of an Advanced TSR: SNAP 293
Chapter 12 Mixed-Language Programming 307
Naming and Calling Conventions 308
The Pascal Calling Convention 310
The STDCALL and SYSCALL Calling Conventions 311
Writing an Assembly Procedure For a Mixed-Language Program 312
The MASM/High-Level-Language Interface 313
The FORTRAN/MASM Interface 323
Chapter 13 Writing 32-Bit Applications 335
MASM Directives for 32-Bit Programming 336
Appendix A Differences Between MASM 6.1 and 5.1 341
New Features of Version 6.1 342
The Assembler, Environment, and Utilities 342
Procedures, Loops, and Jumps 347
Simplifying Multiple-Module Projects 348
New Processor Instructions 350
MASM 6.1 Programming Practices 352
Compatibility Between MASM 5.1 and 6.1 352
Rewriting Code for Compatibility 353
Using the OPTION Directive 361
Changes to Instruction Encodings 377
Appendix C Generating and Reading Assembly Listings 397
Precedence of Command-Line Options and Listing Directives 399
Reading Tables in a Listing File 404
Appendix D MASM Reserved Words 407
Special Operands for the 80386/486 409
8086/8088 Processor Instructions 412
80186 Processor Instructions 413
80286 Processor Instructions 413
80286 and 80386 Privileged-Mode Instructions 413
80386 Processor Instructions 413
80486 Processor Instructions 414
8087 Coprocessor Instructions 414
80287 Privileged-Mode Instruction 415
Appendix E Default Segment Names 417
1.2 Calculating Physical Addresses 8
1.3 Registers for 8088-80286 Processors 17
1.4 Extended Registers for the 80386/486 Processors 18
1.5 Flags for 8088-80486 Processors 20
3.1 Stack Status Before and After Pushes and Pops 72
6.1 Encoding for Real Numbers in IEEE Format 138
6.2 Coprocessor Data Registers 140
6.3 Status of the Register Stack 142
6.4 Status of the Register Stack and Memory Locations 143
6.5 Status of the Previously Initialized Register Stack 144
6.6 Status of the Already Initialized Register Stack 144
6.7 Status of the Register Stack: Main Memory and Coprocessor 148
6.8 Coprocessor Control Registers 154
6.9 Coprocessor and Processor Control Flags 155
7.1 Program Arguments on the Stack 183
7.2 Local Variables on the Stack 190
7.3 Operation of Interrupts 206
8.1 Using EXTERNDEF for Variables 215
8.2 Using PROTO and INVOKE 217
8.3 Using PUBLIC and EXTERN 221
11.1 Time Line of Interaction Between Interrupt Handlers
for a Typical TSR 27811.2 Flowchart for SNAP.EXE: Installation Phase 296
11.3 Flowchart for SNAP.EXE Resident Phase 297
11.4 Flowchart for SNAP.EXE Deinstallation Phase 298
12.5 Basic String Descriptor Format 330
B.1 BNF Definition of the TYPEDEF Directive 380
1.1 8086 Family of Processors 2
1.2 The MS-DOS and Windows Operating Systems Compared 4
2.1 Attributes of Memory Models 35
3.1 Indirect Addressing with 16-Bit Registers 68
5.1 Requirements for String Instructions 112
6.1 Ranges of Floating-Point Variables 136
6.2 Coprocessor Operand Formats 141
6.3 Control-Flag Settings After Comparison or Test 151
7.1 Conditional Jumps Based on Comparisons of Two Values 167
11.1 MS-DOS Internal Stacks 286
12.1 Naming and Calling Conventions 309
12.2 Register Conventions for Simple Return Values 317
A.1 Requirements for String Instructions 353
C.1 Options for Generating or Modifying Listing Files 398
C.2 Symbols and Abbreviations in Listings 400
C.3 Symbols in Timing Column 401
|
Quadralay Corporation http://www.webworks.com Voice: (512) 719-3399 Fax: (512) 719-3606 sales@webworks.com |