CS360 Midterm Exam: March 2, 2004

Question 3

Convert the following main() to assembly code:
main(int argc, char **argv)
{
   int i;

   i = 1;
   b(6, atoi(argv[1]));
   return i;
}

Question 4

Behold the following piece of assembly code:
a:
    push #8
    st %g0 -> [fp]
    ld [fp+12] -> %r0
    st %r0 -> [fp-4]
    b l1
l0:
    ld [fp-4] -> %r0
    add %r0, %g1 -> %r0
    st %r0 -> [fp-4]
l1:
    ld [fp-4] -> %r0
    ld [fp+16] -> %r1
    cmp %r0, %r1
    bge l2
    ld [fp] -> %r0
    ld [fp-4] -> %r1
    add %r0, %r1 -> %r0
    st %r0 -> [fp]
    b l0
l2:
    ld [fp] -> %r0
    ld [fp+20] -> %r1
    st %r0 -> [r1]
    ret
On the answer sheet provided, circle the proper answer to each of the following questions about the assembler and the C code from which it was derived.

Part a. Does this procedure perform register spilling?
Part b. How many local variables does this procedure have?
Part c. How many parameters does this procedure have?
Part d. Does the C procedure have a return value?
Part e. Are any local variables pointers?
Part f. Are any parameters pointers?
Part g. Is there an if statement in the C code?
Part h. Is there a while loop in the C code?
Part i. Is there a for loop in the C code?