Seminar Topics & Project Ideas On Computer Science Electronics Electrical Mechanical Engineering Civil MBA Medicine Nursing Science Physics Mathematics Chemistry ppt pdf doc presentation downloads and Abstract

Full Version: MASM: Directives & Pseudo-Opcodes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
MASM: Directives & Pseudo-Opcodes

[attachment=55402]

INTRODUCTION

Statements like mov ax,0 and add ax,bx are meaningless to the microprocessor. As
arcane as these statements appear, they are still human readable forms of 80x86 instructions.
The 80x86 responds to commands like B80000 and 03C3. An assembler is a program
that converts strings like mov ax,0 to 80x86 machine code like “B80000”. An assembly language
program consists of statements like mov ax,0. The assembler converts an assembly
language source file to machine code – the binary equivalent of the assembly language
program. In this respect, the assembler program is much like a compiler, it reads an ASCII
source file from the disk and produces a machine language program as output. The major
difference between a compiler for a high level language (HLL) like Pascal and an assembler
is that the compiler usually emits several machine instructions for each Pascal statement.
The assembler generally emits a single machine instruction for each assembly
language statement.
Attempting to write programs in machine language (i.e., in binary) is not particularly
bright. This process is very tedious, prone to mistakes, and offers almost no advantages
over programming in assembly language. The only major disadvantage to assembly language
over pure machine code is that you must first assemble and link a program before
you can execute it. However, attempting to assemble the code by hand would take far
longer than the small amount of time that the assembler takes to perform the conversion
for you.
There is another disadvantage to learning assembly language. An assembler like
Microsoft's Macro Assembler (MASM) provides a large number of features for assembly
language programmers. Although learning about these features takes a fair amount of
time, they are so useful that it is well worth the effort.

Overview

Like Chapter Six, much of the information in this chapter is reference material. Like
any reference section, some knowledge is essential, other material is handy, but optional,
and some material you may never use while writing programs. The following list outlines
the information in this text.

The Location Counter

Recall that all addresses in the 80x86's memory space consist of a segment address
and an offset within that segment. The assembler, in the process of converting your
source file into object code, needs to keep track of offsets within the current segment. The
location counter is an assembler variable that handles this.
Whenever you create a segment in your assembly language source file (see segments
later in this chapter), the assembler associates the current location counter value with it.
The location counter contains the current offset into the segment. Initially (when the
assembler first encounters a segment) the location counter is set to zero. When encountering
instructions or pseudo-opcodes, MASM increments the location counter for each byte
written to the object code file. For example, MASM increments the location counter by
two after encountering mov ax, bx since this instruction is two bytes long.

Literal Constants

The Microsoft Macro Assembler (MASM) is capable of processing five different types
of constants: integers, packed binary coded decimal integers, real numbers, strings, and
text. In this chapter we'll consider integers, reals, strings, and text only. For more information
about packed BCD integers please consult the Microsoft Macro Assembler Programmer's
Guide.

Text Constants

Text constants are not the same thing as string constants. A textual constant substitutes
verbatim during the assembly process. For example, the characters 5[bx] could be a
textual constant associated with the symbol VAR1. During assembly, an instruction of the
form mov ax, VAR1 would be converted to the instruction mov ax, 5[bx].