GATE / CS ARCHIVE

GATE CSE 1991 / QUESTION 1(xi)

Registers with minimum operand-memory traffic

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

GATE 1991, Q1(xi) 2 marks · Other
Not in GATE 2027 syllabusReport issue

Code Generation & Register Allocation

Question 1(xi), GATE 1991: Evaluate (a+b)*c−d/e**f on a two-address machine whose operands may be registers or memory. Minimize operand memory accesses and give the required registers. ** denotes exponentiation.
Question 1(xi), GATE 1991: Evaluate (a+b)*c−d/e**f on a two-address machine whose operands may be registers or memory. Minimize operand memory accesses and give the required registers. ** denotes exponentiation.
Question 1(xi), GATE 1991: Evaluate (a+b)*c−d/e**f on a two-address machine whose operands may be registers or memory. Minimize operand memory accesses and give the required registers. ** denotes exponentiation.
Tap to enlarge
Answer & solution

Answer: 2 registers and 6 input reads, excluding final result storage (no official key was published)

Assume six independent input values initially reside in memory, arithmetic allows a memory source and register destination, and exponentiation is an available operation. Read e into R1 and compute R1:=R1**f; read d into R2 and compute R2:=R2/R1. Reuse R1 for a, then add b and multiply by c; finish R1:=R1−R2. Each of a, b, c, d, e, f is read once, achieving the six-read lower bound. Two registers retain one partial result while forming the other; one register would require a spill or destructive memory temporary and extra traffic. A required final output store adds one access; instruction fetches are not operand accesses.

Original paper, page 1