In this lab, you will run a program that causes multiple exceptions. You will step through the exception handling code to better understand how it functions. You will then modify the code so that it no longer causes exceptions. Finally, you will run the original code that causes exceptions but modify the exception handling code to 'fix' the problems encountered and allow the code to run as intended.
Overview
This lab will cover exceptions and exception handling in SPIM. You are given a small program that causes several exceptions, along with a trap handler that is extensively documented to help you step through and understand how the exceptions are handled. Note that for this lab you MUST use the version of pcspim that is available for download from the Tools page of the course site here. Older versions of pcspim WILL NOT work with the necessary trap handler. Once you are comfortable with the control flow and instruction execution that occurs for exceptions, you will modify the program so that it no longer throws exceptions. That modified program will be the first of two pieces of code that you submit. The next step will be to use the original program (which causes the exceptions) but to modify the trap handler so that it can handle the exceptions as specified below. This modified trap handler will be the second of two pieces of code that you submit.
Download the following files:
Part 1: program_with_exceptions.s program under spim
The program should generate six Bad Data/Stack Address Exceptions (Exception 7) because the program assumes that the data segment starts at 0 and spim assumes that it starts at 0x10000000. You
should see the output from the trap handler specifying the
exceptions in spim's 'Console' window.
program_with_exceptions.s
program again using spim and this time single step through
at least two exceptions. Make sure you see how the flow of
control is changed by looking at the source code and note where
the exceptions occur.
[HINT: You will want to use the ' la' instruction.]
Part 2:
program_with_exceptions.s
program again. The program should run the same way it did before, causing exceptions.
When you run the program you should only get two Exception 7 occurrences at the instructions:
lw $t4, 84($t1) #Constant 4 stored in $t4
....
sw $t3, 0($t1) #sum is stored
Your program should handle these exceptions so that the correct
calculation is performed and a 36 is printed at the end.
program_with_exceptions.s, you have completed the last portion of this
lab.
To turn in your solutions to this lab, you must email the TA, Matt, at mpatitz@cs.iastate.edu with "ComS 321, Lab5" as your subject line and with BOTH parts of the code: 1. The modified program_without_exceptions.s which runs correctly with the original commented_trap.handler and causes no exceptions. 2. The modified commented_trap.handler which handles the bad data reference exceptions in program_with_exceptions.s as specified above. Paste the contents of both files into the email and make sure they are clearly separated from each other.
In this lab you learned how spim's trap handler works by stepping through the handling of exceptions. You then modified a piece of code to prevent exceptions, as well as modifying spim's trap handler to handle a particular exception in a customized manner. The resulting trap handler would not be a general purpose trap handler, but instead served to teach you about the basics of how exceptions can be handled. You should now be comfortable with spim's mechanism for catching and handling exceptions. |