Ask a Question

what is the advantage of 2 pass assembler over 1 pass assembler?


Administrator

on 2010-04-18 09:30:00  

The main reason why most assemblers use a 2-pass system is to address the problem of forward references -- references to variables or subroutines that have not yet been encountered when parsing the source code. A strict 1-pass scanner cannot assemble source code which contains forward references. Pass 1 of the assembler scans the source, determining the size and address of all data and instructions; then pass 2 scans the source again, outputting the binary object code. Some assemblers have been written to use a 1.5 (one and a half) pass scheme, whereby the source is only scanned once, but any forward references are simply assumed to be of the largest size necessary to hold any native machine data type (for instance, assuming a reference to the address of an as-yet unencountered subroutine could be very far away, necessitating the use of a far branch). The unknown quantity is temporarily filled in as zero during pass 1 of the assembler, and the forward reference is added to a \'fix-up list\'. After pass 1, the \'.5\' pass goes through the fix-up list and patches the output machine code with the values of all resolved forward references. This can result in sub-optimal opcode construction, but allows for a very fast assembly phase.