Refer to the given 3-address code sequence. This code sequence is split into…

2025

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

\(\begin{aligned} &1001: \quad i = 1 \\ &1002: \quad j = 1 \\ &1003: \quad t1 = 10 \cdot i \\ &1004: \quad t2 = t1 + j \\ &1005: \quad t3 = 8 \cdot t2 \\ &1006: \quad t4 = t3 - 88 \\ &1007: \quad a[t4] = 0.0 \\ &1008: \quad j = j + 1 \\ &1009: \quad \text{if } j \leq 10 \text{ goto } 1003 \\ &1010: \quad i = i + 1 \\ &1011: \quad \text{if } i \leq 10 \text{ goto } 1002 \\ &1012: \quad i = 1 \\ &1013: \quad t5 = i - 1 \\ &1014: \quad t6 = 88 \cdot t5 \\ &1015: \quad a[t6] = 1.0 \\ &1016: \quad i = i + 1 \\ &1017: \quad \text{if } i \leq 10 \text{ goto } 1013 \end{aligned} \)

Attempted by 62 students.

Show answer & explanation

Correct answer: 6

Answer: 6

Explanation:

  • Step 1: Find leaders. A leader is the first instruction, any target of a jump, and any instruction that immediately follows a conditional or unconditional jump.

  • Apply to the code: leaders are 1001 (first instruction), 1003 (target of the jump at 1009), 1002 (target of the jump at 1011), 1010 (instruction after the conditional at 1009), 1012 (instruction after the conditional at 1011), and 1013 (target of the jump at 1017).

  • Step 2: Form basic blocks by grouping each leader with following instructions up to (but not including) the next leader.

  • The basic blocks are:

    • Block 1: instruction 1001

    • Block 2: instruction 1002

    • Block 3: instructions 1003–1009

    • Block 4: instructions 1010–1011

    • Block 5: instruction 1012

    • Block 6: instructions 1013–1017

  • Step 3: Count the blocks. There are 6 basic blocks in total.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir