CS 3843, Spring 2011
Computer Organization
Homework 3

Due Monday, February 14, 2011.

  1. Do the following homework problems from the book:
    1. 2.58 on page 119: Write a function is_little_endian that will return 1 when compiled and run on a little-endian machine, and will return 0 when compiled and run on a big-endian machine. This program should run on any machine, regardless of its word size.
    2. 2.59 on page 120: Write a C expression that will yield a word consisting of the least significant byte of x, and the remaining bytes of y. For operands x = 0x89ABCDEF and y = 0x76543210, this would give 0x765432EF.
    3. 2.74 on page 125: Write a function with the following prototype:
      /* Determine whether arguments can be subtracted without overflow */
      int tsub_ok (int x, int y);
      
      This function should return 1 if the computation x - y does not overflow, 0 otherwise.
    4. 2.81: We are running programs on a machine where values of type int are 32 bits. They are represented in two's complement, and they are right shifted arithmetically. Values of type unsigned are also 32 bits.

      We generate arbitrary values x and y, and convert them to unsigned values as follows:

      /* Create some arbitrary values */
      int x = random();
      int y = random();
      /* Convert to unsigned */
      unsigned ux = (unsigned) x;
      unsigned uy = (unsigned) y;
      

      For each of the following C expressions, you are to indicate whether or not the expression always yields 1. If it always yields 1, describe the underlying mathematical principles. Otherwise, give an example of arguments that make it yield 0.

      1. (x < y) == (-x > -y)
      2. ((x + y) << 4) + y - x == 17*y + 15*x
      3. ~x + ~y + 1 == ~(x+y)
      4. (ux - uy) == -(unsigned) (y - x)
      5. ((x >> 2) << 2) <= x

    When the problems call for C code, make sure the code you write actually compiles and runs correctly on an x86 Linux system such as the main computers.

  2. Write a minimal sum-of-products formula for a function f in four variables x3, x2, x1, and x0, such that f(x3, x2, x1, x0) is true if and only if the 4-bit unsigned integer represented by x0-3, with x0 as the least significant bit, is not prime. Note that 0 and 1 are not prime. Use a Karnaugh map. Show your work.

Write up the answers to these homework problems using a word processor or typesetting program and email a PDF to your teaching assistant as an attachment by 11:59pm, Monday, February 14, 2011. You may draw your K-map by hand and scan it in, or you may (preferably) use a computerized drawing program. All other work must be word-processed. Make sure to email only one PDF file containing everything you intend to turn in. You may not work together on this assignment. Late assignments will not be accepted.