Homework Set #4


  1. Problem 5.1 from the text.

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

  3. C allows the definition of macros with arguments. For example, consider the following macro:
         #define max(A,B)  ((A) > (B) ? (A) : (B))
    
    1. What does this macro do? (Verify by experimentation.)
    2. What are the advantages and disadvantages of using a macro rather than a function that accomplishes the same thing?
    3. If I call the macro in the following way, what happens? (Again, experiment and verify.)
      max(i++,j++)

    Now consider another macro:

         #define square(x)  x * x
    
    1. What happens when I call square(y+1)?
    2. What change must be made to the macro definition to make it work correctly?

  4. Consider the following C function in which the function body has been omitted:
    int MyFunction(int argWord, char argByte)
    {
        int localWord;
        char localByte;
    
        ...
        ...
        ...
    
        return localWord;
    }
    
    Suppose that MyFunction() is called in a program and a debugger is used to display the contents of the stack while the body of the function is executing. Shown below is the stack dump that a debugger might give, and is very similar to the output given by the "ds" or "dump stack" command in Emu86. In the left column are the addresses of stack locations and in the right column are the 16-bit values stored at those locations. For example, we see from the table below that the number 0x1243 (4,660 in decimal) is stored at address 0000:FFF0. Since the 8086 is little endian, this means that the byte value 0x43 is stored at address 0000:FFF0 and the byte value 0x12 is stored at 0000:FFF1.
    Address   | Value
    ------------------
    0000:FFF2 | 0xF320
    0000:FFF0 | 0x1243
    0000:FFEE | 0x02EA
    0000:FFEC | 0xFFF6
    0000:FFEA | 0x0321
    0000:FFE8 | 0x02B9
    
    Assume that SS is 0, SP is 0xFFE8 and BP is 0xFFEC. Also, assume that the C calling convention is followed and that a standard stack frame is used (refer to the document C Calling Convention and the 8086 if necessary).

    1. What are the current values for argWord, argByte, localWord, and localByte in hexadecimal?
    2. What return address was saved on the stack when the function was called?
    3. What value for BP was saved on the stack?


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