CS360 Midterm Exam: March 2, 2004. Answer to Question 4
|
- Part a. Registers r2 - r4 are not used,
so there is no spilling: no.
- Part b. The push #8 combined with the fact that
[fp] and [fp-4] are used separately imply that there
are two local variables: 2.
- Part c. [fp+12], [fp+16] and [fp+20]
are all used -- so a() has three parameters: 3.
- Part d. There is no explicit loading of a value into
r0, so a() appears to have no return value. Perhaps
something like ``return *p1 = total'' might actually cause
this code, but unless you denoted this, the correct answer is: no.
- Part e. Only the values of [fp] and [fp-4] are
ever used. Moreover, they are used in standard addition -- they are
int's: no.
- Part f. [fp+20] is most definitely used as a pointer:
yes.
- Part g. There are labels, but they are used in the pattern
that we have specified for for loops: no.
- Part h. See above: no.
- Part i. See above: yes.
Here is a reasonable C program that would produce this code:
a(int a, int b, int *p)
{
int i, total;
total = 0;
for (i = a; i < b; i++) {
total += i;
}
*p = total;
}