Search code examples
assemblycompiler-constructionmachine-code

Conversion from assembly program to low-level machine language


While studying COMPILER-DESIGN through an online book from Google-Books,referenced as Compiler Design By A.A.Puntambekar, I got stuck across a line. Actually, I am more curious to know the inner-detail.

The assembler converts the assembly-program to low-level machine language using two passes. A pass means one complete scan of the input program. The end of the second pass is the relocatable machine code.

Why the 2 passes for conversion and what are the phases involved like lexical analysis,syntax analysis,etc while conversion from assembly to machine-code??? I have very less/no idea about it.

If someone over here would like to describe those two-passes or link out to some good resources, I'd be thankful to him/her


Solution

  • The compiler has to replace labels by their offsets. If you use the name of a label in a earlier line than the label itself, the compiler will have to repass the program for inserting the offset.