1,888 views

1 Answer

Best answer
3 votes
3 votes

Correct Answer: 8 nodes and 10 edges 

To draw the Control Flow Graph, we have to find the number of basic blocks for given code snippet.

A Basic Block is a sequence of instructions where control enters at the beginning of the statement and leave at the end without any halt (except the last statement of the block).

To find number of basic blocks, we have to find the identify of leaders in the code. The rules for finding leaders are as follows:

  1. First statement in the code is always a leader.
  2. Statement that is target of an conditional or unconditional goto statement like: if....goto L or goto L is always a leader.
  3. Statement which immediately follows a conditional or unconditional goto statement is always a leader

Now, that we have found the leader statements, the basic block consists statements starting from one leader and all statement up to another leader, and not including the next leader.

The leaders and basic blocks for given code snippet:

The CFG for given code snippet:

As we can see, CFG has 8 nodes and 10 edges.

selected by

Related questions

1 votes
1 votes
1 answer
3
Markzuck asked Jan 8, 2019
742 views
someone please share detailed rules for this along with solution- would be of great help.and we usually dont take start and end state- arent they extra here? coz count co...