22-02-2013, 03:43 PM
Programmer’s Guide
Programmer’s Guide.pdf (Size: 1.55 MB / Downloads: 29)
Introduction
The Microsoft® Macro Assembler Programmer’s Guide provides the
information you need to write and debug assembly-language programs with the
Microsoft Macro Assembler (MASM), version 6.1. This book documents
enhanced features of the language and the programming environment for
MASM 6.1.
This Programmer’s Guide is written for experienced programmers who know
assembly language and are familiar with an assembler. The book does not teach
the basics of assembly language; it does explain Microsoft-specific features. If
you want to learn or review the basics of assembly language, refer to “Books for
Further Reading” in this introduction.
This book teaches you how to write efficient code with the new and advanced
features of MASM. Getting Started explains how to set up MASM 6.1.
Environment and Tools introduces the integrated development environment
called the Programmer’s WorkBench (PWB). It also includes a detailed
reference to Microsoft tools and utilities such as Microsoft ® CodeView®,
LINK, and NMAKE. The Microsoft Macro Assembler Reference provides a full
listing of all MASM instructions, directives, statements, and operators, and it
serves as a quick reference to utility commands.
New and Extended Features in MASM 6.1
MASM 6.1 continues the break with tradition established by version 6.0. It
incorporates conveniences of high-level languages while offering all the
traditional advantages of assembly-language programming.
For example, MASM 6.1 includes the Programmer’s WorkBench, which
provides the same integrated software development environment enjoyed by
programmers of Microsoft high-level languages such as C and Basic. From
within PWB you can edit, build, debug, or run a program. You can perform
most of these operations with either menu selections or keyboard commands.
You can also customize PWB to suit your individual programming and editing
requirements and preferences.
ML and MASM Command Lines
MASM 6.1 provides an updated version of the command-line driver, ML,
introduced in version 6.0. ML is more powerful and flexible than the MASM
driver of version 5.1. ML assembles and links with one command. It recognizes
all the old MASM driver command syntax, however, to support existing batch
files and makefiles that use MASM command lines.
Compatibility with Earlier Versions of MASM
MASM 6.1 is fully compatible with version 6.0 and, in many cases, with version
5.1. Code written for MASM 5.1 will often assemble correctly without
modification under MASM 6.1. However, MASM 6.1 provides the OPTION
directive to let you selectively modify the assembly process. In particular, you
can use the M510 argument with OPTION or the /Zm command-line option to
set most features to be compatible with version 5.1 code.
A Word About Instruction Timings
As an assembly-language programmer, whether novice or expert, you are
probably interested in producing lightning-fast code. After all, one of the main
reasons to program in assembly is to take advantage of its ability to streamline
execution speeds to the limit of the processor. This book will help you write
efficient and fast programs.
When discussing the speed of individual instructions, the chapters in this book
often speak of “timing,” which is the number of processor cycles required to
carry out an instruction. The Reference lists instruction timings for processors in
the 8086 family. It is tempting to use timing as the only criterion when judging
an instruction’s actual execution speed, but the world within the processor is not
so simple.
Understanding Global Concepts
With the development of the Microsoft Macro Assembler (MASM) version 6.1,
you now have more options available to you for approaching a programming
task. This chapter explains the general concepts of programming in assembly
language, beginning with the environment and a review of the components you
need to work in the assembler environment. Even if you are familiar with
previous versions of MASM, you should examine this chapter for information
on new terms and features.
The first section of this chapter reviews available processors and operating
systems and how they work together. The section also discusses segmented
architecture and how it affects a protected-mode operating environment such as
Windows.
The second section describes some of the language components of MASM that
are common to most programs, such as reserved words, constant expressions,
operators, and registers. The remainder of this book was written with the
assumption that you understand the information presented in this section.
The Processing Environment
The processing environment for MASM 6.1 includes the processor on which
your programs run, the operating system your programs use, and the aspects of
the segmented architecture that influence the choice of programming models.
This section summarizes these elements of the environment and how they affect
your programming choices.
Operating Systems
With MASM, you can create programs that run under MS-DOS, Windows, or
Windows NT—or all three, in some cases. For example, ML.EXE can produce
executable files that run in any of the target environments, regardless of the
programmer’s environment. For information on building programs for different
environments, see “Building and Running Programs” in Help for PWB.
MS-DOS and Windows 3.1 provide different processing modes. MS-DOS runs
in the single-process real mode. Windows 3.1 operates in protected mode,
allowing multiple processes to run simultaneously.
Although Windows requires another operating system for loading and file
services, it provides many functions normally associated with an operating
system. When an application requests an MS-DOS service, Windows often
provides the service without invoking MS-DOS. For consistency, this book
refers to Windows as an operating system.