Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given this Intermediate File of aCompiler: ( 1 ) : = #1 Indx ( 2 ) JGT Indx #25

ID: 3869000 • Letter: G

Question

Given this Intermediate File of aCompiler:

( 1 )

: =

#1

Indx

( 2 )

JGT

Indx

#25

(20)

( 3 )

-

Indx

#1

t1

( 4 )

*

t1

#10

t2

( 5 )

*

#2

MLK

t3

( 6 )

-

t3

#1

t4

( 7 )

-

t4

#1

t5

( 8 )

+

t2

t5

t6

( 9 )

*

t6

#4

t7

( 10 )

-

Indx

#1

t8

( 11 )

*

t8

#10

t9

( 12 )

*

#2

MLK

t10

( 13 )

-

t10

#1

t11

( 14 )

+

t9

t11

t12

( 15 )

*

t12

#4

t13

( 16 )

: =

ZYX[t13]

CBA[t7]

( 17 )

+

#1

Indx

t14

( 18 )

: =

t14

Indx

( 19 )

JMP

( 2 )

( 20 )

Optimize the code.

Mark which statements would be moved,modified, or removed. Machine independent code optimization uses manytechniques. List the optimization methods you used.

( 1 )

: =

#1

Indx

( 2 )

JGT

Indx

#25

(20)

( 3 )

-

Indx

#1

t1

( 4 )

*

t1

#10

t2

( 5 )

*

#2

MLK

t3

( 6 )

-

t3

#1

t4

( 7 )

-

t4

#1

t5

( 8 )

+

t2

t5

t6

( 9 )

*

t6

#4

t7

( 10 )

-

Indx

#1

t8

( 11 )

*

t8

#10

t9

( 12 )

*

#2

MLK

t10

( 13 )

-

t10

#1

t11

( 14 )

+

t9

t11

t12

( 15 )

*

t12

#4

t13

( 16 )

: =

ZYX[t13]

CBA[t7]

( 17 )

+

#1

Indx

t14

( 18 )

: =

t14

Indx

( 19 )

JMP

( 2 )

( 20 )

Explanation / Answer

( 1 ) : = #1 Indx

( 2 ) JGT Indx #25 (20)

( 3 ) - Indx #1 t1

( 4 ) * t1 #10 t2

( 5 ) * #2 KLM t3

(6 ) - t3 #1 t4

( 7 ) - t4 #1 t5

( 8 ) + t2 t5 t6

( 9 ) * t6 #4 t7

( 10 ) - Indx #1 t8

( 11 ) * t8 #10 t9

( 12 ) * #2 KLM t10

( 13 ) - t10 #1 t11

( 14 ) + t9 t11 t12

( 15 ) * t12 #4 t13

( 16 ) : = XYZ[t13] ABC[t7]

( 17 ) + #1 Indx t14

( 18 ) : = t14 Indx

( 19 ) JMP ( 2 )

( 20 )

Given this Intermediate File of a Compiler:

( 1 )

: =

#1

Indx

Indx = 1

( 2 )

JGT

Indx

#25

(20)

If indx GT 25 goto 20

( 3 )

-

Indx

#1

t1

t1 = indx-1

( 4 )

*

t1

#10

t2

t2 = t1*10

( 5 )

*

#2

MLK

t3

t3=2*MLK// change to t3=MLK+MLK(Strength reduction)

( 6 )

-

t3

#1

t4

t4=t3-1// copy propagation remove statement

( 7 )

-

t4

#1

t5

t5=t4-1//change statement as t5=t3-2

( 8 )

+

t2

t5

t6

t6= t2 + t5

( 9 )

*

t6

#4

t7

    t7= t6 + 4

( 10 )

-

Indx

#1

t8

t8=indx-1      // common sub expression t1 = indx-1 (3) remove t8=indx-1

( 11 )

*

t8

#10

t9

t9= t8 *10// common sub expression t1 = indx-1 (3) remove t8=indx-1

( 12 )

*

#2

MLK

t10

t10=2*MLK// change to t10=MLK+MLK(Strength reduction) and common code sub expression (5)t3=2*MLK

( 13 )

-

t10

#1

t11

t11= t10-1// common code sub expression t4=t3-1(6)

( 14 )

+

t9

t11

t12

t12= t9 + t11//

( 15 )

*

t12

#4

t13

t13= t12 + 4

( 16 )

: =

ZYX[t13]

CBA[t7]

CBA[t7]= ZYX[t13]//change code as CBA[t7]= ZYX[t7]

( 17 )

+

#1

Indx

t14

t14= Indx+1//remove the code

( 18 )

: =

t14

Indx

Indx=t14//replace Indx=Indx+1 copy propagation

( 19 )

JMP

( 2 )

Goto(2)

( 20 )

We can write by above code

( 1 )

Indx = 1

Indx = 1

( 2 )

If indx GT 25 goto 20

L1: If indx GT 25 goto L0

( 3 )

t1 = indx-1

t1 = indx-1

( 4 )

t2 = t1*10

t2 = t1*10

( 5 )

t3=2*MLK// change to t3=MLK+MLK(Strength reduction)

t3=MLK+MLK

( 6 )

t4=t3-1// copy propagation remove statement

( 7 )

t5=t4-1//change statement as t5=t3-2

t5=t3-2

( 8 )

t6= t2 + t5

t6= t2 + t5

( 9 )

    t7= t6 + 4

    t7= t6 + 4

( 10 )

t8=indx-1      // common sub expression t1 = indx-1 (3) remove t8=indx-1

( 11 )

t9= t8 *10// common sub expression t1 = indx-1 (3) remove t8=indx-1

( 12 )

t10=2*MLK// remove this statement common code sub expression (5) t3=2*MLK

( 13 )

t11= t10-1// common code sub expression after changing variables (6)

( 14 )

t12= t9 + t11// common code sub expression(7)

( 15 )

t13= t12 + 4// common code sub expression(8)

( 16 )

CBA[t7]= ZYX[t13]//change code as CBA[t7]= ZYX[t7]

CBA[t7]= ZYX[t7]

( 17 )

t14= Indx+1//remove the code

( 18 )

Indx=t14//replace Indx=Indx+1 copy propagation

Indx=Indx+1

( 19 )

Goto(2)

Goto L1

( 20 )

L0:

The optimized code is

Indx = 1

L1: If indx GT 25 goto L0

            t1 = indx-1

            t2 = t1*10

            t3=MLK+MLK

            t5=t3-2

            t6= t2 + t5

            t7= t6 + 4

            CBA[t7]= ZYX[t7]

            Indx=Indx+1

            Goto L1

L0:

( 1 )

: =

#1

Indx

Indx = 1

( 2 )

JGT

Indx

#25

(20)

If indx GT 25 goto 20

( 3 )

-

Indx

#1

t1

t1 = indx-1

( 4 )

*

t1

#10

t2

t2 = t1*10

( 5 )

*

#2

MLK

t3

t3=2*MLK// change to t3=MLK+MLK(Strength reduction)

( 6 )

-

t3

#1

t4

t4=t3-1// copy propagation remove statement

( 7 )

-

t4

#1

t5

t5=t4-1//change statement as t5=t3-2

( 8 )

+

t2

t5

t6

t6= t2 + t5

( 9 )

*

t6

#4

t7

    t7= t6 + 4

( 10 )

-

Indx

#1

t8

t8=indx-1      // common sub expression t1 = indx-1 (3) remove t8=indx-1

( 11 )

*

t8

#10

t9

t9= t8 *10// common sub expression t1 = indx-1 (3) remove t8=indx-1

( 12 )

*

#2

MLK

t10

t10=2*MLK// change to t10=MLK+MLK(Strength reduction) and common code sub expression (5)t3=2*MLK

( 13 )

-

t10

#1

t11

t11= t10-1// common code sub expression t4=t3-1(6)

( 14 )

+

t9

t11

t12

t12= t9 + t11//

( 15 )

*

t12

#4

t13

t13= t12 + 4

( 16 )

: =

ZYX[t13]

CBA[t7]

CBA[t7]= ZYX[t13]//change code as CBA[t7]= ZYX[t7]

( 17 )

+

#1

Indx

t14

t14= Indx+1//remove the code

( 18 )

: =

t14

Indx

Indx=t14//replace Indx=Indx+1 copy propagation

( 19 )

JMP

( 2 )

Goto(2)

( 20 )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote