Assignment 7, due Oct. 16

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

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

Problems

  1. Background: If you write a file of 32-bit words on a machine that is a highbyter and then read it on a lowbyter machine, you'll get each 32-bit word with the bytes in the wrong order. If you wrote out the word 0123456716 you'd read it back as 6745230116. Note that the order of the bits in each byte is not changed.

    A problem: Write a Hawk subroutine that takes R3 as a pointer to a memory location and reverses the order of the bytes in that location. Your code should follow all of the usual Hawk calling conventions and it should be well documented. (1 point)

  2. Background: Consider a null-terminated linked list of strings. Each object in the list contains a pointer to the next object (creatively named NEXT) and a pointer to the text of the string (TEXT). Initially, assume that R3 points to the first object in the list.

    A problem: Write a Hawk program fragment equivalent to the following C-ish code to traverse the list and print the first character of each string in the list, except where the pointer to the string is null and except when the string is of length zero. (1 point)

            while (R3 != NULL) {
                   char * T = (*R3).TEXT;
                   if (T != NULL) {
                          char CH = *T;
                          if (CH != NUL) dspch(CH);
                   }
                   R3 = (*R3).NEXT;
            }
    

    Note: In C, the declaration char * p declares p to be a pointer to a character. The expression *p, in this context, is the character pointed to by p. The notation o.f refers to field f of object o.

  3. Background: Consider this digital logic function, with inputs a and b, and output c.

    x = not( a and b)
    y = not( a and x)
    z = not( x and b)
    c = not( y and z)

    a) Make a truth table showing x, y z, and c as a function of a and b. (0.5 points)

    b) What logic function is this? (0.5 points)