Information Technology Reference
In-Depth Information
3.4.1. Assemblers
Assemblers are programs that generate machine code instructions from a source
code program written in assembly language. The assembler will replace symbolic
addresses by numeric addresses, replace symbolic operation codes by machine oper-
ation codes, reserve storage for instructions and data, and translate constants into
machine representation.
The functions of the assembler can be performed by scanning the assembly pro-
gram and mapping its instructions to their machine code equivalent. Since symbols
can be used in instructions before they are defined in later ones, a single scanning of
the program might not be enough to perform the mapping. A simple assembler scans
the entire assembly program twice, where each scan is called a pass. During the first
pass, it generates a table that includes all symbols and their binary values. This table
is called the symbol table. During the second pass, the assembler will use the symbol
table and other tables to generate the object program, and output some information
that will be needed by the linker.
3.4.2. Data Structures
The assembler uses at least three tables to perform its functions: symbol table,
opcode table, and pseudo instruction table. The symbol table, which is generated
in pass one, has an entry for every symbol in the program. Associated with each
symbol are its binary value and other information. Table 3.5 shows the symbol
table for the multiplication program segment of Example 2. We assume that the
instruction LD X is starting at location 0 in the memory. Since each instruction
takes two bytes, the value of the symbol LOOP is 4 (004 in hexadecimal).
Symbol N, for example, will be stored at decimal location 40 (028 in hexadecimal).
The values of the other symbols can be obtained in a similar way.
The opcode table provides information about the operation codes. Associated
with each symbolic opcode in the table are its numerical value and other information
about its type, its instruction length, and its operands. Table 3.6 shows the opcode
TABLE 3.5 Symbol Table for the Multiplication
Segment (Example 2)
Value
(hexadecimal)
Other
information
Symbol
Loop
004
EXIT
01E
X
020
Y
022
Z
024
ONE
026
N
028
Search WWH ::




Custom Search