314 Homework 1

  1. What is the binary representation of the hexadecimal number: 0xDEADBEEF ?
  2. What is the hexadecimal representation of the decimal number 314 ?
  3. What is the hexadecimal representation of the binary number:
    0110 0010 1111 0100 1100 1010 0011 0001
  4. What is a caller-save register ?
  5. What is a callee-save register ?
  6. What are the advantages of a caller-save calling convention over a callee-save calling convention ?
  7. What are the advantages of a callee-save calling convention over a caller-save calling convention ?
  8. Answer questions 3.1, 3.2, 3.4, 3.11, 3.21 and 3.25 from the book.
  9. Write a MIPS assembly routine whose signature looks like this:
     
        unsigned int round(unsigned int a, unsigned int b)"
    
    
    round(a,b) should return the integer c which is equal to integer a rounded to integer b. For instance, round(15, 10) = 10, round(27, 9) = 27, round(8, 3) = 6. You may assume that a is always greater than b at the time round is called. It is tempting to solve this problem using a division instruction. Instead (to gain familiarity with control flow instructions), you should implement your routine using repeated subtractions from the first argument, and repeated additions to the result register. The pseudo-code should look roughly like this:
    
       int res = 0;
       while(a >= b) {
          a -= b;
          res += b;
       }
       return res;
    
    
  10. Write a MIPS assembly routine whose signature looks like this:
     
        void roundarray(unsigned int c[2000], unsigned int d)
    
    
    This routine should invoke the round function from the previous question to replace each element of the array with its old value plus the result of rounding the old value to d. For instance, if the first element of the array is 25 at the time roundarray is called (i.e. a[0]=25), and d = 10, upon return from this function a[0] should contain 45 (old value 25 plus round(25, 10), which is 20, yields 45). Make sure you obey the caller/callee-save rules in the MIPS calling convention during the procedure call from roundarray to round. Be careful not to run off the end of the array.