You are on page 1of 2

Understanding Assembler Passes

20/01/15 8:57 pm

[ Bottom of Page | Previous Page | Next Page | Index | ]

Assembler Language Reference


Understanding Assembler Passes
When you enter the as command, the assembler makes two passes over the source program.

First Pass
On the first pass, the assembler performs the following tasks:
Checks to see if the instructions are legal in the current assembly mode.
Allocates space for instructions and storage areas you request.
Fills in the values of constants, where possible.
Builds a symbol table, also called a cross-reference table, and makes an entry in this table for every
symbol it encounters in the label field of a statement.
The assembler reads one line of the source file at a time. If this source statement has a valid symbol in
the label field, the assembler ensures that the symbol has not already been used as a label. If this is the
first time the symbol has been used as a label, the assembler adds the label to the symbol table and
assigns the value of the current location counter to the symbol. If the symbol has already been used as
a label, the assembler returns the error message Redefinition of symbol and reassigns the symbol
value.
Next, the assembler examines the instruction's mnemonic. If the mnemonic is for a machine instruction
that is legal for the current assembly mode, the assembler determines the format of the instruction (for
example, XO format). The assembler then allocates the number of bytes necessary to hold the machine
code for the instruction. The contents of the location counter are incremented by this number of bytes.
When the assembler encounters a comment (preceded by a # (pound sign)) or an end-of-line character,
the assembler starts scanning the next instruction statement. The assembler keeps scanning statements
and building its symbol table until there are no more statements to read.
At the end of the first pass, all the necessary space has been allocated and each symbol defined in the
program has been associated with a location counter value in the symbol table. When there are no more
source statements to read, the second pass starts at the beginning of the program.
Note: If an error is found in the first pass, the assembly process terminates and does not continue to
the second pass. If this occurs, the assembler listing only contains errors and warnings generated
during the first pass of the assembler.

Second Pass
On the second pass, the assembler:
Examines the operands for symbolic references to storage locations and resolves these symbolic
references using information in the symbol table.
Ensures that no instructions contain an invalid instruction form.
Translates source statements into machine code and constants, thus filling the allocated space with
object code.
Produces a file containing error messages, if any have occurred.
At the beginning of the second pass, the assembler scans each source statement a second time. As the
assembler translates each instruction, it increments the value contained in the location counter.

http://www-01.ibm.com/support/knowledgecenter/api/content/nl/e_aix_53/com.ibm.aix.aixassem/doc/alangref/assembler_passes.htm

Page 1 of 2

Understanding Assembler Passes

20/01/15 8:57 pm

If a particular symbol appears in the source code, but is not found in the symbol table, then the symbol
was never defined. That is, the assembler did not encounter the symbol in the label field of any of the
statements scanned during the first pass, or the symbol was never the subject of a .comm, .csect,
.lcomm, .sect, or .set pseudo-op.
This could be either a deliberate external reference or a programmer error, such as misspelling a symbol
name. The assembler indicates an error. All external references must appear in a .extern or .globl
statement.
The assembler logs errors such as incorrect data alignment. However, many alignment problems are
indicated by statements that do not halt assembly. The -w flag must be used to display these warning
messages.
After the programmer corrects assembly errors, the program is ready to be linked.
Note:
If only warnings are generated in the first pass, the assembly process continues to the second pass.
The assembler listing contains errors and warnings generated during the second pass of the
assembler. Any warnings generated in the first pass do not appear in the assembler listing.

Related Information
Assembling and Linking a Program.
Interpreting an Assembler Listing.
Interpreting a Symbol Cross-Reference.
Subroutine Linkage Convention.
Understanding and Programming the TOC.
Running a Program.
The as command.
[ Top of Page | Previous Page | Next Page | Index | ]

http://www-01.ibm.com/support/knowledgecenter/api/content/nl/e_aix_53/com.ibm.aix.aixassem/doc/alangref/assembler_passes.htm

Page 2 of 2

You might also like