Hardware Reference
In-Depth Information
Assembly language statements have up to four parts: first, a label field, second,
an operation (opcode) field, third, an operand field, and fourth, a comments field.
None of these is mandatory. Labels, which are used to provide symbolic names for
memory addresses, are needed on executable statements so that the statements can
be branched to. Additionally, they are needed for data words to permit the data
stored there to be accessible by symbolic name. If a statement is labeled, the label
(usually) begins in column 1.
The example of Fig. 7-1 has four labels: FORMULA , I , J , and N . The MASM
requires colons on code labels but not on data labels. There is nothing fundamen-
tal about this. Other assemblers may have other requirements. Nothing in the un-
derlying architecture suggests one choice or the other. One advantage of the colon
notation is that with it a label can appear by itself on a line, with the opcode in col-
umn 1 of the next line. This style is convenient for compilers to generate. Without
the colon, there would be no way to tell a label on a line all by itself from an op-
code on a line all by itself. The colon eliminates this potential ambiguity.
It is an unfortunate characteristic of some assemblers that labels are restricted
to six or eight characters. In contrast, most high-level languages allow the use of
arbitrarily long names. Long, well-chosen names make programs much more read-
able and understandable by other people.
Each machine has some registers, so they need names. The x86 registers have
names like EAX , EBX , ECX , and so on.
The opcode field contains either a symbolic abbreviation for the opcode—if
the statement is a symbolic representation for a machine instruction—or a com-
mand to the assembler itself. The choice of an appropriate name is just a matter of
taste, and different assembly language designers often make different choices. The
designers of the MASM assembler decided to use MOV for both loading a register
from memory and storing a register into memory but they could have chosen MOVE
or LOAD and STORE.
Assembly progams often need to reserve space for variables. The MASM as-
sembly language designers chose DD (Define Double), since a word on the 8088
was 16 bits.
The operand field of an assembly language statement is used to specify the ad-
dresses and registers used as operands by the machine instruction. The operand
field of an integer addition instruction tells what is to be added to what. The oper-
and field of a branch instruction tells where to branch to. Operands can be regis-
ters, constants, memory locations, and so on.
The comments field provides a place for programmers to put helpful explana-
tions of how the program works for the benefit of other programmers who may
subsequently use or modify the program (or for the benefit of the original pro-
grammer a year later). An assembly language program without such docu-
mentation is nearly incomprehensible to all programmers, frequently including the
author as well. The comments field is solely for human consumption; it has no ef-
fect on the assembly process or on the generated program.
 
Search WWH ::




Custom Search