GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Using the standard backpatching scheme (each relational test yields 'if a<b goto _' followed by 'goto _', with no fall-through optimisation and instruction numbers starting at 100), how many three-address instructions are generated for: while (a < b && c < d || e < f) { if (x < y) p = 1; else q = 2; }? The loop's exit is the next instruction after the final goto.

  1. A. 11
  2. B. 13
  3. C. 9
  4. D. 12

Correct answer: D. 12

Three relops give 6 jumps; the if-else gives 2 (test) + 1 + 1 (skip goto) + 1 = 5; the loop adds a closing 'goto 100'; total 12.

More Compiler Design questions

Exams that ask this topic