Assignment 11, Solutions

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

  1. Background: A typical fast typist can type 60 words per minute, where a word is 5 letters, on the average, and most words are separated by spaces. A typical modern CPU can execute on the order of 1,000,000,000 instructions per second (rounded to the nearest power of 1000).

    a) How frequently must the keyboard-ready bit be polled to keep up with a fast typist? (0.3 points)

    60 words per minute at 5 letters per word plus a space between words is 360 characters per minute or 6 characters per second.

    Therefore, the keyboard ready bit must be checked at least 6 times per second to avoid data loss. 1/6 second is 166 milliseconds, so we must check the ready bit every 166 milliseconds.

    b) How many times a second will the KBGETC routine from the Hawk Monitor poll the ready bit while it is waiting for input? (0.3 points)

    If our machine really runs at 1,000,000,000 instructions per second (there is reason to doubt this for any instructions that check I/O status registers, since access to them cannot be accelerated by a cache), that is 1 nanosecond per instruction.

    The polling loop inside KBGETC is 2 instructions long, so it re-tests the keyboard status every 2 nanoseconds.

    c) How do the above considerations motivate the introduction of interrupt mechanisms in CPU design. (Open ended question). (0.4 points)

    The answer to part a) was bit every 166 milliseconds. The answer to part b) was bit every 2 nanoseconds. That means that the polling loop is polling the polling the status bit 83,000,000 times faster than necessary. This means that there is time for a considerable amount of computation between tests of the polling loop. Interrupt mechanisms provide one way to automate the polling so that computation can proceed normally without concern for polling.

  2. Background: In the early 1970's, Centronics was a major manufacturer of impact printers. Centronics printers were common enough that when IBM came out with the PC, they included a Centronics-compatible parallel port, and as a result, the terms IBM PC Parallel port and Centronics Printer Port are synonyms. This interface defines the following connections (somewhat simplified): Note: If you hunt for documentation on the Internet, you will find lots of stuff specific to the PC. This is a bit confused because the PC gratuitously inverts some of the signal lines, more or less at random. (Actually, the inversions aren't gratuitous; they make it so that, when you turn the power to the PC, it comes up not trying to output anything.)

    a) Give a timing diagram showing Data, Strobe and Ack and Busy as a function of time as the computer sends 2 characters to the printer which then prints them. You can show just two data values, call them valid and invalid. (0.5 points)

                                valid               valid
                    |        ____________        ____________
            Data    |--------____________--------____________--------
                    |__________        ____________        __________
            Strobe  |          |______|            |______|
                    |______________        ____________        ______
            Ack     |              |______|            |______|
                    |                    _______             _______
            Busy    |___________________|       |___________|       |
                    |_________________________________________________
                                     time ------>
    

    b) Give pseudocode -- it need not be in a real programming language -- for the parallel port print ppprint(ch) routine, focusing on waiting for the right conditions reported by the printer and setting the outputs appropriately at the right times. (0.5 points)

            ppprint(ch) {
                    while (ppstatus.ack == 0) wait;
                    ppdata = ch;
                    while (ppstatus.busy == 1) wait;
                    ppstatus.strobe == 0;
                    while (ppstatus.ack == 1) wait;
                    ppstatus.strobe == 1;
    	}
    

  3. Background: Consider a logic circuit with the following structure:

    This circuit is a memory device, a kind of flipflop. It can be made to remember one bit.

    a) Draw this circuit as a logic diagram. (0.4 points)

    schematic diagram of a mystery flipflop

    b) Give a table showing the 4 input combinations, identifying the combinations that set and reset the flipflop and the combination that allows it to remember. The final combination is the one that should usually be avoided. (0.4 points)

      a    b     c    d  
    0000Reset
    0101(avoid)
    100/10/1Remember
    1111Set

    c) When it is remembering a stored value, are the outputs of this flipflop the same or different? (0.2 points)

    The same.