CMSI 284
Final Exam

The test is open-everything with the sole limitation that you neither solicit nor give help while the exam is in progress.

Submit all answers on these exam sheets. No extra sheets are allowed. If you are nervous about this, work out the problem on a separate sheet and copy your answers here. Work quickly but carefully.

ProblemYou gotOut of
1
 
10
2
 
10
3
 
10
4
 
10
5
 
10
6
 
10
7
 
10
8
 
10
9
 
10
10
 
10
TOTAL
 
100
  1. Convert the following codepoints to UTF-8 (Express your answer in hex):
    
    
        00032b12  ____________________________
    
    
    
        0000fade  ____________________________
    
    
    
        00007fff  ____________________________
    
    
  2. Give the single precision IEEE-754 encoding of -1026.625 and explain your answer.
  3. Give x86 logic operations to perform the following operations on the esi register (assuming that it contains an unsigned number).
        Complement every odd-numbered bit  ___________________________________
    
    
    
        Replace it with its value mod 64  _______________________________________
    
    
    
        Replace it with the largest multiple
        of 64 less than or equal to itself  ______________________________________
    
  4. Write a C function that reverses an array of integers, that is implemented by using pointers, not array indexes, to manipulate the array. Note that the functions will have two arguments; the first (being the array) has type int* and the second (being the length) has type int.
  5. Write, in assembly language, a function that is intended to be called from C, that takes in an array of ints (and its length) and returns the maximum value in the array. Do not use any conditional jumps other than one to determine when you are "done" iterating through the array. Implement the function the easy way, with cmovg.
  6. What does this code fragment do?
        xor eax, ebx
        xor ebx, eax
        xor eax, ebx
    
  7. Implement the following in NASM:

    int spfft(int a, int b, int* c, int d) {
      if (&b < c)
        return a / b / *c % d;
      else
        return d * *c;
    }
    
  8. Write the following in assembly language (use the C calling convention). It is supposed to compute a*log10(b). Use the fyl2x and fldl2t instructions.

    double f(double a, double b);
  9. Explain in detail how the following computes the minimum of the two signed numbers in eax and ebx, leaving the result in ebx. (Hint: give your explanation in two parts — one in which eax starts off less than ebx and the other where it doesn't.)
        sub eax, ebx
        cdq
        and edx, eax
        add ebx, edx
    
  10. What well-known mathematical function is this?
    mystery:  cdq
              xor     eax, edx
              sub     eax, edx
              ret
    

    Explain why it works.