GATE Computer ScienceModerateGATE CSE

How many basic blocks does this three-address code contain? 1: i = 0; 2: s = 0; 3: if i >= n goto 9; 4: t = a[i]; 5: if t < 0 goto 7; 6: s = s + t; 7: i = i + 1; 8: goto 3; 9: print s; 10: halt

  1. A. 5
  2. B. 6
  3. C. 7
  4. D. 8

Correct answer: B. 6

Leaders (instruction numbers): 1, 3, 4, 6, 7, 9 — first instruction, jump targets and instructions after jumps — so 6 blocks.

More Compiler Design questions

Exams that ask this topic