3,693 views

1 Answer

Best answer
3 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
Position:
Show:

Related questions

1 1 vote
0 0 answers
367
367 views
harsh_20 asked Jan 16, 2025
367 views
The following program uses six temporary variables p, q, r, s, tand u. The code is:p=6q=7t=p*qs=t +pu=8u=s* ps =p +ur=r*qt =t +preturn tAssuming that all operations take ...
4 4 votes
2 answers 2 answers
3.6k
3.6k views
Sambhrant Maurya asked Oct 31, 2018
3,641 views
The minimum number of temporary variables created in 3 address code of the following expression are _____ a+b*c+d-e-a+b*cAssume order of precedence from...
1 1 vote
1 1 answer
954
954 views
Ankita87077 asked Oct 27, 2021
954 views
In such questions, In which it is asked " minimum number of registers required for executing this three address code without spilling", can we apply code motion optimizat...
1 1 vote
1 1 answer
1.1k
1.1k views
Markzuck asked Jan 8, 2019
1,105 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...