Writing Trap Handlers

Reference: Computer Systems, Chapter 8, Section 8.2.

A trap instruction executes as if it were a single machine language instruction wired into the instruction set of the CPU. However, it really executes a sequence of machine language instructions that are initiated by the hardware trap mechanism. The Pep/8 operating system provides one nonunary trap instruction, NOP and four unary trap instructions, NOP0, NOP1, NOP2, and NOP3, so you can reprogram them to implement instructions of your own choosing.

Topics: Trap handlers, The .BURN pseudo-op.

Trap handlers

To modify the operating system for the problems in Chapter 8 of the text is a six-step process.

Step 1.

Decide on your mnemonic for your new instruction. It will replace one of NOP0, NOP1, NOP2, NOP3, NOP, DECI, DECO, or STRO. Select the menu option System->Redefine Mnemonics to change the mnemonics of one of the instructions. The dialog box requires you to enter a mnemonic and its allowed addressing modes if it is nonunary. For example, change the mnemonic for the unary instruction NOP0 to ECHO.

redefinemnemonics

Step 2.

In this Help system in the pane on the left, select Pep/8 Operating System, and then click the Copy to Source button. The default operating system will be copied to the Source Code pane.

pep8oshelpsystem

Step 3.

Modify the trap handler part of the operating system to implement your new instruction. As an example, here is the original NOP0 trap handler.

nop0

And here is how you would modify it to implement the new ECHO instruction in place of NOP0.

echo

CAUTION: You cannot use any trap instructions in your trap handler.

Step 4.

Select System->Assemble/Install New OS to assemble and install the reprogrammed operating system.

assembleinstallnewos

You can save your modified operating system as a .pep file as you would any other Pep/8 assembly language program.

Step 5.

Write an assembly language program to test your new instruction with the new mnemonic. The assembler should recognize the new mnemonic and generate the appropriate object code. For example, your test program might be the following.

echoprogram

Step 6.

Load and execute your program assembled in step 5. In this example, whatever character is placed in the Input pane should be echoed in the output pane.

pecho

Scroll to topics.

The .BURN pseudo-op

When you include .BURN in a program, the assembler assumes that the program will be burned into read-only memory (ROM). It generates code for those instrctions that follow the burn directive, but not for those that precede it. The assembler also assumes that the ROM will be installed at the bottom of memory, leaving the top of memory for the application programs. It therefore calculates tha addresses for the symbol table such that the last byte generated will have the address specified by the burn directive.

Pep/8 is a 16-bit computer, and can therfore access 216 = 64KB = 65,536 bytes of main memory. The Pep/8 operating system contains .BURN 0xFFFF because 0xFFFF is the address of the 65,536th byte.

It is possible to install a smaller amount of memory in the Pep/8 system. Simply change the burn directive in the operating system to a smaller value. For example, you can change the burn directive to .BURN 0x7FFF, assemble and install the new OS, and the system will install only 32KB of memory instead of 64KB.

modifieddotburn

The trap handlers all run correctly, which you can trace in the Memory Dump pane.

relocatedos

Scroll to topics.