CS 208: Computer Organization & Architecture

Takehome Exam #2

Submit as a PDF file via Moodle by 2:20PM Friday, November 11.

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.

This exam was designed to produce short answers for each question, although the justification of your answers (showing your work, showing a diagram if relevant, etc.) is still important. With that in mind, your submission should have the following structure:

Some answers don't require much explanation. However, when you get an answer wrong, showing your work can lead to significant partial credit if your reasoning is sound but you made a small mistake.

  1. (6 points)

    1. What is the 32-bit IEEE 754 representation of the number -50.625? Give your answer as a single 8-digit hexadecimal number.
    2. To what number does the 32-bit IEEE 754 representation 0x40755555 correspond? Please express your answer as a fraction. (Note: since the significand appears to have a repeating pattern, you may find that extending that pattern infinitely gives you a simpler fraction than the rounded off version stored in this 32-bit float.)
  2. (8 points) Character encoding in Python 3. (That's Python 3, not Python 2--they're quite different for this material.)

    You might find the Unix command hexdump -C filename handy in this problem, just for checking to make sure your files look right.

    1. If you do the assignment statement
      s = 'résumé'
      what Python 3 type is the variable s? Excessively helpful hint: the answer to this question is str, which you can verify with print(type(s)).
    2. Of what does an object of type str consist? (Go to the official Python documentation for this one, and keep your answer to one sentence. A link or citation would be appropriate here.)
    3. What is an encoding of an object of type str? (Again, keep this to one sentence.)
    4. What is a BOM?
    5. Use a text editor to save a file (including some non-ASCII characters) in the UTF-8 encoding with no BOM (TextWrangler is quite nice for this, but it can be done with lots of text editors. Note that MS Word is not a text editor). What code would you use to open this file and read its contents into a variable of type str? (This can be done in one short line of code, or two if you are stylistically picky.)
    6. Same question as in part (e), but for UTF-16 little endian.
    7. What code would you use to write a str variable to a file using the UTF-16 big endian encoding with no BOM?
  3. (2 points) Tell me a joke, or if you prefer, recommend a movie for me to see. Thank you.

  4. (9 points) Consider our favorite non-pipelined datapath, Figure 4.17.

    1. Suppose PC is pointing to an address containing the instruction "li $a1, -45". List the values for RegDst, Branch, MemRead, MemToReg, MemWrite, ALUSrc, and RegWrite. You may specify each as 0, 1 or DC (for "don't care").
    2. As we have noted in class, this datapath does not support the bne instruction. Suppose we replace the Branch control line with a 2-bit BranchType line BT_1 BT_0, whose value is 00 if the instruction is not a branch, 01 for beq, and 10 for bne. Give logic formulas for BT_1 and BT_0 In terms of the opcode I_31 I_30 I_29 I_28 I_27 I_26 (i.e., the highest-order six bits of the instruction). Make sure, of course, that your formulas never generate 11.
    3. Let's call the control line going into the multiplexer in the upper right of the diagram PCSrc. Now that we have replaced the Branch control with BranchType, give a formula for PCSrc in terms of BT_1, BT_0, and Zero. If we replace the existing AND gate with this new formula, we will now have a datapath that supports both beq and bne.
  5. (9 points) Consider this slightly enhanced version of our pipelined datapath with forwarding, Figure 4.56. Suppose further that the sequence of instructions currently in the pipeline is:

    lw $A, 24($sp) [MEM/WB] add $B, $8, $9 [EX/MEM] sub $5, $6, $7 [ID/EX] beq $3, $4, loop [IF/ID]

    where A and B are register numbers yet to be determined. As usual in our exercises, assume the current contents of $k = 0x00001000 * k for each k from 0 to 31.

    1. What are the current values of the lines marked X, Y, Rs, Rt, and Rd in the EX section of the datapath?
    2. What values of A and B would cause ASrc1 = 1 and ASrc2 = 2?
    3. What values of A and B would cause ASrc1 = 2 and ASrc2 = 1?
    4. What values of A and B would cause ASrc1 = 2 and ASrc2 = 2?