CSCE 312 Spring 2018 Second 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. _____ Consider a buffer overflow exploit where the attacker sends a malicious string attempting to get the program to return somewhere in the string. This attack will fail if the pages of the stack are marked as not executable.
    2. _____ Consider a buffer overflow exploit where the attacker sends a malicious string attempting to get the program to return to several places in the standard C library. This attack will fail if the pages of the stack are marked as not executable.
    3. _____ A two-level page table improves access time, but doesn't decrease the size of the page table.
    4. _____ A fully-associative cache is likely to give a better miss rate than a direct-mapped cache.
    5. _____ A set-associative cache is likely to give a better miss rate than a direct-mapped cache.
    6. _____ Virtual memory is useless without having a disk for paging.
    7. _____ Replacing switch with a sequence of if statements generally results in faster code.
    8. _____ A fully associative cache cannot have conflict misses.
    9. _____ A direct-mapped cache cannot have capacity misses.
    10. _____ Increasing the block size would reduce compulsory misses for a program with good locality.
    11. _____ A function call inside a loop can prevent the compiler from performing certain optimizations.
    12. _____ leaq (%rbx,%rbx,4), %rbx multiplies the %rbx register by 5.
    13. _____ Let %rax=1. Then subq %rax,%rax; leaq %rax, 1(%rax); je L1 would jump to L1.
    14. _____ Any C program may be rewritten correctly without for, while, and do/while.
    15. _____ Any C program may be rewritten correctly without switch without changing execution time.
    16. _____ Virtual memory uses the DRAM as a direct-mapped cache for the disk.
    17. _____ A four-variable Karnaugh map has 16 squares.
    18. _____ SRAM is generally faster than DRAM.
    19. _____ The x86_64 instruction set includes floating point instructions.
    20. _____ The TLB caches page table entries.



















  2. Consider a direct-mapped cache with 16-bit addresses, 16-byte blocks, and 16 sets. The following table gives the contents of the cache valid bits and tags:
    Cache Contents
    Index
    Valid
    Tag
    0 1 0xa7
    1 1 0xf1
    2 1 0xd9
    3 1 0x2a
    4 0 0x82
    5 1 0xc8
    6 1 0xd8
    7 1 0xfe
    8 1 0x43
    9 0 0x4d
    10 1 0x98
    11 1 0x55
    12 0 0x8c
    13 1 0xe2
    14 1 0xb3
    15 1 0x47

    1. What is the capacity of the cache in bytes?


    2. What is the size of a tag in bits?


    3. For each of the following addresses, write hit in the blank space next to it if it would be a hit, or miss if it would be a miss. For each subsequent access, assume that the previous accesses have occurred and have updated the tags and valid bits:
      
      0x47f4 _____________
      
      0x4d9a _____________
      
      0x1a45 _____________
      
      0xa702 _____________
      
      0x1a42 _____________
      
      0x1b40 _____________
      
      0x1a45 _____________
      
      





  3. 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
    
    1. Which register holds the value of a?





    2. Which register holds the value of b?





    3. Which register holds the value of c?





    4. Which register holds the value of t?





    5. Which register holds the value of t2?





    6. Which register holds the return value?








  4. Consider the following C program:
    struct {
            int     a;
            char    b;
            double  c;
            char    *d;
            char    e;
    } X;
    
    int main () {
            printf ("%d\n", sizeof (X));
            printf ("%p\n", & X);
            X.a = 1;
            X.b = 2;
            X.c = 3;
            X.d = (char *) & X;
            X.e = 4;
            printf ("%d\n", * X.d);
            printf ("%d\n", * (X.d + 4));
            printf ("%d\n", * (X.d + 24));
    	return 0;
    }
    
    The first printf prints 32. The second printf prints 0x601080 (note that %p prints a hexadecimal pointer value).