Thur, 1st Oct 2015, 11:30 Re: Problem Set 3 EE306

```

A student writes:

> Hello Dr. Patt,
> I am a student in your 306 class and I was working on questions 12 and 13
> of problem set 3 when I encountered the 1111 opcode for the TRAP function.
> A TA informed me that it was the halt operation and I thought it would be a
> good idea to bring it up with you since it was not covered in this week's
> lecture.
>
> <<name withheld to protect the student who did not see 1111 in class>

You are absolutely right!  I did not get to it in class.  I ran out of time
before I could get to it.  I will talk about it on Monday.  Meanwhile, I will
try to explain it here so you can use it in the problem set.

The opcode 1111 is the TRAP instruction.  I sometimes call it the OSH
instruction, where OSH stands for: Operating System, Help!

What do I mean by that?  Answer: There are a lot of things that computers can
do that most programmers do not understand things well enough to direct the
computer to do them.  Input and output, for example, is really understood by
very few programmers.  So, most ISAs have an instruction that the programmer
can use to get the computer to do things the programmer can not do for
him/herself.  One company calls this instruction the SWI instruction.
I call it the TRAP instruction.

The TRAP instruction is, like all instructions in the LC-3, 16 bits wide.
Bits[15:12] specify the opcode 1111.  Bits[11:8] are 0000.  Bits[7:0] contain
an 8-bit
code which is the message the programmer conveys to the hardware to tell the
hardware what work the programmer wants done on his/her behalf.

The specific question you asked relates to one of the things the programmer
needs the computer to do that he/she can not do for him/herself: stop the
computer.  The programmer uses the code x25 to tell the computer to stop the
computer.

So, after the computer has carried out all the work specified by the
programmer's program, and the programmer is ready to stop the computer,
the programmer specifies the instruction: 1111 0000 0010 0101.  In executing
this one instruction, the computer is able to figure out what the programmer
wants done and can proceed to do it.  How this actually works you will learn
in a few weeks, but for now it is enough to know that if the programmer needs
help from the computer or operating system, he/she inserts the instruction
(with opcode 1111) into the program where help is needed, and specifies the
specific 8-bit code in Bits[7:0] to indicate the precise nature of the help
needed.

OK?

Good luck finishing the problem set and doing well on the exam.

Yale Patt

```