CS 208: Computer Organization and Architecture

Midterm exam, due on paper at 8:30AM Friday, October 21, 2011.

This is a an exam. You may consult your notes, any book, and the Internet. You may not speak with any person other than Jeff Ondich, electronically or otherwise, about the content of this exam. If you obtain relevant information from any source other than yourself, cite your sources clearly. Justify your answers. (Note that "justify your answers" implies "show your work.") Have fun.

  1. Numbers (10 points)

    1. In base ten, what is the value of the largest 32-bit two's complement integer?
    2. In base ten, what is the value of the smallest 32-bit two's complement integer? (Note that "smallest" and "largest" refer to position on the number line so, for example, -3 is smaller than 2.)
    3. If you have a 32-bit two's complement integer N > 0, and 2*N is small enough to be representable as a 32-bit two's complement integer, then you can double N by shifting its two's complement representation left by one bit. Now, suppose N < 0. Does shifting left double N? If so, explain why. If not, give an example where it fails.
    4. Show the 32-bit IEEE 754 representation of the number -35.875.
    5. To what real number does the 32-bit IEEE 754 representation 0x40155555 correspond? (Hint: since the significand appears to have a repeating pattern, you may find that extending that pattern infinitely gives you a simpler real number than the rounded off version stored in this 32-bit float.)
  2. (5 points) Sometimes you want to write code that behaves like this pseudo-code:

        if A < B
            do X
        else if A > B
            do Y
        else
            do Z

    Assuming X, Y, and Z are unknown-length blocks of code, write PAL code implementing this if/else-if/else structure. You may assume that the whole thing, include the locations A and B, fits on a single page. You can just write "[X goes here]" or something similar to indicate where X, Y, and Z appear in your code.

  3. (6 points) Consider the following story about D latches and flip-flops.

    • In the beginning, Q = 0, D = 1, and C = 0
    • C's value rose to 1
    • D's value fell to 0
    • C's value fell to 0

    Assuming there was a long enough pause between each step to enable the whole circuit to stabilize, draw a timing diagram for this story for each of the following:

    1. The D latch in Figure C.8.2 of the textbook
    2. The D flip-flop in Figure C.8.4
    3. The D flip-flop in Figure C.8.4, but with the NOT gate moved so it goes in front of the C line on the lefthand latch instead of the righthand latch
  4. (6 points) Consider the following boolean function of three variables:

         A   B   C  | Out
        =================
         0   0   0  |  1
         0   0   1  |  1
         0   1   0  |  0
         0   1   1  |  1
         1   0   0  |  1
         1   0   1  |  0
         1   1   0  |  1
         1   1   1  |  0
        

    • Write a boolean algebraic expression for this function, using a conjunction (sum) of 3-term products, as we did with a similar function in class.
    • Simplify your algebraic expression as much as possible.
    • Draw a circuit implementing this function using AND, OR, and NOT gates. Use as few gates you can.
  5. (2 points) I just finished a book (Our Kind of Traitor, by John LeCarré--quite good, as he usually is). What should I read next?

  6. (7 points) Assembly language in its purest form has the property that each assembly instruction corresponds to exactly one machine/binary instruction. The PAL language as you have learned it has this property (e.g. "TAD 0007" corresponds to "1007", etc.). Even with that level of purity, however, the designers of the PAL assembler "pal" have seen fit to give programmers a little extra help, by providing assembler directives (e.g. *0200), comments, etc.

    Another kind of help assembler writers sometimes provide is called a "pseudo-instruction" (see pages 140-141 of the textbook). A pseudo-instruction typically corresponds not to a single machine instruction, but to a sequence of instructions. The assembly language programmer will use the pseudo-instruction in a program just like any other instruction, but when the assembler runs (e.g. "pal -r myprogram.pal"), the pseudo-instruction gets transformed into two or more machine instructions instead of just one. The programmer, for most purposes, never has to know the difference. (Or course, as with any programming knowledge, knowing how a thing works makes debugging and performance-tuning easier, so it's good to know which instructions are pseudo and which aren't.)

    If I were about to embark on a major PDP-8 programming project and I wanted to give myself and my teammates some help, I think the thing I would desire most urgently would be a second accumulator. Since I'm not going to modify the PDP-8 hardware (I'm terrible with a soldering iron), I could modify the PAL assembler instead, to simulate a second accumulator. I would, for example, provide myself with instructions like CLA2, TAD2, DCA2, etc.

    Your job for this problem is to explain in detail how you would go about modifying the pal program to simulate a second accumulator. You'll need to explain where the contents of AC2 get stored, what instruction sequences TAD2 and DCA2 get transformed into, what additional restrictions this new stuff will place on PAL programmers, and so on. The goal is to give me as a PAL programmer access to a simulated accumulator AC2. How would you go about giving me that?