Department of Electrical Engineering and Computer Science
EECS
61C, Summer 2004
Lab 7-1: I/O with Polling
This assignment is intended to familiarize you with how low-level input and output work on the MIPS architecture.
When running spim or xspim for these exercises, you must use the shell command
[x]spim -memio -quiet
which will enable memory mapped I/O and tell SPIM not to print a message when an exception occurs.
SPIM simulates the terminals reading and writing by running a certain unspecified number of MIPS instructions after the terminal receives a command, before setting the terminal back to ready.
Exercise 1: Writing to the terminal
The file ~cs61c/labs/lab7-1/buggy.print.s contains an incorrect version of a character output handler corresponding to C's putchar function. The problem is that it fails to check whether the terminal is ready to accept a character before it sends the character to the terminal. Notice that even though there is a loop which runs 512 times, to wait for the terminal to finish, this loop is not long enough, and characters are still being dropped.
Determine approximately how many MIPS instructions are executed before the
terminal finishes writing a character in the SPIM simulator.
Then, fix the code by replacing the loop with another loop that is based not
on number of instructions, but instead will terminate only when the ready bit
of the terminal is on; ie, write a loop that will poll the terminal until it is
ready. Make sure that the string is now displayed correctly.
Checkoff: Tell your TA approximately how many MIPS instructions are run before
the terminal finishes writing a character, and demonstrate to your TA the
working print.s program.
Exercise 2: Reading from the terminal
The file ~cs61c/labs/lab7-1/echo.s contains three parts:
Your task is to fill in the getchar procedure to poll the receiver
terminal until a character is available, and return it in $v0.
Then, copy your print code from part 1 of the lab. Test your
program in SPIM and verify that it displays the characters you press.
Experiment with various chacters to see what gets printed. To quit the program,
press Control-C.
Technical note: Since UNIX buffers up input before sending it to
programs, you may not see output until you have pressed several characters, and
some of them may be dropped by SPIM. To avoid this problem, make sure you run
the command:
stty min 1
before testing part 2.
Checkoff: Show your TA the working echo.s program.