Homework Set #5


  1. Problem 6.1 from the text. Explain your answer.

  2. Problem 6.2 from the text. Explain your answer.

  3. Let's investigate two ways of declaring and initializing two-dimensional arrays, as illustrated in this short C program: C Program. Study the source code, then compile, assemble, and run the program using the ECEn 425 tools. Then use the listing file to answer the following questions:

    1. How many identical copies of each string are stored in memory when the program loads?
    2. How did the compiler represent a and b in the assembly file?
    3. How many total bytes are required to represent array a?
    4. How many total bytes are required to represent array b (including string data)?
    5. Suppose we wish to sort the strings in each array in alphabetical order. Let us assume that the sorting algorithm will swap the contents of pairs of rows in some unspecified order until they are sorted. Are there substantial differences in the relative overhead of swapping rows in the two different array representations? Why or why not?

  4. Consider the following sample program:
    #include "clib.h"
    
    int AsmFunction(int a, char b, int c);
    
    void main(void)
    {
        printString("Hello, world!\n");
        AsmFunction(10, 35, 3);
    }
    
    The function AsmFunction() is written in assembly and is contained in another source file. Notice the line "int AsmFunction(int a, char b, int c);" at the beginning of this code. This type of statement is often called a function prototype. Answer the following questions:

    1. What is the purpose of the function prototype?
    2. Why do we not see a function prototype for the function printString() in the above code?
    3. Where is the code for printString()?


Turn in your hard-copy solution for this assignment to the homework box before 4:45 PM on the due date.
Last updated 3 September 2013
James Archibald jka@ee.byu.edu