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.html
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.app
During the first pass, the assembler:ide
Checks the syntax of the instruction or directive. It faults if there is an error in the syntax, for example if a label is specified on a directive that does not accept one.ui
Determines the size of the instruction and data being assembled and reserves space.spa
Determines offset of labels within sections.debug
Creates a symbol table containing label definitions and their memory addresses.code
During the second pass, the assembler:orm
Faults if an undefined reference is specified in an instruction operand or directive.htm
Encodes the instructions using the label offsets from pass 1, where applicable.ci
Generates relocations.
Generates debug information if requested.
Outputs the object file.
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.
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.
Assembling the code in Example 2 generates the error:
A1909E: Line not seen in second pass; cannot be assembled.
Assembler Reference: