CSCE 312 Spring 2018 Midterm Exam

Write your answers on this question paper. Your answers must be clear and legible. Use the space provided to show how you arrived at your answer for partial credit. Only the answers you write in the spaces provided will be graded; you may use the back of the pages for your own private calculations. If a question seems ambiguous, state any assumptions you need to make to work the problem. Make sure to write your name on this paper.
  1. True/False. For each of the following answer 'T' for True or 'F' for False.
    1. _____ Any Boolean function can be computed by a circuit with only NOR gates.
    2. _____ Any Boolean function can be computed by a circuit with only NOT and AND gates.
    3. _____ Any Boolean function can be computed by a circuit with only AND gates.
    4. _____ There are O(n) full-adders in a ripple-carry-adder circuit adding two n-bit numbers.
    5. _____ The three-input majority circuit can be built with 5 two-input NAND gates.
    6. _____ A p-type transistor allows current to flow from source to drain when the gate input is set to 1.
    7. _____ An n-type transistor allows current to flow from source to drain when the gate input is set to 1.
    8. _____ A four-input K-map has 64 squares.
    9. _____ A 6-transistor SRAM cell contains two inverter circuits.
    10. _____ Modern CPUs from AMD and Intel are 32-bit processors.
    11. _____ The program counter register on x86-64 is called "%rax"
    12. _____ Condition codes contain facts about recently executed arithmetic or logical operations.
    13. _____ Memory is addressed as a three-dimensional array of bits.
    14. _____ Suppose %rcx=1 and %rbx=2. On a Linux x86-64 system, after we execute "movq %rbx, %rcx," the %rbx register will be 2.
    15. _____ %rdx is a register that points to the top of the machine stack.
    16. _____ For C/C++ programs, x86-64 stores integer data in memory in little-endian format.
    17. _____ For C/C++ programs, x86-64 stores string data in memory in little-endian format.
    18. _____ Suppose a C/C++ function returns an int. In assembly language, the return value would be kept in the %eax register.
    19. _____ The x86-64 instruction set uses little-endian representation.
    20. _____ ASCII stands for "A Simple Code for Internet Information."























    1. Consider the following C/C++ code:
              unsigned int a = 0x1eab577e;
              unsigned char *b = (unsigned char *) & a;
              for (int i=0; i<4; i++) printf ("%x", (unsigned int) b[i]);
      
      What is the output of this code on a Linux x86-64 system? Note that the "%x" format specifier for printf prints an unsigned integer as hexadecimal.












    2. Now look at this C/C++ code:
              unsigned int a, b;
              int c, d;
      
              a = 1 << 31;
              b = a * 2;
              printf ("%x\n", b);
      
              a = 0x1234;
              b = a >> 12;
              printf ("%x\n", b);
      
              c = -16;
              d = c >> 4;
              printf ("%d\n", d);
      
      What is the output of this code on a Linux x86-64 system? Note that the "%d" format specifier for printf prints an integer as a decimal number.














  2. Consider the following Boolean formula:

    a b c d + a b c d + a b c d + a b c d + a b c d + a b c d + a b c d + a b c d

    1. Fill in the following 4-input K-map with 1s and 0s equivalent to the function computed by this Boolean formula. Note that each product in that Boolean formula yields a 1 in a distinct K-map square.

    2. Give the minimal sum-of-products representation of this Boolean formula. That is, give a formula that computes the same function but has a minimal number of ORs and ANDs. Hint: there are three products and each one has only two variables in it. You should be able to read the minimal sum-of-products directly from the K-map; you should not need to do any further algebraic manipulations (so don't write a lot).





















  3. Consider the following circuit diagram:

    Give a truth table for the Boolean function of a and b computed by this circuit.






























  4. Consider the following C function:
    int foo (int a, int b, int c) {
            int t = a + b;
            int t2 = c - t;
            return t2;
    }
    
    When compiled into x86_64, it looks like this:
    foo:
            movl    %edx, %eax
            addl    %esi, %edi
            subl    %edi, %eax
            ret
    
    %edi, %esi, and %edx are parameters a, b, and c, respectively. Note that we are using registers like %eax instead of %rax because the parameters and variables are 32-bit integers, not 64-bit integers.

    1. Which register holds the value of t?





    2. Which register holds the value of t2?





    3. Which register holds the return value?