CS61C
Spring 2005
Lab 5

Goals

This lab gives you more practice with using the assembly language equivalent of C arrays and pointers, in particular with the technique of writing table-driven code. (This is like data-directed programming in CS 61A.) It also introduces you to characteristics of numerical representations at the machine level.

Reading

P&H Sections on MIPS and Procedures
You should familiarize yourself with the code provided for this assignment in order to make most productive use of lab time.

Exercise 1

Background

An instruction on the IBM 360, which we'll call scan, worked as follows. Given the address of the start of a string and the address of a 256-byte table of values, it essentially implemented the following C code:

	char *sptr;
	char table[256];
	for (sptr = address of start of the string; table[*sptr] == 0; sptr++) {
	}

That is, it scans the string looking for the first character whose corresponding table entry is nonzero.

The file ~cs61c/labs/lab05/lab5.s contains the framework of a program to skip past white space in a string; for exercise 1, you complete this program. Test your solution code with the following input lines:

Part (a)

At the location in the program labeled by table, provide a table of bytes with the following contents.

ASCII tables are available online (search for "ascii table" at Google).

A useful abbreviation allowed by spim in the .byte directive is the notation value:count, which initializes the next count bytes with the given value. For example, the directive .byte 0:39 initializes the next 39 bytes with 0.

Part (b)

Supply the code that implements the scan instruction. Your code should be given the string address in register $s1 and the table address in register $s2; it should branch to the label scan_done when it finds a character in the string whose corresponding table value is nonzero, leaving the address of that character in $s1 and the corresponding table value in $s0.

Exercise 2

Verify that C ignores integer overflow in two ways:

Exercise 3

Invent an exam question based on this lab assignment that would test a student's understanding of the code from exercise 1.