A student is confused as to what is part of the LC-3 and what is part of
the operating system (the o/s).  Since we have been using trap service
routines for some time now, and he has single stepped through them, he
thought somehow they were part of the LC-3.  NO!  They are part of the
O/S.  The LC-3 is the bare machine that executes the instructions in your
program.  The O/S provides service routines and the entries in the trap vector
and interrupt vector tables to tell the LC-3 where to find them.

The following dialog may be useful to you.  WARNING: It is looooong. 
If it is not clear, bring it to the attention of the TA, or ask me again.

        Dr Patt,

        As I sit here reviewing material for the final and working on the last
        program, I've become confused on the use of the term "operating 
        system." I know that when I use a trap instruction, its like saying 
        (in your words) "Operating system, help me!" implying that the 
        operating system (In my case, it is Windows XP) of the computer is 
        doing the work for us. 

Good.  Yes.

        But we know that
        TRAP x23 or any other trap instruction sends the PC to the location
        designated by x23 in the trap vector table. If you scroll through 
        the LC-3 simulator, you can see the different service routines. 

Sure.  AND, those service routines (as well as the ADDRESSES that are in
the trap vector table entries) are all part of the operating system.

        The confusion comes from the discussion of the interrupt service 
        routines, where it has been said that "we have not installed 
        Windows or Linux on the LC-3." Okay, I understand that much. 
        Now we have to write the interrupt routine to do the job of the 
        operating system, because we can't use trap
        routines. But wait! Aren't those trap service routines part 
        of the LC-3, and not the operating system? 

No, the trap service routines are part of the operating system.

        Surely, just as Bill Gates is unlikely to release
        Windows for the LC-3 anytime soon, Windows doesn't come equipped with
        service routines for the LC-3. 

If Bill Gates released Windows for the LC-3, it would come with trap 
service routines written in LC-3 code for use with the LC-3.

        The routines corresponding to the various
        trap instructions are coded into the LC-3 simulator, 
        apart from Windows, aren't they?

No, the trap routines are procedures running on the LC-3 simulator.

        The more I think about this, the more I confuse myself. In fact, 
        I am far
        more confused at the end of this email than I was when I started. To
        summarize, what exactly is meant by "operating system"? When I hear that
        term I generally think of Windows, Linux, etc, which is the software 
        that enables the average user to interact with their computer hardware. 

Yes.  And interrupt routines and trap routines both help the user interact
with the computer hardware.

        If the
        LC-3 is designed to represent the hardware of a computer, without an
        operating system, how do trap instructions actually work? 

Actually, every computer can operate without an operating system.  Except,
it would be a very painful way to go.  The user would have to write all the
code.  As soon as some of that code was in the form of service routines, we
have the beginnings of an o/s in our hands.

        Do other ISAs such
        as the x86 have trap routines, or is the trap an instruction for the 
        LC-3 that is meant as a teaching tool only?

Other ISAs have the equivalent of the LC-3 TRAP instruction, and all operating
systems take advantage of that equivalent mechanism to direct the user program
to an o/s service routine.

        Any sort of explanation would be greatly appreciated.

        <<name withheld to protect the student causing this very long response>>

OKay, now from the top:

The LC-3:

1. The LC-3 is an ISA.  It is mostly defined by the instruction set in
the inside cover of the book, but also includes stuff like the size of
memory, memory addressibility, memory-mapped I/O addresses.  With respect
to interrupts, it contains the interrupt vector associated with each event
that can interrupt the machine.  The LC-3 contains NO programs.  It is like 
a car without gasoline, so to speak.  ...or perhaps better, without a driver.

2. The TRAP instruction executes by loading the starting address of the
corresponding trap service routine into the PC.

3. Interrupts are initiated by loading the starting address of the 
corresponding interrupt service routine into the PC.

The O/S:

1.  The LC-3 provides an EMPTY trap vector table to the o/s.  The o/s 
identifies what trap vector corresponds to what service routine, and loads 
the starting address of the service routine into the trapvector table entry 
and loads the service routine into memory starting at that address.

2. In the same way, the LC-3 provides an EMPTY interrupt vector table to the 
o/s.  The o/s determines what code should be executed in behalf of each
interrupting event, and loads the starting address of the service routine that
will execute that code into the interrupt vector table entry. ...and loads 
the interrupt service routine into memory starting at that address.
So, the LC-3 is the bare machine.  The o/s fills up the trap and 
interrupt vector tables with starting addresses, and loads the corresponding
service routines into their proper locations.  

The fact that there ARE interrupt and trap vector tables is part of the LC-3.
The CONTENTS of these tables are part of the O/S.  All the service routines
are part of the O/S.

Since we do not have a full blown O/S in EE 306, what I have done is written
some of the O/S code so you could have the O/S do certain things for you.
These are the trap routines for TRAP x20, x21, x22, x23, x25.

In the final programming assignment, I wanted you to have some feel for how
interrupts work.  I could have written the keyboard interrupt service routine
for you, and I could have installed it in the simulator, and stored its 
starting address into x0180.  I decided to let you have the fun of doing that 

I hope this is better.  If not, and you still have questions, please ask again
or see one of the TAs.

Yale Patt