Hardware Reference
In-Depth Information
EQU is used to give a symbolic name to an expression. For example, after the
pseudoinstruction
BASE EQU 1000
the symbol BASE can be used everywhere instead of 1000. The expression that fol-
lows the EQU can involve multiple defined symbols combined with arithmetic and
other operators, as in
LIMIT EQU 4 * BASE + 2000
Most assemblers, including MASM, require that a symbol be defined before it is
used in an expression like this.
The next four pseudoinstructions, DB, DW, DD, and DQ , allocate storage for one
or more variables of size 1, 2, 4, or 8 bytes, respectively. For example,
TABLE DB 11, 23, 49
allocates space for 3 bytes and initializes them to 11, 23, and 49, respectively. It
also defines the symbol TABLE and sets it equal to the address where 11 is stored.
The PROC and ENDP pseudoinstructions define the beginning and end of as-
sembly language procedures, respectively. Procedures in assembly language have
the same function as procedures in other programming languages. Similarly,
MACRO and ENDM delimit the scope of a macro definition. We will study macros
later in this chapter.
The next two pseudoinstructions, PUBLIC and EXTERN , control the visibility of
symbols. It is common to write programs as a collection of files. Frequently, a
procedure in one file needs to call a procedure or access a data word defined in an-
other file. To make this cross-file referencing possible, a symbol that is to be made
available to other files is exported using PUBLIC . Similarly, to prevent the assem-
bler from complaining about the use of a symbol that is not defined in the current
file, the symbol can be declared as EXTERN , which tells the assembler that it will
be defined in some other file. Symbols that are not declared in either of these
pseudoinstructions have a scope of the local file. This default means that using,
say, FOO in multiple files does not generate a conflict because each definition is
local to its own file.
The INCLUDE pseudoinstruction causes the assembler to fetch another file and
include it bodily into the current one. Such included files often contain definitions,
macros, and other items needed in multiple files.
Many assemblers, support conditional assembly. For example,
WORDSIZE EQU 32
IF WORDSIZE GT 32
WSIZE:
DD 64
ELSE
WSIZE:
DD 32
ENDIF
Search WWH ::




Custom Search