GateAI
Intermediate Code Generation

GATE CSE 2024 Set 1 · Q39

MCQ2 marksMedium

Time

Consider the following pseudo-code.L1: t1 = -1 L2: t2 = 0 L3: t3 = 0 L4: t4 = 4 * t3 L5: t5 = 4 * t2 L6: t6 = t5 * M L7: t7 = t4 + t6 L8: t8 = a[t7] L9: if t8 <= max goto L11 L10: t1 = t8 L11: t3 = t3 + 1 L12: if t3 < M goto L4 L13: t2 = t2 + 1 L14: if t2 < N goto L3 L15: max = t1Which one of the following options CORRECTLY specifies the number of basic blocks and the number of instructions in the largest basic block, respectively ?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) 7 and 6

Intermediate Code Generation

To determine the basic blocks, we first identify the leaders using the standard basic block rules:

  1. First instruction is a leader:

    • L1

  2. Target instructions of any conditional or unconditional jump/goto are leaders:

    • Target of L9 (goto L11)→\rightarrowL11

    • Target of L12 (goto L4)→\rightarrowL4

    • Target of L14 (goto L3)→\rightarrowL3

  3. Instructions immediately following any conditional or unconditional jump/goto are leaders:

    • Instruction following L9→\rightarrowL10

    • Instruction following L12→\rightarrowL13

    • Instruction following L14→\rightarrowL15

Thus, the set of leaders is {L1,L3,L4,L10,L11,L13,L15}\{L1, L3, L4, L10, L11, L13, L15\}.

Now, partitioning the sequence of three-address instructions from each leader up to (but not including) the next leader, we get the following 7 basic blocks:

  • Block 1:L1, L2 (2 instructions)

  • Block 2:L3 (1 instruction)

  • Block 3:L4, L5, L6, L7, L8, L9 (6 instructions)

  • Block 4:L10 (1 instruction)

  • Block 5:L11, L12 (2 instructions)

  • Block 6:L13, L14 (2 instructions)

  • Block 7:L15 (1 instruction)

  • Total number of basic blocks: 77

  • Largest basic block: Block 3 (L4 to L9) with 66 instructions.

Hence, the correct option is (D).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Intermediate Code Generation previous year question is Q39 of the GATE CSE 2024 Set 1 paper. Find more GATE CSE PYQs on Intermediate Code Generation in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Intermediate Code Generation PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Intermediate Code Generation in GATE CSE

Intermediate Code Generation has 14 GATE CSE PYQs across 12 papers from 2011 to 2025. 4 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2024 Set 1.

How GATE tests Intermediate Code Generation

More from GATE CSE 2024 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2024 Set 1 · Q39 · MCQ

Consider the following pseudo-code. L1: t1 = -1 L2: t2 = 0 L3: t3 = 0 L4: t4 = 4 * t3 L5: t5 = 4 * t2 L6: t6 = t5 * M L7: t7 = t4 + t6 L8: t8 = a[t7] L9: if t8 Which one of the following options CORRECTLY specifies the number of basic blocks and the number of instructions in the largest basic block, respectively ?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.