Sun, 6th Dec 2015, 16:40 TRAP instruction and trap routine -- NOT the same thing



Several of my TAs have told me there is a misconception among several of you
regarding the TRAP instruction and a trap routine.  If you understand the
difference, then feel free to delete and move on.  But this is a very
important concept that you will see again and again in your courses, so I
want to be sure you do understand it.

A TRAP instruction is ONE instruction. You can count the number of clock cycles
it takes by looking at the State Machine.  I do not have the state machine
in front of me, and I have not memorized it, so I can not count the clock
cycles for you.  It is somethink 11 or 12 clock cycles.  By comparison, a LD
takes 15 cycles and ADD takes 9 cycles.  Those I happen to remember!

So, TRAP x22 takes 11 or 12 cycles.  TRAP x21 takes 11 or 12 cycles.

This should not be confused with a trap ROUTINE.  It takes as many cycles
as it needs to take to execute all the instructions in the routine.  Usually,
100 clock cycles or more.

Recall that the TRAP Instruction saves the return linkage and loads the PC
with the starting address of the trap Routine.  Since the PC contains the
starting address of the trap routine, the LC-3 starts executiong the routine
to carry out the work required by the user giving the specific trap vector.

So, even though the trap routine takes 100 cycles or more, it is still a small
number compared to the DELAY subroutine which is executing the loop thousands
of times.  That is why, incidentally, screen shot 2 shows up rarely.

OK?

Good luck with EE306 as you head down the home stretch.



Yale Patt