Starting from:
$35

$29

Problem 2 Solution

At  the beginning of class on the due date,  submit your neatly presented solution with this page stapled   to the front (10 points).

Given the following program (in pseudo-like language),  construct two  control flow graphs for the program. In the first, use maximal basic blocks; in the second, place each statement in its own basic block. In both cases, label the nodes in the graphs with the numbers of the program statements.

procedure sqrt(real x):real real x1,x2,x3,eps,errval;

begin
1.    x3 = 1
2.    errval = 0.0
3.    eps = .001
4.    if (x <= 0.0)
    5. output("illegal operand");
    6. return errval;
    7. else
8.    if (x < 1)
9.    x1 = x;
10.    x2 = 1;
    11. else
    12. x1 = eps;
13.    x2 = x;
14.    endif
15.    while ( (x2-x1) >= 2.0*eps ) 16.        x3 = (x1+x2)/2.0
17.    if ( (x3*x3-x)*(x1*x1-x) < 0)
18.    x2 = x3;
19.    else
20.    x1 = x3;
    21. endif;
    22. endwhile;
    23. return x3;
    24. endif;
    25. end.












1

More products