10/21/04

A student writes about some weird behavior after his program executes if he does not set a breakpoint at the address of the TRAP x25 instruction.

First, you all should be sure to set a breakpoint at the address of the TRAP x25 instruction before running your program. Hopefully the reason will be clear at the end of this message.

The student writes:

     Well, my program works.

     That is, it works if I set the breakpoint on top of the trap
     instruction.  If I let it go through to my .fills (none of which
     are a jmp or br instruction), it strangely jumps to another
     location in the memory (xFD27 or so) and stops there.  Is this
     acceptable?

     << name withheld to protect the positively inquisitive >>

Actually, your email points out a couple of highlights that I was saving for later, but heck, you are ready for them now.

First, you are quite right that if you set a breakpoint at the address of the TRAP x25 instruction, the computer will stop just before executing the TRAP instruction. Thus, everything is fine. That is because at that point you have executed everything you were supposed to and are now ready to halt.

However, if you do not set the breakpoint there, what happens? Nope, the computer does not work its way through the .FILL garbage. What happens is the computer executes 1111000000100101 (i.e., TRAP x25) which you recall is a request that the operating system stop the computer. The program (or, rather, what we call the service routine) executes. This service routine

     (a) saves some of the registers (the reason for this will have to
      wait a couple of weeks),

     (b) prints a message on the screen (Halting the machine.), and then

     (c) sets to 0 the bit that is ANDed with the crystal oscillator that
         is producing the clock signal (as discussed in Section 4.5).

The instruction that actually sets that bit to 0 is stored in location xFD78. Since the PC was incremented during the FETCH phase of that instruction, the machine stops with PC = xFD79.

Since the TRAP x25 service routine clobbers some of the registers that you are using in your program, you should set the breakpoint to the address of the TRAP x25 instructon, so the program will stop before executing that TRAP instruction. This will allow you to examine registers, etc. to test whether your program executed correctly.

Yale Patt