Homework Assignment 6 -- CS429 Fall 2013

Due Date: 9 Oct 2013

  1. I want to dynamically allocate an array of 5 elements of type int. Which of the following will do that?
    1. p = malloc(5);
    2. p = realloc(p,5);
    3. p = calloc(sizeof(int),5);
    4. p = malloc(sizeof(int));
    5. p = malloc(5*sizeof(int));
    6. p = malloc(sizeof(5*int));

    When I go to compile this, I get an error message:
    warning: initialization makes integer from pointer without a cast
    1. What does this mean?
    2. What should be the type of p?

  2. Suzie has a computer with vectored, priority interrupts with the interrupted address saved on a stack. Poor Joe has a computer that just saves the interrupted PC in location 0 and starts executing at location 8. Which of the features of Suzie's computer can Joe add in software to get the same functionality?

    1. vectored interrupts
    2. stacked interrupt address
    3. priority interrupts

    What does Joe lose by doing the things that he can in software instead of hardware?

  3. Assume a 32-bit machine with 32-bit addresses. The stack always pushes and pops 32-bit values. If the stack pointer is currently 0xFFFFF400, consider the following:
    int foo(int c, int d)
        int x[5];
        int i;
        z = foo(3,5);

    Inside the body of the function foo, what is the offset from BP to access

    1. i?
    2. x[3]?
    3. x[5]?
    4. c?
    5. d?