Rutgers University CS 211 Sections 1 and 2, Fall 2005 Computer Architecture Third Exam

Read these instructions carefully. On the front of your bluebook, write your name and section number (1 or 2). Choose TWO of the following questions to answer and write your answers in the bluebook provided. Do not answer more than two questions; we will only grade the first two answers we encounter.

  1. Consider the following C function:
    void foo (int n) {
            int i, *p;
                                                                                    
            for (i=1; i<=n; i++) {
                    p = (int *) malloc (i);
                    free (p);
            }
    }
    
    Suppose that malloc uses a single explicit free list to keep track of free blocks. free puts a block at the head of the list in constant time. The asymptotic time complexity of this function in terms of n is given by the total number of times a link in the free list is traversed (assume constant time for allocating a new block from system memory). For instance, if an ideal version of malloc traverses only one link per iteration, then the asymptotic complexity would be O(n).

  2. Consider the following fragment of assembly language, with line numbers added for reference:
    1         movl    $9, %edx
    2 .L1:
    3         addl    %eax, %esi
    4         addl    %esi, %eax
    5         addl    %ebx, %ecx
    6         addl    %ecx, %ebx
    7         decl    %edx
    8         jns     .L1
    
    Assume the following: Without changing the meaning of the code, rewrite it so that it will execute faster. That is, your new code should run faster and all of the register values at the end of the loop should be the same as they would be for the unmodified code.

  3. Assume the following: Answer the following questions: