Professional Documents
Culture Documents
44-525 Theory and Implementation of Programming Languages Intro Exercise 05
44-525 Theory and Implementation of Programming Languages Intro Exercise 05
44-525 Theory and Implementation of Programming Languages Intro Exercise 05
Intro Exercise 05
Consider the following code fragment:
for( i = 1; i <= 10; i++ )
{
x = x + 2 * y;
}
A compiler might generate the intermediate code shown below. Note that
each instruction consists of a single arithmetic operation, a conditional
branch, or a jump.
test:
i = 1
if i > 10 jump to endfor
temp = 2 * y
x = x + temp
i = i + 1
jump test
endfor:
(a)
What is the total number of instructions that is executed when this
code is run?
(b)