Assignment 7, due Mar 15

Part of the homework for 22C:60 (CS:2630), Spring 2013
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: Consider the problem of converting all upper case text in a string to lower case. A subroutine to do this must look at each character in the string. If the character is upper case, that is, between 'A' and 'Z' inclusive, it can be converted to lower case by adding the constant 'a'-'A'. This works using any character set where the codes for the upper case letters are in alphabetical order, with no gaps, and so aare the codes for the lower case letters.

    A problem: Write a subroutine that takes a pointer to a null-terminated string as a parameter and edits that string, converting all upper case letters in that string to lower case. (The string must be stored in RAM, not ROM, for this to be possible. This is not a machine problem. If your code is correct and legible, it will receive full credit even if it is handwritten.) (1.0 points)

  2. Background: Consider this statement in C (or C++ or Java or C#, they all look pretty much the same:
            if (!((ch < 'A')||(ch > 'Z'))) ch = ch + ('a' - 'A');
    

    A problem: Apply DeMorgan's laws to the Boolean expression on the if statement. The result should be easier to read. (0.2 points)

  3. Background: The LOADS instruction sets the C condition code oddly in order to support highly optimized text processing code (a topic discussed in Chapter 7 of the notes). Specifically, the C condition code after a LOADS will be true if any byte in the result is all zero.

    To simplify this problem, let's imagine for the moment that the Hawk has a 12 bit word with bits B11 (the most significant bit) through B0 (the least significant bit). Furthermore, assume that there are just 3 bits per byte, so byte zero consists of B0, B1 and B2, and byte three consists of B9, B10 and B11.

    a) Give a Boolean expression for the C condition code as a function of bits B0 to B11. (0.3 points)

    b) Draw out a schematic logic diagram equivalent to the above. Legibility is important here. If you can't draw a straight line, use a ruler. (0.3 points)

  4. Background: In C or Java, a programmer could write a=b^c to compute the exclusive or of two boolean variables (with values restricted to the range 0 to 1), but beginning programmers sometimes do this:
            if (b) a=!c; else a=c;
    

    a) Draw a neat and legible schematic logic diagram showing how to compute the exclusive-or of two variables using a 2-input multiplexor and a not-gate. The logic is exactly the same as the code above. (0.3 points)

    b) The Hawk has no instruction to compute the exclusive-or of two variables, analogous to the ^ operator in languages like C and Java. Instead, a two-instruction sequence is required to compute this. Give the sequence required to compute R3=R3^R4. (0.3 points)

  5. An equivalence circuit outputs true if both of its inputs are the same and false if they are different.

    a) (0.3 points) Give the truth table for an equivalence circuit with inputs a and b and output c. (0.3 points)

    b) Use the general methodology for converting any truth table to a logic circuit given in the middle of Chapter 8 of the notes to derive the logic circuit for equivalence from your truth table. (0.3 points)