3.6 The Assembly Process

Having established the basic syntax and semantics of assembly language, we will now give an overview of the process of assembling a program. Most assemblers are considered to be two-pass assemblers: They make two complete passes through the text file that expresses the source program. Two passes are required because all symbol values must be known before final translation into a binary machine language program can begin.

As we have seen, the assembler is supposed to work through the programmer's symbolic source file and produce a binary object file and perhaps a listing file. This task requires that the assembler program be able to perform three functions:

  1. Build a list of addresses and values for the symbols found in declarations and instructions.

  2. Translate the symbolic operation names into binary opcodes.

  3. Convert the symbolic operand specifiers into their proper binary forms.

Both passes through the source file are intimately connected with the symbol table that contains every programmer-defined symbol. An assembler also uses internal tables of permanently known symbols, such as the names for registers, the assembler directives, and the mnemonics for opcodes.

On the first pass, every new symbol name is entered into the symbol table. The assembler enters values for symbols into the table as it determines them while passing through the source file. The assembler also checks for the possibility that a symbolic address may have been multiply defined. By the end of the first pass, every symbol should either have a value or be known to be an external symbol. Some assemblers report a list of undefined symbols at the end of the first pass, while others assume that the lack of definition indicates the symbol is external, and not the result of a typographical error.

External symbols are resolved during the linking process, described later. In order to enforce syntax and semantics, an assembler classifies the programmer's symbols by type. At the very least, this means noting whether they were defined using an equal sign (symbolic value) or a colon (symbolic address label).

At the end of the first pass for SQUARES, the internal symbol table prepared by the assembler would contain the labels sq1, sq2, sq3, main, first, and done. Their values are the location counter values that you can see in the listing file (Figure 3-2). The values of the symbols first and done are location counter offsets from the origin of the .text code section, while sq1, sq2, and sq3 have values relative to the origin of the .data section.

Object and listing files are produced on the second pass. Expressions are evaluated using values from the symbol table, and the resulting data values or instructions are formatted into binary and associated with storage addresses. Diagnostic error messages are written into the listing file and to the programmer's screen. Severe errors may abort generation of an object file. Our advice for dealing with errors: Always give prime consideration to the first few error messages, as fixing the problem that gave rise to those may clear up subsequent messages.

Expressions containing certain combinations of symbols, including external references, cannot be fully resolved by an assembler. In such instances, information about the expression is forwarded to the linker by way of the object file.

The gcc command uses the -W option to convey requests to other software components of the GNU programming environment. If we want the assembler component to make a listing file, we may use a command line of the form

 L> gcc -Wa,-a=prog.lis ... 

where no spaces can occur within the entire -W construct. A gcc listing file for SQUARES has been shown (Figure 3-2). Intel's assembler and some HP-UX assemblers may not produce a listing file.



ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net