1,513 views
1 1 vote

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 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
3 3 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.

Position:
Show:

Related questions

0 0 votes
2 2 answers
1.1k
1.1k views
bts1jimin asked Jan 12, 2019
1,081 views
Answer is 6,6Can anybody explain how?Q. 49Consider the basic block given below:\[\begin{array}{l}b=b+c \\d=b+d \\b=b-d \\e=d+b\end{array}\]The minimum number of nodes and...
0 0 votes
1 1 answer
1.8k
1.8k views
stblue asked Aug 26, 2017
1,768 views
a) (i) and (ii) onlyb) (ii) and (iii) onlyc) (i) and (iv) onlyd) All are correctConsider the following statements:(i). The symbol table contains information about the lex...
1 1 vote
1 answers 1 answer
955
955 views
thor asked Nov 17, 2016
955 views
One of the purpose of using intermediate code in compilers is tomake parsing and semantic analysis simplerimprove error recovery and error reportingincrease the chances o...
0 0 votes
1 1 answer
1.5k
1.5k views
thor asked Nov 17, 2016
1,472 views
Which of the following is not a Three Address Code(TAC)return 0if $\mathrm{a}>\mathrm{b}$ goto c$a[i]=b$;none