Skip to content
Official PYQ · 2025

GATE CS 2025 Set 1 Q42 — Intermediate Code Generation

Explain with AI

Refer to the given 33-address code sequence. This code sequence is split into basic blocks. The number of basic blocks is ________. (Answer in integer)

1001: i = 1
1002: j = 1
1003: t1 = 10*i
1004: t2 = t1+j
1005: t3 = 8*t2
1006: t4 = t3-88
1007: a[t4] = 0.0
1008: j = j+1
1009: if j <= 10 goto 1003
1010: i = i+1
1011: if i <= 10 goto 1002
1012: i = 1
1013: t5 = i-1
1014: t6 = 88*t5
1015: a[t6] = 1.0
1016: i = i+1
1017: if i <= 10 goto 1013

 

View worked solution

Answer: 6:6

To find the number of basic blocks, we first identify the leaders in the three-address code. A basic block starts with a leader and contains all instructions up to (but not including) the next leader.

The rules for identifying leaders are as follows:

  1. The first three-address instruction is a leader.
  2. Any instruction that is the target of a conditional or unconditional jump is a leader.
  3. Any instruction that immediately follows a conditional or unconditional jump is a leader.

Let's apply these rules to the given code:

  • Rule 1: Instruction 1001 is a leader.
  • Rule 2 (Targets of jumps):
    • 1003 is a leader (target of goto 1003 at 1009).
    • 1002 is a leader (target of goto 1002 at 1011).
    • 1013 is a leader (target of goto 1013 at 1017).
  • Rule 3 (Instructions following jumps):
    • 1010 is a leader (immediately follows the jump at 1009).
    • 1012 is a leader (immediately follows the jump at 1011).

Collecting all the leaders, we get the set:
Leaders={1001,1002,1003,1010,1012,1013}\text{Leaders} = \{1001, 1002, 1003, 1010, 1012, 1013\}

Since each leader corresponds to the start of a unique basic block, we can partition the code into the following 66 basic blocks:

  • Block 1: 1001
  • Block 2: 1002
  • Block 3: 1003 to 1009
  • Block 4: 1010 to 1011
  • Block 5: 1012
  • Block 6: 1013 to 1017

Thus, the number of basic blocks is 6.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Intermediate Code Generation questions