Computer Sciences Dept.

CS/ECE 354 Machine Organization and Programming

Fall 2008 Section 1
Instructor Mark D. Hill
TAs Mark Liu & Somayeh Sardashti

Assignment 6 // Due Friday, December 5, before 5pm

Send e-mail questions to Mark Liu, mliu@cs.wisc.edu

This program is intended to provide understanding in the areas of interrupts and exception handling. Do this program in fixed steps. Each step builds on the previous step, and each step will be turned in.

STEP 1

For this step you will simply create a file named coprimeA.s that will perform exactly the tasks of assignment 4. In other words, do you do not need to write new code for this part if you do not want to! For reference, here is what your program is expected to do.

This MAL program requests, and reads in a user-entered integer. For this program, the integer is not restricted to exactly 1 digit. Instead the program reads all characters until it encounters the first newline character. The program then uses the integer to print out the set of output lines for whether or not that integer is coprime with the integers in the range 2-9. No array is used for the results. Any positive integer greater than 1 is accepted by the program.

Here are several examples of program execution. User input is shown in bold to distinguish it from program output.

Enter an integer: 25
25 and 2 coprime? Y
25 and 3 coprime? Y
25 and 4 coprime? Y
25 and 5 coprime? N
25 and 6 coprime? Y
25 and 7 coprime? Y
25 and 8 coprime? Y
25 and 9 coprime? Y

Here is another example.

Enter an integer: 200
200 and 2 coprime? N
200 and 3 coprime? Y
200 and 4 coprime? N
200 and 5 coprime? N
200 and 6 coprime? N
200 and 7 coprime? Y
200 and 8 coprime? N
200 and 9 coprime? Y

Here are several examples that show what the program does under unusual or erroneous user input. The difficulty is given in bold as a header.

User wants to enter a negative number, and starts with a '-' (dash) character.

 
Enter an integer: -96 
Bad user input.  Quitting. 

User enters an integer that is less than 2.

 
Enter an integer: 1 
Bad user input.  Quitting. 

The user enters a valid integer, but again it is less than 2.

 
Enter an integer: 0000000 
Bad user input.  Quitting. 

User enters a bad character as part of the requested integer.

 
Enter an integer: 3x7 
Bad user input.  Quitting. 

Again, the user enters a bad character as part of the requested integer.

 
Enter an integer: 218h 
Bad user input.  Quitting. 

Again, the user enters a bad character (a space) as part of the requested integer.

 
Enter an integer: 2 36 
Bad user input.  Quitting. 
Note:
  • The program only outputs once the user has hit the enter key. This goes for error cases as well.
  • Follow the 354 conventions for register usage and parameter passing for any and all functions in your code.

STEP 2

Copy the application from STEP 1 to a separate file called coprimeB.s. For the remainder of this assignment specification, the application is referred to as the user-level program. Put all STEP 2 modifications into coprimeB.s. To make the program run correctly, these modifications are not necessary, as the assembler within the simulator would do them for us. However, these modifications emphasize how exception handling works.

For the I/O instructions getc, putc, and puts within the user-level program, substitute the MAL instructions (as given in the lecture notes on Assembly). Your resulting program will not have the instructions getc, putc, or puts, but will instead use syscall. The syscall function number (which goes in register $2, or $v0, before syscall) is also given in the lecture notes on Assembly.

Just as for STEP 1, test this program with sim354. Runs of the program will appear exactly as they did for STEP 1.

STEP 3

Put the user-level program (coprimeB.s) together with an interrupt-driven kernel. The interrupt-driven kernel is provided for you in the file
/p/course/cs354-common/public/bin/interrupt.kernel
Copy this kernel file (to your own directory). Put the user-level program (coprimeB.s) together in the same file with the interrupt-driven kernel. The kernel goes first within the file. Call this new file (that has both kernel and user-level program together) coprimeC.s. Check that this code (in coprimeC.s) works using sim354, but follow the directions in the simulator guide for Invocation of simulator (kernel plus MIPS assembly language program). It should work without modification. And, runs of the program will appear exactly as they did for STEP 1.

STEP 4

Modify the user-level program and the kernel.

The user-level program is modified in one way:

  • It times how long the user takes entering the line of input. This information is then printed out.

    STEP 4 sample run 1

    Enter an integer: 200
    200 and 2 coprime? N
    200 and 3 coprime? Y
    200 and 4 coprime? N
    200 and 5 coprime? N
    200 and 6 coprime? N
    200 and 7 coprime? Y
    200 and 8 coprime? N
    200 and 9 coprime? Y
    Time to enter the line of input, in seconds: 8
    

    The user-level program needs access to timing information to know how much time has elapsed between the time the program started running until the user enters the enter key. Fortunately for us, the simulator includes one more I/O device that we call the clock. This I/O device sends regular interrupts at the rate of one per second.

    For STEP 3, you have a working interrupt-driven kernel that already handles the I/O syscalls putc, getc, and puts, as well interrupts from the keyboard and the display. It is missing all code that handles clock interrupts. You must write the code within the kernel to handle clock interrupts. The clock is handled like any other I/O device. The memory mapped I/O location ClockStatus already exists, and it works the same way as all the other device statuses work. Your kernel implementation uses the clock interrupts to generate a representation for how much time has passed (since the simulator started running the program). This is a simplified version of system time.

    And, since the user-level program needs access to timing information, utilize the generality of the syscall instruction to add a new function for syscall. This new type of syscall is to return (in $v0) the elapsed time (in seconds) since the the program began running. Use the value 15 in register $2 ($v0) as a function number for this new syscall.

    Requirements

    1. Your program must follow style guidelines as given in Style Guidelines.

      Also include a comment at the top of the kernel's source code with your name (and your partner's name, if working in a pair).

    2. Your kernel must not miss clock interrupts.
    3. Identify where you have added code to the kernel by placing the exact comments:
      #################################
      # ADDED KERNEL CODE

      before the code you add, and the comments
      # END OF ADDED KERNEL CODE
      #################################

      after the code you add. This will make the job of grading easier.
    4. Organize your program such that there is only one exit point (the done instruction) in the user-level program.
    5. Your program is to operate and appear the same as the examples given above.
    6. For all functions and procedures, follow all parameter passing and register usage conventions as described in MIPS register usage.

    Notes

    Step 4 of this assignment is the only part that contains any challenge. For the modifications in Step 4, we suggest that you use the following ordered steps, to try to reduce the amount of time it will take to get a completed assignment. Test each step before continuing.

    1. Modify the kernel to handle clock interrupts. When testing this, you will not notice any change in your application.
    2. Add the kernel code that handles syscall 15 requests. Again when testing this, you will not notice any change in your application, as you will not have any syscalls that ask what the current time is. You will be using syscall 15 right before and right after your call to get_integer.
    3. Modify your user-level program to time how long it takes the user to enter the integer, and to print out the statistic using print_integer.

    Collaboration Policy

    For this assignment, you may work in pairs (2 people). All students (whether working in a pair or not) must individually turn in the assignment by individually running the handin program. Therefore, 2 copies of the assignment will be turned in for those working as a pair. The grader will choose to grade only one copy of a pair's work, and assign the same score to both students.

    If working in a pair, the names of BOTH students must appear at the top of the turned in assignment.


    Handing In the Program

    Your three files named coprimeA.s, coprimeB.s, and coprimeC.s, will be turned in. Turn these in by running the lab-supported handin program.

    Use the following command to run the handin program:
    
      handin -c cs354-1 -a a6 -d .
    
    
    while your current working directory is the one containing the program source code files.

    Grading will be based only on coprimeC.s, unless it does not exist, or does not work at all. If such is the case, partial credit (but not much!) will be given based on coprimeA.s or coprimeB.s. Most of the point allocation for this program will be devoted to aspects of kernel operation.

  •  
    Computer Sciences | UW Home