Question:

Show Hint

To count basic blocks, look for the jumps or conditional statements ("if" or "goto") that affect the flow. Each section of the code between these jumps forms a basic block.
Updated On: Jan 30, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 6

Solution and Explanation

We need to identify the basic blocks in the given code. A basic block is a sequence of consecutive instructions where the control flow enters at the beginning and exits at the end without any intermediate branches or jumps, except possibly at the end. Step 1: Identifying Basic Blocks
The given code contains the following branches and jumps, which help in determining the basic blocks:
1. Block 1: Instructions 1001 to 1002 (initializations of \( i \) and \( j \)).
2. Block 2: Instructions 1003 to 1007 (computation of \( t1 \), \( t2 \), \( t3 \), \( t4 \), and assignment to \( a[t4] \)).
3. Block 3: Instructions 1008 to 1009 (update \( j \) and the conditional jump "if \( j \leq 10 \) goto 1003").
4. Block 4: Instructions 1010 to 1011 (update \( i \) and the conditional jump "if \( i \leq 10 \) goto 1002").
5. Block 5: Instructions 1012 to 1017 (resetting \( i \), computing \( t5 \), \( t6 \), assigning to \( a[t6] \), and the conditional jump "if \( i \leq 10 \) goto 1013").
6. Block 6: Instructions 1013 to 1017 (additional operations and a conditional jump based on \( i \)). Step 2: Counting the Basic Blocks
After analyzing the control flow, we find that the code is divided into 6 basic blocks. Thus, the number of basic blocks is 6.
Was this answer helpful?
0
0

Top Questions on Memory hierarchy

View More Questions