CS 61C Homework 8 1. How does an overflow exception differ from an interrupt? 2. Why must the exception handler be privileged code? 3. What would happen if the exception handler returned control to a user program without reenabling interrupts? 4. What could go wrong if the hardware didn't disable interrupts before running the exception handler? Would the problem happen often, or rarely? 5. This assignment concerns input/output registers; you must read section A.8 in Appendix A of P&H before you do it. Submit answers to these questions in hw8.txt. Before you begin the next part, copy the files ~cs61c/lib/print.s ~cs61c/lib/echo.s to your directory. You will modify those files to complete the assignment. WHEN RUNNING SPIM OR XSPIM FOR THIS ASSIGNMENT, YOU MUST USE THE SHELL COMMAND [x]spim -memio -quiet 5a. Write a procedure to output a string to the terminal. The file print.s contains a main program that initializes the stack, and the skeleton of a procedure PRINT. Your job is to fill in the body of PRINT. If it were written in C, PRINT would have the following declaration: void print(char *string); In other words, it takes a single argument, which is the address of a NULL-terminated ASCII string. PRINT should output the characters of the string onto the terminal one at a time, waiting for each character to be output before outputting the next one. It should not return until all the characters have been output. PRINT should work for strings of any length. This version of PRINT should not use interrupts; just test the "ready" bit of the transmitter control register over and over until the device is ready. The program is written to output a single-character string. Once you've gotten your program working with the one-character string, change the main program to pass STRING2 to PRINT instead of STRING1. Try several different strings to convince yourself that your solution works. Turn in a copy of print.s. Note: the PRINT procedure must obey the MIPS conventions for calling procedures and using the stack. 5b. Your job for this problem is to write a procedure that will input a character from the terminal. The file echo.s contains a skeleton for the program. You must write the procedure GETCHAR, which would have the following declaration if it were written in C (in fact, this procedure does exist in C, although the C version behaves a little differently from the version you'll write): char getchar(void); In other words, it takes no arguments and returns a character result. Input should wait until a character has been typed on the terminal. Then it return the character's value in $2 (the result register). As with the other problems in this assignment, you should not use interrupts. Just test the ready bit over and over until a character has arrived. The file echo.s contains a main program to help test your GETCHAR procedure. To use it, write GETCHAR and fill in the body of the PRINT procedure with the code you wrote for Problem 5a above. The main program will call GETCHAR, then create a string containing the single character, then call PRINT to "echo" the character back out to the terminal. It will repeat this loop over and over again. Once your code works you should be able to run the program, type characters, and see them echoed back on your terminal. Try typing various characters to see what they do. Notice that carriage return may only move the cursor back to the beginning of the line, and not advance to the next line. "Line feed" will advance to the next line without moving the cursor back to the beginning of the line. Typing control-C will interrupt your program and return to the SPIM prompt. Turn in a copy of echo.s. Note: your code must obey the MIPS conventions for calling procedures and using the stack.