Refer to the given -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:
- The first three-address instruction is a leader.
- Any instruction that is the target of a conditional or unconditional jump is a leader.
- 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
1001is a leader. - Rule 2 (Targets of jumps):
1003is a leader (target ofgoto 1003at 1009).1002is a leader (target ofgoto 1002at 1011).1013is a leader (target ofgoto 1013at 1017).
- Rule 3 (Instructions following jumps):
1010is a leader (immediately follows the jump at 1009).1012is a leader (immediately follows the jump at 1011).
Collecting all the leaders, we get the set:
Since each leader corresponds to the start of a unique basic block, we can partition the code into the following basic blocks:
- Block 1:
1001 - Block 2:
1002 - Block 3:
1003to1009 - Block 4:
1010to1011 - Block 5:
1012 - Block 6:
1013to1017
Thus, the number of basic blocks is 6.
Free practice · Your answers on this page are not saved.
