Assignment 6, due Mar 11

Part of the homework for 22C:60, Spring 2005
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, and unless there is what insurance companies call "an act of God" - something outside your control; the only exceptions to this rule will be by advance arrangement.

  1. From chapter 7 of the notes, do problems c (0.3 points), h and o (0.6 points each).

  2. From chapter 8 of the notes, do problems c, g, h (0.3 points each), and i (0.6 points).

Machine problem 2, Due March 25

Write a Hawk strncpy subroutine that copies word-by-word if the strings are aligned identically, halfword by halfword if their alignment is off by one byte, and only copies byte by byte if they are aligned identically. This is the combined versions of q and r from Chapter 7.

The details of the test program for this are as follows: The test program must copy strings from each possible alignment in a word to each possible alignment in a word (there are 4 possible source alignments and 4 possible destination alignments), and it must copy strings of many different lengths (4 relevant alignments of the final byte copied). This means testing 64 cases, so obviously, we want an algorithm to generate them! Then, of course, the result needs to make sense!

To solve this problem, we will copy successively shorter snips of one original string back and forth between buffers, using the following logic:

char srcbuf[80] = "abcdefghijklmnopqrstuvwxyz"
                  "0123456789<>[]"
                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                  "0123456789<>[";
char dstbuf[80];

int main() {
        char * src;
        char * dst;
        int  len, i, j, k;

        len = 80;
        src = srcbuf;
        dst = dstbuf;
        for (i = 0; i < 4; i++) {
                for (j = 0; j < 4; j++) {
                        for (k = 0; k < 4; k++) {
                                strncpy( dst, src, len );
                                dspstr( dst );
                                dst = dst + 1;
                                len = len - 1;
                        }
                        src = src + 1;
                }
                len = len - 1;
        }
}

See mp2test.txt a translation of this test program into Hawk code. Running this in an 80x55 text window lets you see the entire output.