Department of Electrical and Computer Engineering

The University of Texas at Austin

EE 306, Fall 2017
Programming Assignment 5
Due: December 11th, 16:59 pm
Yale N. Patt, Instructor
TAs:Stephen Pruett, Siavash Zangeneh, Aniket Deshmukh, Zachary Susskind, Meiling Tang, Jiahan Liu

You must do every programming assignment by yourself. You are permitted to get help ONLY from the TAs and Dr. Patt. When you have completed the program, and tested it sufficiently so that you are comfortable that it works on any input, submit it for grading according to the submission instructions at the end of this handout.

The purpose of this assignment is to show how interrupt-driven Input/Output can interrupt a program that is running, execute the interrupt service routine, and return to the interrupted program, picking up exactly where it left off (just as if nothing had happened). In this assignment, we will use the Keyboard as the input device for interrupting the running program.

The assignment consists of three parts:


The user program.

Your user program will consist of continually printing "Input a capital letter from the English alphabet:" on the display, ending each line with a newline character (ASCII code x000A).

Example output:

Input a capital letter from the English alphabet:
Input a capital letter from the English alphabet:
Input a capital letter from the English alphabet:
Input a capital letter from the English alphabet:
Input a capital letter from the English alphabet:
To ensure the output on the screen is not too fast to be seen by the naked eye, the user program should include a piece of code that will count down from 40000 each time a line is output on the screen. A simple way to do this is with the following subroutine DELAY:

 
DELAY   ST  R1, SaveR1
        LD  R1, COUNT
REP     ADD R1,R1,#-1
        BRnp REP
        LD  R1, SaveR1
        RET
COUNT   .FILL #40000
SaveR1  .BLKW 1
Feel free to change the number 40000 to speed up or slow down outputting the prompt.


The keyboard interrupt service routine.

The keyboard interrupt service routine will examine the key typed to see if it is a capital letter in the English alphabet.

If the character typed is NOT a capital letter, the interrupt service routine will, starting on a new line on the screen, print "<the input character> is not a capital letter in the English alphabet.". For example, if the input key is '#', interrupt service routine will print

# is not a capital letter in the English alphabet.
If the character typed IS a capital letter, the interrupt service routine will, starting on a new line on the screen, print "The lower case character of <the input character> is: <the lower case of the input>". For example, if the input key is 'G', interrupt service routine will print
The lower case character of G is g.
The service routine would then print a line feed (x0A) to the screen, and finally terminate with an RTI.

Your interrupt service routine should start at the location x1500.

VERY IMPORTANT instructions for constructing your interrupt service routine:

  1. You may not use any TRAP instructions in your interrupt service routine. (However, you may use TRAP instructions as you wish in your user program.)
  2. To display a character on the screen, you must poll the DSR before writing to the DDR.
If you use TRAP in the interrupt service routine, or if you do not properly poll the DSR before writing to the DDR, your program is not correct and will fail our tests, even though it may appear to work when you test it.

Hint: Don't forget to save and restore any registers that you use in the interrupt service routine.


The operating system enabling code.

Unfortunately, we have not YET installed Windows or Linux on the LC-3, so we are going to have to ask you to do the following three enabling actions in your user program first, before your user program starts outputing the prompts. Normally, these would be done by the operating system before your user program starts executing.

1. Normally, the operating system would have previously set up some stack space so that the PC and PSR can be pushed when an interrupt is encountered. (As you know, when the service routine executes RTI, both PC and PSR will be popped, returning the machine to the interrupted program.) Since there is no operating system, please initialize R6 to x3000, indicating an empty stack.

2. Also, normally, the operating system establishes the interrupt vector table to contain the starting addresses of the corresponding interrupt service routines. You will have to do that for the keyboard interrupt. The starting address of the interrupt vector table is x0100 and the interrupt vector for the keyboard is x80. It is necessary for you to only provide the one entry in the interrupt vector table that is needed for this programming lab assignment.

3. Finally, normally, the operating system would set the IE bit of the KBSR. You will have to do that as well.


Your job.

Your job is to do three things:

  1. Write the user program described above.
  2. Write the keyboard interrupt service routine described above.
  3. Write the code necessary to perform the three tasks described above (because we do not have an operating system installed) to enable interrupts to be handled, and insert that code at the front of your user program.

The user program must be named user_program.asm and will be of the form:

                .ORIG    x3000
                  --      ---     ; initialize the stack pointer
                     ...
                  --      ---
                  --      ---     ; set up the keyboard interrupt vector table entry
                     ...
                  --      ---
                  --      ---     ; enable keyboard interrupts
                     ...
                  --      ---     
                  --      ---     ; start of actual user program to continuously print the prompt
                     ...
                  --      ---
                .END
The interrupt service routine must be named interrupt_service_routine.asm and will be of the form:

                .ORIG     x1500
                  --     ---      ; the code
                     ...
                  --     ---
                 RTI
                  --     ---      ; buffer space as required
                      ...
                  --     ---
                .END	  

We have provided a screenshot as an example of how the console should look when you run the program.

Notes: