Question

In: Computer Science

Software Testing Question Program P2 CFG. a) Identify the basic blocks for the following program P2...

Software Testing Question

Program P2 CFG.

a) Identify the basic blocks for the following program P2 written in pseudo-code.

b) Draw the control flow graph.

Program P2

1) integer A, B;

2) input (A);

3) B = 1;

4) while (int i=1; i<=A; i++)

5) {

6) B = B * i;

7) if (B>13)

8) B = B / 2;

9) else 1

0) B = B * 2;

11) }

12) output (A,B);

13) end;

Solutions

Expert Solution

First we have to write the 3 Address Code for given pseudo code.

3 Address Code :

1. B = 1;

2. i = 1;

3. if ( i > A) go to 10.

4. t1 = B * 1;

5. if (t1 <= 13) go to 7.

6. t2 = t1/2;

7. t3 = t1*2;

8. t4 = i+1;

9. i = t4;

10. calling program

Basic Block :

A basic block is a sequence of three address statements where control enters at the beginning and leaves only at the end without any jumps or halts.

To find basic blocks we have to find leaders in the 3AC

How to find leaders

1) First instructions in the 3AC are leaders i.e, 1 and 2

2) Any instructions that is the target of the conditioal or unconditional jump. Statement 3 is conditional jump and it goes to 10. So statement 10 is leader. Similarly 7 is the leader.

3) Any instruction that immediately follows a conditional or unconditional jump. Statements 4, 6 are leaders.

4) The statements between one leader to next leader forms the basic block.


Related Solutions

on plc program(PLC software) (Ladder diagram)basic program on paper is ok if it is drwan on...
on plc program(PLC software) (Ladder diagram)basic program on paper is ok if it is drwan on paper i just need an example to understand and do by myself detail answer is much appreciated thank you Write a short (no more than 2 page) paper on your process and ladder diagram • choose a simple manufacturing process (i.e. conveyor belt, garage door, filling operation, etc.) • process must have the following inputs • A safety factor (such as 2 pushbuttons or...
SE 4367, Software Testing Homework #10, Control Flow Coverage For the following program P written in...
SE 4367, Software Testing Homework #10, Control Flow Coverage For the following program P written in pseudo-code, given the test set T: T = {t1 = <4, 2>, t2 = <90, 0>, t3 = <56, 1>} What is the statement coverage for T? What is the block coverage for T? What is the decision coverage for T? What is the condition coverage for T? What is the condition/decision coverage for T? Program P integer X, Y, Z; input (X, Y);...
Identify the appropriate specimen for lipid testing and describe the basic features of cholesterol and triglyceride...
Identify the appropriate specimen for lipid testing and describe the basic features of cholesterol and triglyceride assays.
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
Identify solutions of the following salts as acidic, basic or neutral. Identify solutions of the following...
Identify solutions of the following salts as acidic, basic or neutral. Identify solutions of the following salts as acidic, basic or neutral. a.) NaBr b.) Ca(C2H3O2)2 c.) NH4F d.) MgHPO4 e.)C2H5NH3Cl f.) KHSO4
Find all basic feasible solutions for the following LP and identify the adjacent basic feasible solutions...
Find all basic feasible solutions for the following LP and identify the adjacent basic feasible solutions of each basic feasible solution. max z= 3x1 +5x2 s.t. x1 <4 2x2 < 12 3x1 +2x2 < 18 x1>0, x2>0
*****Software Engineering Define the following : QUESTION 1 1.1) Contract Software 1.2) Internal Software Development 1.3)...
*****Software Engineering Define the following : QUESTION 1 1.1) Contract Software 1.2) Internal Software Development 1.3) Client 1.4) Object
Identify the directives and statements in the following program. What is the output of the program?...
Identify the directives and statements in the following program. What is the output of the program? [2 points] #include <stdio.h> int main (void) { printf(“Parkinson’s Law: \n Work expands so as to \t”); If i and j are positive integers, does (-i)/j always have the same value as –(i/j)? Justify your answer. [2 points] printf(“fill the time \n”); Supply parenthesis to show how a C compiler would interpret the following expressions: [2 points] a * b – c *d +...
Basic JAVA Question When we try to run this program, a problem occurs. What is this...
Basic JAVA Question When we try to run this program, a problem occurs. What is this problem called? And why does this problem occur here? public class Main {    public static void main(String[] args) {    PhoneNumber pn = new PhoneNumber();        System.out.println(pn.isTollFree());    } } class PhoneNumber { String number;    public boolean isTollFree() { return number.charAt(1) == '8'; } }
Identify the basic assumption or broad accounting principle that was violated in each of the following...
Identify the basic assumption or broad accounting principle that was violated in each of the following situations. 1. Pastel Paint Company purchased land two years ago at a price of $250,000 Because the value of the land has appreciated to $400,000 the company has valued the land at$400,000 in it's most recent balance sheet.   2. Atwell Corp has not prepared financial statements for external users for over three years 3. The Klingon Company sells farm machinery Revenue from a large...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT