How the assembler works

The ARM assembler is a 2 pass assembler that outputs object code from the assembly language source code. This means that it reads the source code twice. Each read of the source code is called a pass.

This is because assembly language source code often contains forward references. A forward reference occurs when a label is used as an operand, for example as a branch target, earlier in the code than the definition of the label.The assembler cannot know the address of the forward reference label until it reads the definition of the label. During each pass, the assembler performs different functions.

During the first pass, the assembler:

During the second pass, the assembler:

Memory addresses of labels are determined and finalized in the first pass. Therefore, the assembly code must not change during the second pass. All instructions must be seen in both passes. Therefore you must not define a symbol after a :DEF: test for the symbol. The assembler faults if it sees code in pass 2 that was not seen in pass 1. Example 1 shows that num EQU 42 is not seen in pass 1 but is seen in pass 2.

Example 1. Line not seen in pass 1

    AREA x,CODE 
    [ :DEF: foo 
num EQU 42 
foo DCD num 

Assembling the code in Example 1 generates the error:

A1903E: Line not seen in first pass; cannot be assembled.

Example 2 shows that MOV r1,r2 is seen in pass 1 but not in pass 2.

Example 2. Line not seen in pass 2

    AREA x,CODE 
    [ :LNOT: :DEF: foo 
    MOV r1, r2 
foo MOV r3, r4

Assembling the code in Example 2 generates the error:

A1909E: Line not seen in second pass; cannot be assembled.

Show/hideSee also

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0473H