The least number of temporary variables required to create a three-add...
t1= q*r
t2= p+t1
t3= q*r
t4= s/t3
t5= t2-t4
Hence, minimum 5 variables are required.
View all questions of this test
The least number of temporary variables required to create a three-add...
Expression: p q*r-s/(q*r)
Three-address code: Three-address code is a type of intermediate code representation that breaks down an expression into a sequence of instructions, each containing at most three operands. In static single assignment (SSA) form, each variable is assigned only once.
To create a three-address code in SSA form for the given expression, we need to break it down into smaller sub-expressions and assign temporary variables to hold the intermediate results.
Sub-expressions:
1. q * r
2. s / (q * r)
3. p - (s / (q * r))
Temporary variables:
To create the three-address code, we will need temporary variables to hold the intermediate results of the sub-expressions. Let's assign temporary variables t1, t2, t3, t4, and t5.
Step-by-step breakdown:
1. Evaluate the sub-expression q * r and assign it to temporary variable t1.
- Three-address code: t1 = q * r
2. Evaluate the sub-expression s / (q * r) and assign it to temporary variable t2.
- Three-address code: t2 = s / t1
3. Evaluate the sub-expression p - (s / (q * r)) and assign it to temporary variable t3.
- Three-address code: t3 = p - t2
4. Evaluate the sub-expression q * r and assign it to temporary variable t4.
- Three-address code: t4 = q * r
5. Evaluate the sub-expression t3 / t4 and assign it to temporary variable t5.
- Three-address code: t5 = t3 / t4
Final three-address code:
1. t1 = q * r
2. t2 = s / t1
3. t3 = p - t2
4. t4 = q * r
5. t5 = t3 / t4
Number of temporary variables:
We have used 5 temporary variables (t1, t2, t3, t4, t5) to create the three-address code in SSA form for the given expression.
The least number of temporary variables required to create a three-add...
T1 and t3 both represent the same expression , so why we need two variable for this ? Can you please explain ?
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).