12/07/2006
A student writes: Dr Patt, In using a TRAP instruction, we (the coders) specify the TRAP vector to execute the functions we wish to perform. So when we write TRAP x20 we're telling the LC-3 exactly what we want it to do (namely, look in the entry x20 of the Trap Vector Table, that is your starting address). All true, but just to be sure you are not being misled: The user does not write the trap service routine, it is part of the o/s. So, while it is true we (the coders) are specifying the TRAP vector, we are not devising the routine, but rather we are selecting a routine from a collection of routines that are available to us. If you are programming in Java or C++, etc. that is all hidden from you. The compiler knows what each of these trap service routines do and inserts TRAP instructions with the necessary trap vectors where appropriate. In your lecture the other day, you mentioned that the difference is that when using an interrupt, the device that is interrupting our code PROVIDES this location in the Interrupt Vector Table, we, as the code writer, do not. Also true. In this case, the I/O device wants to interrupt your program, so the device supplies the interrupt vector corresponding to the routine that the device wants carried out in its behalf. The Interrupt Device (in PA5) is providing the address x0180 to look for the starting address of our specific interrupt service routine. Am I correct so far? Yes. Assuming I'm correct, now when writing my program, in the initialization of the program, I need to actually store the memory location of the starting instruction of my interrupt service routine (x2000) into memory location x0180. Which is something that if we were running an O/S on the LC-3 would be done for me. Is this correct? Right again. So, again, assuming I'm correct, the interrupt device (Keyboard) would say "HEY! INTERRUPT! Look at memory location x0180 for where to go next." I could not say it better myself! You want to teach 306 next semester? OR Does the interrupt device (Keyboard) say "HEY! INTERRUPT! Look at memory location x0100 (start of the Interrupt Vector Table) and then increment to x0180." Actually, the real truth is the interrupt device supplies x80 and the LC-3 hardware sticks a 1 in front of it since the hardware knows the interrupt vector table starts at x100. Since you are doing so great, I will even add an embellishment (shame on me) that you do NOT need to know for 306: In most modern machines the interrupt vector table can be anywhere in memory, so rather than it starting at x0100, there is another register (called the Interrupt Vector Table Base Register) which contains the starting address of the interrupt vector table. In such cases (almost all, today), the hardware will add the interrupt vector (for example x80) to the contents of the IVTB Register to get the address of the location in the interrupt vector table containing the starting address of the interrupt service routine. I think I am a little confused as to whether I need to do anything with the given information in the statement of the programming assignment about the start of the Interrupt Vector Table being at x0100 or if I can just simply store x2000 into x0180. You can simply store x2000 at x0180. Thanks for your help! My pleasure. Yale Patt <<name withheld to protect the student who thinks incorrectly that he is confused>>