743 views
1 votes
1 votes

Consider the following code

 

1.  location = -1

2.  i=0

3.  if (i<100) goto 5

4.  goto 13

5.  t1 = 4*i

6.  go to 3

7.  t2 = A[t1]

8.  if t2 = x goto 10

9.  goto 11

10.location = i

11.t3 = i+1

12.i = t3

13.goto 3

 

The number of basic blocks from the given code are______

2 Answers

Best answer
2 votes
2 votes

Basic block: The collection of 3AC statements from leader to next leader without including the next leader is known as the basic block. 

Steps to find the basic blocks:

  • Identify the leader first. (The first statement of 3AC is the leader.)
  • Address of conditional, unconditional goto is the leader. (target location of goto)
  • immediate next line of goto is the leader.

Now construct the basic block from leader to line before the next leader.

In the given 3AC $9$ leaders are there: $1,3,4,5,7,9,10,11,13$

There are $9$ basic block are there:

  1. Block $B_1$: statement $1-2$
  2. Block $B_2$: statement $3$
  3. Block $B_3$: statement $4$
  4. Block $B_4$: statement $5-6$
  5. Block $B_5$: statement $7-8$
  6. Block $B_6$: statement $9$
  7. Block $B_7$: statement $10$
  8. Block $B_8$: statement $11-12$
  9. Block $B_9$: statement $13$

Ref: Basic Block

selected by
4 votes
4 votes

A number of basic blocks = Number of leaders. Because every basic block will contain 1 leader.

Now, how to find a leader?

  1. The first statement is a leader.
  2. The target of a goto is a leader.
  3. The next statement after goto is a leader.

So here in this question the number of leaders in the given control flow graph =9, which are 1,3,4,5,7,9,10,11,13.

The number of basic blocks from the given code is =9.

Related questions

0 votes
0 votes
2 answers
1
bts1jimin asked Jan 12, 2019
572 views
Answer is 6,6Can anybody explain how?
0 votes
0 votes
1 answer
2
stblue asked Aug 26, 2017
869 views
a) (i) and (ii) onlyb) (ii) and (iii) onlyc) (i) and (iv) onlyd) All are correct
1 votes
1 votes
1 answer
3
thor asked Nov 17, 2016
662 views
0 votes
0 votes
1 answer
4
thor asked Nov 17, 2016
1,089 views