Assignment 11, due Nov

Part of the homework for 22C:60, Fall 2010
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always write your name legibly as it appears on your University ID and on the class list!

Note, only the top 10 homework scores will be counted toward the final grade, but it would not be wise to cease doing homework just because you have 10 strong scores. All material covered in the homework is liable to be covered in exams, and the best way to study it is to work on the homework.

Homework

  1. Background: Here is the description of a logic circuit in purely equational terms:
    inputs: a and b
    outputs: e and f
    intermediate values: c and d
    c = a + b
    d = ab
    e = cf
    f = d + e

    a) Draw the logic circuit in schematic form with the inputs on the left and outputs on the right. (0.5 points)

    b) Draw a timing diagram for this circuit showing how the outputs change as the inputs move through the following sequence of 13 changes: (0.5 points)
      [a,b] = [0,0],[0,1],[0,0],[1,0],[1,1],[1,0],[0,0],[1,0],[1,1],[0,1],[1,1],[1,0],[0,0]

    c) Is this circuit a kind of flipflop? If so, what input combination causes it to remember a value, how do you set it, and how do you reset it?

  2. Background: The solution to MP4 distributed on line doesn't contain any checking for errors. If the input string were "zuuuuuuuuuuuuuuu*", for example, it will try to put an asterisk fifteen lines above the top of the screen, probably resulting in a bus trap error. If the input string contains unbalanced parentheses, such as "((((((((((", things also begin to go wrong.

    An obvious way to deal with such errors is to raise an exception when the interpreter discovers something irregular. It would be easy, for example, to check, before outputting a character, to see if the x and y coordinates are on the screen, and raise an exception if not.

    a) Where should the handler be? (0.5 points)

    b) What would you check for, and where in the code, to detect unbalanced parentheses as illustrated above? Hint: There is no need to count the parentheses. (0.5 points)

  3. Background: Look at the code in Chapter 13 for raising an exception in the general case. Suppose a program includes error checks that raise large numbers of different exceptions. Duplicating different versions of this 4-instruction block of code each time an exception is raised seems wasteful.

    A Problem: Suggest a way to compact the code for raising exceptions by putting most of the code in one place with just one or two instructions that must be duplicated in each place the exception is raised. Your code might take one or two extra instructions to raise an exception, but it should be more compact if there are enough exceptions raised in the program. (0.5 points)