
Compiler Construction – SMD163
Homework assignment 5
1.
Show how the compilation schemes E and S introduced on slides 41 - 51
in the notes for
lecture no. 8 can be extended to describe the translation of the
following constructs into 386
assembly language:
- the Boolean literal false;
- comparisons of the form e1 > e2;
- array accesses of the form v[e], where v specifies the address of
a global array of
32 bit integers, and e is an integer valued expression;
- array accesses of the form v[e], where v is a local variable (of
type int[]) found at
offset -16 from the frame pointer, and e is an integer valued
expression.
- blocks of statements of the form { s1 ... sn };
- assignment statements of the form v = e, where v is a local
variable
found at
offset -16 from the frame pointer;
- assignment statements of the form v = e, where v is a global
variable.
2.
Using the definitions for E and S from the slides together with the
extensions that you
described in your answers to Question 1, translate the following
program into 386 assembly
language.
tot = 0;
j = 0;
while (count > j) {
tot = tot + a[j];
j
= j + 1;
}
You may assume that all variables are allocated globally, at symbolic
addresses denoted by
their respective names.
Be sure to follow the compilation rules in the same, mechanical fashion
that a compiler
would, and do not attempt to optimize the generated assembly code in
any way.
Report via email to
Subject line: SMD163 - 5.
Deadline is Feb 27, 10:00.
Homework assignments are carried out individually.
Oral discussion is good, copying
files is not!