Hardware Reference
In-Depth Information
the comments, has to be saved. If no listing is needed, then the intermediate form
can be reduced to the bare essentials.
Either way, another task of pass one is to save all macro definitions and expand
the calls as they are encountered. Thus defining the symbols and expanding the
macros are generally combined into one pass.
7.3.2 Pass One
The principal function of pass one is to build up a table called the symbol ta-
ble , containing the values of all symbols. A symbol is either a label or a value that
is assigned a symbolic name by means of a pseudoinstruction such as
BUFSIZE EQU 8192
In assigning a value to a symbol in the label field of an instruction, the assem-
bler must know what address that instruction will have during execution of the pro-
gram. To keep track of the execution-time address of the instruction being assem-
bled, the assembler maintains a variable during assembly, known as the ILC
( Instruction Location Counter ). This variable is set to 0 at the beginning of pass
one and incremented by the instruction length for each instruction processed, as
shown in Fig. 7-6. This example is for the x86.
Label
Opcode
Operands
Comments
Length
ILC
MARIA:
MOV
EAX, I
EAX = I
5
100
MOV
EBX, J
EBX = J
6
105
ROBERTA:
MOV
ECX, K
ECX = K
6
111
IMUL
EAX, EAX
EAX = I * I
2
117
IMUL
EBX, EBX
EBX = J * J
3
119
IMUL
ECX, ECX
ECX = K * K
3
122
MARILYN:
ADD
EAX, EBX
EAX = I * I+J * J
2
125
ADD
EAX, ECX
EAX = I * I+J * J+K * K
2
127
STEPHANY:
JMP
DONE
branch to DONE
5
129
Figure 7-6. The instruction location counter (ILC) keeps track of the address
where the instructions will be loaded in memory. In this example, the statements
prior to MARIA occupy 100 bytes.
Pass one of most assemblers uses at least three internal tables: the symbol ta-
ble, the pseudoinstruction table, and the opcode table. If needed, a literal table is
also kept. The symbol table has one entry for each symbol, as illustrated in
Fig. 7-7. Symbols are defined either by using them as labels or by explicit defini-
tion (e.g., EQU ). Each symbol table entry contains the symbol itself (or a pointer to
it), its numerical value, and sometimes other information. This additional infor-
mation may include
 
 
Search WWH ::




Custom Search