Skip to content
GATEiit

GATE CSE 2017 Session 1 Q62: Minimum registers for (a − 1) * (((b + c) / 3) + d) on a load/store machine

Syllabus topic: Outside the current syllabus

Question

Consider the expression (a−1)∗(((b+c)/3)+d). Let X be the minimum number of registers required by an optimal code generation (without any register spill) algorithm for a load/store architecture, in which (i) only load and store instructions can have memory operands and (ii) arithmetic instructions can have only register or immediate operands. The value of X is ______.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 2 (official GATE 2017 final answer key)

Concept used: Optimal code generation evaluates the subtree needing more registers first (Sethi–Ullman style) and reuses registers; on a load/store machine every variable must be loaded into a register before use.

First step: Evaluate the right subtree ((b+c)/3)+d first, reusing registers where possible, and track how many registers are live at once, then evaluate a−1 while one result is held.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key