tano6502 wrote:
How can assemblers do this in two passes?
I don't know of assemblers that do that (but looking at the other comments it seems some do), but TeX (the typesetting program) does it like that:
It layouts a dokument, calculates the page numbers etc, inserts them, layouts again, recalculates, layouts again, recalculate, layout, ... and so on until the layout (or the calculated data) does not change anymore.
IIRC sometimes it would even go into a loop, where one change would say increase the page number, after the next layout a change cause by that would happen that decreases the page number again and it would start anew. (I'm using page number only as example, TeX computes table of contents, reference tables, and a lot more, which may take much more place than a page number)
An assembler could actually do the same. Assemble, calculate the address labels, re-assemble with better optimization, re-calculate address labels (that could have changed again), re-assemble ... and so on until the output does not change anymore.
But that is not 2-pass.
André