GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 4.9

One-register evaluation and precedence

Compiler Design · Code Generation & Register Allocation · Full GATE CSE 1997 paper

GATE 1997, Q4.9 2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Code Generation & Register Allocation

Question 4.9, GATE 1997: For expression prefix (a*b)*c op…where op is+, *, or exponentiation, which operators permit the accumulated product to remain in one register?
Tap to enlarge
Your answer
Answer & solution

Answer: A: + or * under the standard left-to-right accumulator model (no official key was published)

After computing a*b, the single accumulator holds that intermediate value. If op is+or*, ordinary precedence and left associativity allow completing the multiplication by c before moving to the following operation; the accumulator can be reused without spilling a*b. If op is exponentiation, the c-power subexpression binds more tightly and normally must be computed before multiplying by the held a*b, creating a second live intermediate. Thus A in the stated compiler-evaluation model. The omitted suffix and machine instruction set are not fully specified; recomputation or different schedules can change storage requirements, so this is not an architecture-independent impossibility theorem.

Original paper, page 4