|
1. Generate 3AC code for the following code segments:
|
a)
if(x+y*z>x*y+z)
a+0;
|
b)
fact(x)
f int f=1;
for (i=2, i >=x, i++)
f
f=f*i;
return f;
|
2. Implement the statement
a=b*-c+b*-c
into following Intermediate code representation.
a. Quadruple
b. Indirect Triples
3. For the given boolean expression
(a + b ∗ c) + d + (a + b ∗ c) − d + e
draw the DAG
4. Construct the DAG for the following Block:
L0:T0=b+c
L1:T1=t0*d
L2:a=T1
L3: T2=f*a
L4 :e=T2
L5:T3 =b+c
L6 :T4=T3*e
L7:F=T4
L8:T5=b+c
L9:T6=T5/d
L10:g=T6
5. Divide the following code segment into basic blocks, draw a control flow graph.
(
1)P := 0
(2) I := 1
(3) P := P + I
(4) IF P <= 60 GOTO (7)
(5) P := 0
(6) I := 5
(7) T1 := I * 2
(8) I := T1 + 1
(9) IF I <= 20 GOTO (3)
(10) K := P * 3
6. Show all the steps required to parse the input string
(( a,a ),a,a )
7. Consider the fragment of source code. Identify leader, basic block and draw a control flow graph.
sum=0;
for(i=0;i<=10;i++)
sum=sum+a[t1];
8. Write the steps in code generation algorithm and generate target code for the following source language statements.
a) x=a+b+c*d
b) a= (a + b) + (a * b) * (a - b)
9. Optimize and develop this code by eliminating common sub expression, performing reduction in strength.
(1) prod:=0
(2) i:=1
(3) t1:=4*i
(4) t2:a[t1]
(5) t3=4*i
(6) t4=b[t3]
(7) t5:=t2*t4
(8)t6:=prod+t5
(9)prod:=t6
(10) t7=i+1
(11)i:=t7
(12)if i<=20 goto (3)
10. Explain in detail about the following:
a) Elements in Activation Record
b) Static Allocation vs Dynamic Allocation vs Heap Allocation
|