GATE / CS ARCHIVE

GATE CSE 1992 / QUESTION 1(vii)

Why macro expansion precedes final assembly

Compiler Design · Compiler Phases, Linking & Loading · Full GATE CSE 1992 paper

GATE 1992, Q1(vii) Other
Report issue

Compiler Phases, Linking & Loading

Question 1(vii), GATE 1992: Why expand macros in pass one rather than pass two?
Question 1(vii), GATE 1992: Why expand macros in pass one rather than pass two?
Tap to enlarge
Answer & solution

Answer: Expansion changes code size and the addresses needed for the symbol table (no official key was published)

A macro invocation can expand into several instructions, data definitions and labels. Pass one must account for their sizes to advance the location counter correctly and assign addresses to all later symbols. Deferring expansion until after that layout would invalidate those addresses or require another layout pass. Thus the standard macro assembler expands before or during its first layout pass. A separately implemented macro preprocessor can perform the same work before the nominal assembler passes; the essential requirement is expansion before final address assignment.

Original paper, page 1