Final Exam Topics


  1. bitwise operations on binary expressions (1's and 0's)
  2. Interpret binary expression as twos complement signed decimal value and as an unsigned decimal value
  3. Given a negative decimal value give its twos complement representation in hex.
  4. Write C expressions for the following values as expressions using the variable x. The result for x = 0x98FDECBA and a 32-bit word size shown in square brackets next to each question. Although the examples assume a 32-bit word size, your code should work for any word size

    1. The least significant nibble (4 bits) of x with all other bits set to 0 [Ans. 0x0000000A]
    2. The lease significant nibble of x with all other bits set to 1. [Ans. 0xFFFFFFFA]
    3. The complement of the least significant nibble of x with all other bits left unchanged. [Ans. 0x98FDECB5]
  5. For the following int, unsigned int and float types mark each of the following as "always true" or "sometimes false". Assume the variables have some random initial value. But assume the float values are NOT + or - infinitiy and also NOT Nan.

    	  int x, y;
    	  unsigned int u, v;
    	  float f, g;
    	
    1. x == ~(~x)
    2. if x >= y then (x + x) >= y
    3. if f >= g then (f + f) >= g
    4. ((x + y) - x) == y
    5. ((f + g) - f) == g
    6. if (x & 0xF) == 0xF then (x << 29) < 0
    7. if x < 0, y < 0 and (x + y) >= 0 then overflow occurred
    8. u < u + v
    9. x == (int) (float) x
    10. x == (int) (double) x
    1. Given register and memory contents, give the memory address indicated by different operands. (See quiz3 review)

    2. Given register and memory contents give the value stored by a movl or a leal instruction.

  6. Given 3 C code function versions, and 1 assembly code version. Identify which C code compiles to the assembly code.

    C functions
    int fun1(int x, int y)
    {
      if ( x < y ) {
        return x;
      } else {
        return y;
      }
    }
    
    int fun2(int x, int y)
    {
      if ( x < y ) {
        return y;
      } else {
        return x;
      }
    }
    
    int fun3(int x, int y)
    {
       unsigned ux = (unsigned) x;
       if (ux < y) {
         return x;
       } else {
         return y;
       }
    }
    	    
    Assembly Code
         pushl %ebp
         movl %esp,%ebp
         movl 8(%ebp),%edx
         movl 12(%ebp),%eax
         cmpl %eax,%edx
         jge .L9
         movl %edx,%eax
    .L9:
         movl %ebp,%esp
         popl %ebp
         ret
    	      
    	    
  7. Practice problem 3.41

    For each of the following structure declarations, determine the offset of each field, the total size of the structure, and its alignment requirements under Linux/IA32.

    Alignment: shorts: 2 byte boundary; larger: 4 byte boundary.

    Alignment: structs must be aligned on a boundary that is a multiple of the alignment of the largest field.

    A. struct P1 { int i; char c; int j; char d; };
    B. struct P2 { int i; char c; char d; int j; };
    C. struct P3 { short w[3]; char c[3]; };
    D. struct P4 { short w[3]; char *c[3]; };
    E. struct P5 { struct P1 a[2]; struct P2 *p;};
    F. struct P6 { short s; char c; char d; int n; };
    	
  8. Cache Lookup ( Feb 22 Lecture notes and Practice problems 6.10 and 6.14)