| 1 | <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01//EN"> |
| 2 | |
| 3 | <html> |
| 4 | <head> |
| 5 | <title> Pep/8: Trap Handlers Documentation </title> |
| 6 | <style type="text/css" media="all"> |
| 7 | code { font-family:Courier, 'Courier New', monospace; font-size:11pt } |
| 8 | pre { font-family:Courier; font-size:11pt } |
| 9 | img { vertical-align:text-top; } |
| 10 | h4 { margin-bottom: 0; border-bottom-width: 0; padding-bottom: 0; } |
| 11 | </style> |
| 12 | </head> |
| 13 | <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#000033" alink="#0066FF"> |
| 14 | <table bgcolor="#FB9F14" width="100%" cellpadding="2" cellspacing="0" border="0"> |
| 15 | <tr><td> |
| 16 | <p style="text-align:center; font-family:helvetica, arial, sans-serif; font-size:14pt; font-weight:bold; color: #29315E"> |
| 17 | Writing Trap Handlers |
| 18 | </p> |
| 19 | </td></tr> |
| 20 | </table> |
| 21 | <p> |
| 22 | Reference: <i>Computer Systems</i>, Chapter 8, Section 8.2. |
| 23 | <p> |
| 24 | A trap instruction executes as if it were a single machine language instruction wired into the instruction set of the CPU. |
| 25 | However, it really executes a <i>sequence</i> of machine language instructions that are initiated by the hardware trap mechanism. |
| 26 | The Pep/8 operating system provides one nonunary trap instruction, <code>NOP</code> and four unary trap instructions, |
| 27 | <code>NOP0</code>, <code>NOP1</code>, <code>NOP2</code>, and <code>NOP3</code>, so you can reprogram them to implement |
| 28 | instructions of your own choosing. |
| 29 | <p> |
| 30 | <a name = "Topics">Topics:</a> |
| 31 | <a href="#Trap">Trap handlers</a>, |
| 32 | <a href="#BURN">The .BURN pseudo-op</a>. |
| 33 | |
| 34 | <h3><a name="Trap">Trap handlers</a></h3> |
| 35 | |
| 36 | To modify the operating system for the problems in Chapter 8 of the text is a six-step process. |
| 37 | <p> |
| 38 | <h4>Step 1.</h4> |
| 39 | Decide on your mnemonic for your new instruction. |
| 40 | It will replace one of <code>NOP0</code>, <code>NOP1</code>, <code>NOP2</code>, <code>NOP3</code>, |
| 41 | <code>NOP</code>, <code>DECI</code>, <code>DECO</code>, or <code>STRO</code>. |
| 42 | Select the menu option System->Redefine Mnemonics to change the mnemonics of one of the instructions. |
| 43 | The dialog box requires you to enter a mnemonic and its allowed addressing modes if it is nonunary. |
| 44 | For example, change the mnemonic for the unary instruction <code>NOP0</code> to <code>ECHO</code>. |
| 45 | <p> |
| 46 | <img src="qrc:/help/images/redefinemnemonics.png" alt="redefinemnemonics" hspace=10 vspace=10> |
| 47 | <p> |
| 48 | <h4>Step 2.</h4> |
| 49 | In this Help system in the pane on the left, select Pep/8 Operating System, and then click the Copy to Source button. |
| 50 | The default operating system will be copied to the Source Code pane. |
| 51 | <p> |
| 52 | <img src="qrc:/help/images/pep8oshelpsystem.png" alt="pep8oshelpsystem" hspace=10 vspace=10> |
| 53 | <p> |
| 54 | <h4>Step 3.</h4> |
| 55 | Modify the trap handler part of the operating system to implement your new instruction. |
| 56 | As an example, here is the original NOP0 trap handler. |
| 57 | <p> |
| 58 | <img src="qrc:/help/images/nop0.png" alt="nop0" hspace=10 vspace=10> |
| 59 | <p> |
| 60 | And here is how you would modify it to implement the new <code>ECHO</code> instruction in place of <code>NOP0</code>. |
| 61 | <p> |
| 62 | <img src="qrc:/help/images/echo.png" alt="echo" hspace=10 vspace=10> |
| 63 | <p> |
| 64 | CAUTION: You cannot use any trap instructions in your trap handler. |
| 65 | <p> |
| 66 | <h4>Step 4.</h4> |
| 67 | Select System->Assemble/Install New OS to assemble and install the reprogrammed operating system. |
| 68 | <p> |
| 69 | <img src="qrc:/help/images/assembleinstallnewos.png" alt="assembleinstallnewos" hspace=10 vspace=10> |
| 70 | <p> |
| 71 | You can save your modified operating system as a <code>.pep</code> file as you would any other Pep/8 assembly language program. |
| 72 | <p> |
| 73 | <h4>Step 5.</h4> |
| 74 | Write an assembly language program to test your new instruction with the new mnemonic. |
| 75 | The assembler should recognize the new mnemonic and generate the appropriate object code. |
| 76 | For example, your test program might be the following. |
| 77 | <p> |
| 78 | <img src="qrc:/help/images/echoprogram.png" alt="echoprogram" hspace=10 vspace=10> |
| 79 | <p> |
| 80 | <h4>Step 6.</h4> |
| 81 | Load and execute your program assembled in step 5. |
| 82 | In this example, whatever character is placed in the Input pane should be echoed in the output pane. |
| 83 | <p> |
| 84 | <img src="qrc:/help/images/pecho.png" alt="pecho" hspace=10 vspace=10> |
| 85 | <p> |
| 86 | <a href="#Topics">Scroll to topics</a>. |
| 87 | |
| 88 | <h3><a name="BURN">The .BURN pseudo-op</a></h3> |
| 89 | |
| 90 | When you include <code>.BURN</code> in a program, the assembler assumes that the program will be burned into read-only memory (ROM). |
| 91 | It generates code for those instrctions that follow the burn directive, but not for those that precede it. |
| 92 | The assembler also assumes that the ROM will be installed at the bottom of memory, leaving the top of memory for the application programs. |
| 93 | It therefore calculates tha addresses for the symbol table such that the last byte generated will have the address specified |
| 94 | by the burn directive. |
| 95 | <p> |
| 96 | Pep/8 is a 16-bit computer, and can therfore access 2<sup>16</sup> = 64KB = 65,536 bytes of main memory. |
| 97 | The Pep/8 operating system contains <code>.BURN 0xFFFF</code> because <code>0xFFFF</code> is the address of the 65,536th byte. |
| 98 | <p> |
| 99 | It is possible to install a smaller amount of memory in the Pep/8 system. |
| 100 | Simply change the burn directive in the operating system to a smaller value. |
| 101 | For example, you can change the burn directive to <code>.BURN 0x7FFF</code>, assemble and install the new OS, |
| 102 | and the system will install only 32KB of memory instead of 64KB. |
| 103 | <p> |
| 104 | <img src="qrc:/help/images/modifieddotburn.png" alt="modifieddotburn" hspace=10 vspace=10> |
| 105 | <p> |
| 106 | The trap handlers all run correctly, which you can trace in the Memory Dump pane. |
| 107 | <p> |
| 108 | <img src="qrc:/help/images/relocatedos.png" alt="relocatedos" hspace=10 vspace=10> |
| 109 | <p> |
| 110 | <a href="#Topics">Scroll to topics</a>. |
| 111 | <p> |
| 112 | </body> |
| 113 | </html> |