CSE 127: Lecture 10


The topics covered in this lecture are Sparc register windows (see discussion section notes), architecture vs implementation and when register spills occur; and assignment 1 discussion/hints. Here are some programs in which you might practice finding bugs (additional material promised from lec 9).

Assignment 1

You may use the program set_stack_offset in the course public directory (/home/solaris/ieng9/cs127w/public/assn1.tools) to fix the stack so that the stack always start at the same location. Use it by running assn1 by:
$ ../public/assn1.tools/set_stack_offset ../public/assn1
... lots of output ...
$
If you want to redirect input from a file to the program, do it via
$ ../public/assn1.tools/set_stack_offset ../public/assn1 < attack_data
You got it!
$
The assignment is now due at Feb 5, 2000, 2359 PST.

Finding Bugs

How many bugs lurk in these code fragments? What are preconditions that the programmers must satisfy?
void sort(int array[],
          int nelt)
{
	int i, j, t;

	for (i = 0; i < nelt; i++) for (j = 0; j < nelt; j++)
		if (array[j] > array[j+1]) {
			t = array[j];
			array[j] = array[j+1];
			array[j+1] = t;
		}
}
A more pointer oriented sort:
void sort(int array[],
          int nelt)
{
	int i, t, *ip, *ipend;

	ipend = array + nelt;
	for (i = 0; i < nelt; i++) {
		for (ip = array; ip < ipend; )
			if (*ip > *ip++) {
				t = *ip;
				*ip = ip[-1];
				ip[-1] = t;
			}
	}
}
A search algorithm:
struct record {
	int key;
	struct data *datap; /* ... */
}
struct record *find_rec(struct record *p, int nrec, int key)
{
	int mid = nrec/2;

	if (record[mid].key == key) return record+mid;
	if (record[mid].key < key)
		return find_rec(p,mid-1,key);
	return find_rec(p+mid+1,nrec-(mid+1),key);
}

[ search CSE | CSE | bsy's home page | links | webster | MRQE | google | yahoo | citeseer | certserver ]
picture of bsy

bsy+cse127w02@cs.ucsd.edu, last updated Mon Mar 25 15:22:08 PST 2002. Copyright 2002 Bennet Yee.
email bsy.


Don't make me hand over my privacy keys!