| 1 | <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01//EN"> |
| 2 | |
| 3 | <html> |
| 4 | <head> |
| 5 | <title> Pep/8: Reference Documentation </title> |
| 6 | <style type="text/css" media="all"> |
| 7 | th { background-color:#FB9F14; color: #29315E } |
| 8 | img { vertical-align:text-top; } |
| 9 | code { font-family:Courier, 'Courier New', monospace; font-size:11pt } |
| 10 | </style> |
| 11 | </head> |
| 12 | <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#000033" alink="#0066FF"> |
| 13 | <table bgcolor="#FB9F14" width="100%" cellpadding="2" cellspacing="0" border="0"> |
| 14 | <tr><td> |
| 15 | <p style="text-align:center; font-family:helvetica, arial, sans-serif; font-size:14pt; font-weight:bold; color: #29315E"> |
| 16 | Pep/8 Reference |
| 17 | </p> |
| 18 | </td></tr> |
| 19 | </table> |
| 20 | <p> |
| 21 | The Pep/8 computer is a 16-bit complex instruction set computer (CISC). |
| 22 | It is designed to teach computer architecture and assembly language programming principles. |
| 23 | Its 39 instructions are based on an expanding opcode and are either unary (one byte) or nonunary (three bytes). |
| 24 | The eight addressing modes are designed for straighforward translation between C/C++ and assembly language. |
| 25 | <p> |
| 26 | <a name = "Topics">Topics:</a> |
| 27 | <a href="#Instruction">Instruction set</a>, |
| 28 | <a href="#SettingC">Setting the C bit on subtraction</a>, |
| 29 | <a href="#SettingN">Setting the N bit on <code>CPr</code></a>, |
| 30 | <a href="#Dot">Dot commands</a>, |
| 31 | <a href="#Addressing">Addressing modes</a>, |
| 32 | <a href="#Register">Register field</a>, |
| 33 | <a href="#Trace">Trace tags</a>, |
| 34 | <a href="#Syntax">Assembly language syntax summary</a>. |
| 35 | |
| 36 | <h3><a name="Instruction">Instruction set</a></h3> |
| 37 | |
| 38 | <table border cellspacing=0 cellpadding=5> |
| 39 | <tr> |
| 40 | <th>Instruction Specifier</th> <th>Mnemonic</th> <th>Instruction</th> <th>Addressing Modes</th> <th>Status Bits</th> |
| 41 | </tr> |
| 42 | <tr> |
| 43 | <td><code>0000 0000</code></code></td> <td><code>STOP</code></td> <td>Stop execution</td> <td>U</td> <td></td> |
| 44 | </tr> |
| 45 | <tr> |
| 46 | <td><code>0000 0001</code></td> <td><code>RETTR</code></td> <td>Return from trap</td> <td>U</td> <td></td> |
| 47 | </tr> |
| 48 | <tr> |
| 49 | <td><code>0000 0010</code></td> <td><code>MOVSPA</code></td> <td>Move SP to A</td> <td>U</td> <td></td> |
| 50 | </tr> |
| 51 | <tr> |
| 52 | <td><code>0000 0011</code></td> <td><code>MOVFLGA</code></td> <td>Move NZVC flags to A</td> <td>U</td> <td></td> |
| 53 | </tr> |
| 54 | <tr> |
| 55 | <td><code>0000 010a</code></td> <td><code>BR</code></td> <td>Branch unconditional</td> <td>i, x</td> <td></td> |
| 56 | </tr> |
| 57 | <tr> |
| 58 | <td><code>0000 011a</code></td> <td><code>BRLE</code></td> <td>Branch if less than or equal to</td> <td>i, x</td> <td></td> |
| 59 | </tr> |
| 60 | <tr> |
| 61 | <td><code>0000 100a</code></td> <td><code>BRLT</code></td> <td>Branch if less than</td> <td>i, x</td> <td></td> |
| 62 | </tr> |
| 63 | <tr> |
| 64 | <td><code>0000 101a</code></td> <td><code>BREQ</code></td> <td>Branch if equal to</td> <td>i, x</td> <td></td> |
| 65 | </tr> |
| 66 | <tr> |
| 67 | <td><code>0000 110a</code></td> <td><code>BRNE</code></td> <td>Branch if not equal to</td> <td>i, x</td> <td></td> |
| 68 | </tr> |
| 69 | <tr> |
| 70 | <td><code>0000 111a</code></td> <td><code>BRGE</code></td> <td>Branch if greater than or equal to</td> <td>i, x</td> <td></td> |
| 71 | </tr> |
| 72 | <tr> |
| 73 | <td><code>0001 000a</code></td> <td><code>BRGT</code></td> <td>Branch if greater than</td> <td>i, x</td> <td></td> |
| 74 | </tr> |
| 75 | <tr> |
| 76 | <td><code>0001 001a</code></td> <td><code>BRV</code></td> <td>Branch if V</td> <td>i, x</td> <td></td> |
| 77 | </tr> |
| 78 | <tr> |
| 79 | <td><code>0001 010a</code></td> <td><code>BRC</code></td> <td>Branch if C</td> <td>i, x</td> <td></td> |
| 80 | </tr> |
| 81 | <tr> |
| 82 | <td><code>0001 011a</code></td> <td><code>CALL</code></td> <td>Call subroutine</td> <td>i, x</td> <td></td> |
| 83 | </tr> |
| 84 | <tr> |
| 85 | <td><code>0001 100r</code></td> <td><code>NOTr</code></td> <td>Bitwise invert r</td> <td>U</td> <td>N Z</td> |
| 86 | </tr> |
| 87 | <tr> |
| 88 | <td><code>0001 101r</code></td> <td><code>NEGr</code></td> <td>Negate r</td> <td>U</td> <td>N Z V</td> |
| 89 | </tr> |
| 90 | <tr> |
| 91 | <td><code>0001 110r</code></td> <td><code>ASLr</code></td> <td>Arithmetic shift left r</td> <td>U</td> <td>N Z V C</td> |
| 92 | </tr> |
| 93 | <tr> |
| 94 | <td><code>0001 111r</code></td> <td><code>ASRr</code></td> <td>Arithmetic shift right r</td> <td>U</td> <td>N Z C</td> |
| 95 | </tr> |
| 96 | <tr> |
| 97 | <td><code>0010 000r</code></td> <td><code>ROLr</code></td> <td>Rotate left r</td> <td>U</td> <td>C</td> |
| 98 | </tr> |
| 99 | <tr> |
| 100 | <td><code>0010 001r</code></td> <td><code>RORr</code></td> <td>Rotate right r</td> <td>U</td> <td>C</td> |
| 101 | </tr> |
| 102 | <tr> |
| 103 | <td><code>0010 01nn</code></td> <td><code>NOPn</code></td> <td>Unary no operation trap</td> <td>U</td> <td></td> |
| 104 | </tr> |
| 105 | <tr> |
| 106 | <td><code>0010 1aaa</code></td> <td><code>NOP</code></td> <td>Nonunary no operation trap</td> <td>i</td> <td></td> |
| 107 | </tr> |
| 108 | <tr> |
| 109 | <td><code>0011 0aaa</code></td> <td><code>DECI</code></td> <td>Decimal input trap</td> <td>d, n, s, sf, x, sx, sxf</td> <td>N Z V</td> |
| 110 | </tr> |
| 111 | <tr> |
| 112 | <td><code>0011 1aaa</code></td> <td><code>DECO</code></td> <td>Decimal output trap</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td></td> |
| 113 | </tr> |
| 114 | <tr> |
| 115 | <td><code>0100 0aaa</code></td> <td><code>STRO</code></td> <td>String output trap</td> <td>d, n, sf</td> <td></td> |
| 116 | </tr> |
| 117 | <tr> |
| 118 | <td><code>0100 1aaa</code></td> <td><code>CHARI</code></td> <td>Character input</td> <td>d, n, s, sf, x, sx, sxf</td> <td></td> |
| 119 | </tr> |
| 120 | <tr> |
| 121 | <td><code>0101 0aaa</code></td> <td><code>CHARO</code></td> <td>Character output</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td></td> |
| 122 | </tr> |
| 123 | <tr> |
| 124 | <td><code>0101 1nnn</code></td> <td><code>RETn</code></td> <td>Return from call with n local bytes</td> <td>U</td> <td></td> |
| 125 | </tr> |
| 126 | <tr> |
| 127 | <td><code>0110 0aaa</code></td> <td><code>ADDSP</code></td> <td>Add to stack pointer (SP)</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z V C</td> |
| 128 | </tr> |
| 129 | <tr> |
| 130 | <td><code>0110 1aaa</code></td> <td><code>SUBSP</code></td> <td>Subtract from stack pointer (SP)</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z V C</td> |
| 131 | </tr> |
| 132 | <tr> |
| 133 | <td><code>0111 raaa</code></td> <td><code>ADDr</code></td> <td>Add to r</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z V C</td> |
| 134 | </tr> |
| 135 | <tr> |
| 136 | <td><code>1000 raaa</code></td> <td><code>SUBr</code></td> <td>Subtract from r</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z V C</td> |
| 137 | </tr> |
| 138 | <tr> |
| 139 | <td><code>1001 raaa</code></td> <td><code>ANDr</code></td> <td>Bitwise AND to r</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z</td> |
| 140 | </tr> |
| 141 | <tr> |
| 142 | <td><code>1010 raaa</code></td> <td><code>ORr</code></td> <td>Bitwise OR to r</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z</td> |
| 143 | </tr> |
| 144 | <tr> |
| 145 | <td><code>1011 raaa</code></td> <td><code>CPr</code></td> <td>Compare r</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z V C</td> |
| 146 | </tr> |
| 147 | <tr> |
| 148 | <td><code>1100 raaa</code></td> <td><code>LDr</code></td> <td>Load r from memory</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z</td> |
| 149 | </tr> |
| 150 | <tr> |
| 151 | <td><code>1101 raaa</code></td> <td><code>LDBYTEr</code></td> <td>Load byte r from memory</td> <td>i, d, n, s, sf, x, sx, sxf</td> <td>N Z</td> |
| 152 | </tr> |
| 153 | <tr> |
| 154 | <td><code>1110 raaa</code></td> <td><code>STr</code></td> <td>Store r to memory</td> <td>d, n, s, sf, x, sx, sxf</td> <td></td> |
| 155 | </tr> |
| 156 | <tr> |
| 157 | <td><code>1111 raaa</code></td> <td><code>STBYTEr</code></td> <td>Store byte r to memory</td> <td>d, n, s, sf, x, sx, sxf</td> <td></td> |
| 158 | </tr> |
| 159 | </table> |
| 160 | <p> |
| 161 | <a href="#Topics">Scroll to topics</a>. |
| 162 | |
| 163 | <h3><a name="SettingC">Setting the C bit on subtraction</a></h3> |
| 164 | |
| 165 | There are two different philosophies for setting the carry bit after subtraction. |
| 166 | <p> |
| 167 | Z80, x86, and SPARC treat the carry flag as a "borrow flag" when doing a subtraction. |
| 168 | When subtracting x - y, if x is less than y (treating both operands as unsigned), |
| 169 | the carry flag is set because there is a borrow. |
| 170 | A BRC after a <code>SUBr</code> or <code>CPr</code> instruction is equivalent to "branch if unsigned overflow" in this case. |
| 171 | <p> |
| 172 | On other processor families, such as ARM and PowerPC, the carry flag after a subtraction |
| 173 | is set to the adder carry output after computing (x + ~y + 1). |
| 174 | When subtracting x - y, if x is greater than or equal to y (treating both operands as unsigned), the carry flag is set. |
| 175 | A BRC after a <code>SUBr</code> or <code>CPr</code> instruction is equivalent to "branch if not unsigned overflow" in this case. |
| 176 | <p> |
| 177 | Previous versions of Pep/8 set the C bit on subtraction according to the first philosophy. |
| 178 | However, starting with version 8.1.0, the C bit on subtraction is set according to the second philosophy. |
| 179 | This is consistent with the section "The Carry Bit" in Chapter 3, and the adder/subtracter circuit |
| 180 | in Figure 10.53 in the text. |
| 181 | <p> |
| 182 | <a href="#Topics">Scroll to topics</a>. |
| 183 | |
| 184 | <h3><a name="SettingN">Setting the N bit on <code>CPr</code></a></h3> |
| 185 | |
| 186 | Normally, the N bit duplicates the sign bit, so that N is 1 when the result of the operation is negative. |
| 187 | The compare instruction <code>CPr</code> subtracts the operand from the register and sets the status bits without storing |
| 188 | the result of the subtraction. |
| 189 | <p> |
| 190 | As long as there is no overflow when the operands are interpreted as signed integers, the N bit is set appropriately for a |
| 191 | subsequent conditional branch instruction. |
| 192 | If the result of the subtraction yields an overflow and the N bit were set as usual, the subsequent conditional branch instruction |
| 193 | might execute an erroneous branch. |
| 194 | Consequently, if the <code>CPr</code> subtraction operation overflows and sets the V bit, then the N bit is inverted |
| 195 | from its normal value and does not duplicate the sign bit. |
| 196 | <p> |
| 197 | With this adjustment, the compare operation extends the range of valid comparisons. |
| 198 | Even though there is an overflow, the N bit is set as if there were no overflow so that a subsequent conditional branch |
| 199 | will operate as expected. |
| 200 | <p> |
| 201 | <a href="#Topics">Scroll to topics</a>. |
| 202 | |
| 203 | <h3><a name="Dot">Dot commands</a></h3> |
| 204 | |
| 205 | <table border cellspacing=0 cellpadding=5> |
| 206 | <tr> |
| 207 | <th>Dot Command</th> <th>Description</th> |
| 208 | </tr> |
| 209 | <tr> |
| 210 | <td><code>.ADDRSS</code> symbol</td> <td>The address of a symbol (two bytes)</td> |
| 211 | </tr> |
| 212 | <tr> |
| 213 | <td><code>.ASCII</code> "string"</td> <td>A string of ASCII bytes</td> |
| 214 | </tr> |
| 215 | <tr> |
| 216 | <td><code>.BLOCK</code> n</td> <td>A block of n bytes</td> |
| 217 | </tr> |
| 218 | <tr> |
| 219 | <td><code>.BURN 0xFFFF</code></td> <td>Initiate ROM burn ending at 0xFFFF</td> |
| 220 | </tr> |
| 221 | <tr> |
| 222 | <td><code>.BYTE</code> constant</td> <td>A byte value (one byte)</td> |
| 223 | </tr> |
| 224 | <tr> |
| 225 | <td><code>.END</code></td> <td>The sentinel for the assembler</td> |
| 226 | </tr> |
| 227 | <tr> |
| 228 | <td><code>.EQUATE</code> constant</td> <td>Equate a symbol to a constant value</td> |
| 229 | </tr> |
| 230 | <tr> |
| 231 | <td><code>.WORD</code> constant</td> <td>A word value (two bytes)</td> |
| 232 | </tr> |
| 233 | </table> |
| 234 | <p> |
| 235 | <a href="#Topics">Scroll to topics</a>. |
| 236 | |
| 237 | <h3><a name="Addressing">Addressing modes</a></h3> |
| 238 | |
| 239 | <table border cellspacing=0 cellpadding=5> |
| 240 | <tr> |
| 241 | <th>Addressing Mode</th> <th>aaa-field</th> <th>Letters</th> <th>Operand</th> |
| 242 | </tr> |
| 243 | <tr> |
| 244 | <td>Immediate</td> <td><code>000</code></td> <td>i</td> <td>OprndSpec</td> |
| 245 | </tr> |
| 246 | <tr> |
| 247 | <td>Direct</td> <td><code>001</code></td> <td>d</td> <td>Mem [OprndSpec ]</td> |
| 248 | </tr> |
| 249 | <tr> |
| 250 | <td>Indirect</td> <td><code>010</code></td> <td>n</td> <td>Mem [Mem [OprndSpec ] ]</td> |
| 251 | </tr> |
| 252 | <tr> |
| 253 | <td>Stack-relative</td> <td><code>011</code></td> <td>s</td> <td>Mem [SP + OprndSpec ]</td> |
| 254 | </tr> |
| 255 | <tr> |
| 256 | <td>Stack-relative deferred</td> <td><code>100</code></td> <td>sf</td> <td>Mem [Mem [SP + OprndSpec ] ]</td> |
| 257 | </tr> |
| 258 | <tr> |
| 259 | <td>Indexed</td> <td><code>101</code></td> <td>x</td> <td>Mem [OprndSpec + X ]</td> |
| 260 | </tr> |
| 261 | <tr> |
| 262 | <td>Stack-indexed</td> <td><code>110</code></td> <td>sx</td> <td>Mem [SP + OprndSpec + X ]</td> |
| 263 | </tr> |
| 264 | <tr> |
| 265 | <td>Stack-indexed deferred</td> <td><code>111</code></td> <td>sxf</td> <td>Mem [Mem [SP + OprndSpec ] + X ]</td> |
| 266 | </tr> |
| 267 | </table> |
| 268 | <p> |
| 269 | <a href="#Topics">Scroll to topics</a>. |
| 270 | |
| 271 | <p> |
| 272 | <table border cellspacing=0 cellpadding=5> |
| 273 | <tr> |
| 274 | <th>Addressing Mode</th> <th>a-field</th> <th>Letters</th> <th>Operand</th> |
| 275 | </tr> |
| 276 | <tr> |
| 277 | <td>Immediate</td> <td><code>0</code></td> <td>i</td> <td>OprndSpec</td> |
| 278 | </tr> |
| 279 | <tr> |
| 280 | <td>Indexed</td> <td><code>1</code></td> <td>x</td> <td>Mem [OprndSpec + X ]</td> |
| 281 | </tr> |
| 282 | </table> |
| 283 | <p> |
| 284 | <a href="#Topics">Scroll to topics</a>. |
| 285 | |
| 286 | <h3><a name="Register">Register field</a></h3> |
| 287 | |
| 288 | <p> |
| 289 | <table border cellspacing=0 cellpadding=5> |
| 290 | <tr> |
| 291 | <th>r-field</th> <th>Register</th> |
| 292 | </tr> |
| 293 | <tr> |
| 294 | <td><code>0</code></td> <td>Accumulator, A</td> |
| 295 | </tr> |
| 296 | <tr> |
| 297 | <td><code>1</code></td> <td>Index register, X</td> |
| 298 | </tr> |
| 299 | </table> |
| 300 | <p> |
| 301 | <a href="#Topics">Scroll to topics</a>. |
| 302 | |
| 303 | <h3><a name="Trace">Trace tags</a></h3> |
| 304 | |
| 305 | <p> |
| 306 | <table border cellspacing=0 cellpadding=5> |
| 307 | <tr> |
| 308 | <th>Trace tag</th> <th>Format</th> |
| 309 | </tr> |
| 310 | <tr> |
| 311 | <td><code>#1c</code></td> <td>One-byte character</td> |
| 312 | </tr> |
| 313 | <tr> |
| 314 | <td><code>#1d</code></td> <td>One-byte decimal</td> |
| 315 | </tr> |
| 316 | <tr> |
| 317 | <td><code>#2d</code></td> <td>Two-byte decimal</td> |
| 318 | </tr> |
| 319 | <tr> |
| 320 | <td><code>#1h</code></td> <td>One-byte hexadecimal</td> |
| 321 | </tr> |
| 322 | <tr> |
| 323 | <td><code>#2h</code></td> <td>Two-byte hexadecimal</td> |
| 324 | <tr> |
| 325 | <td><code>#2d4a</code></td> <td>Two-byte decimal, four-cell array (example)</td> |
| 326 | </tr> |
| 327 | </table> |
| 328 | <p> |
| 329 | <a href="#Topics">Scroll to topics</a>. |
| 330 | |
| 331 | <h3><a name="Syntax">Assembly language syntax summary</a></h3> |
| 332 | |
| 333 | A decimal integer starts with an optional <code>+</code> or <code>-</code>, followed by a decimal digit followed by zero or more digits. |
| 334 | <p> |
| 335 | A decimal integer used with <code>.BYTE</code> ranges from -128 to 255, otherwise from -32768 to 65535. |
| 336 | <p> |
| 337 | A hex integer starts with <code>0x</code> or <code>0X</code> followed by one or more hex digits (upper- or lower-case). |
| 338 | <p> |
| 339 | A hex integer used with <code>.BYTE</code> ranges from 0 to FF, otherwise from 0 to FFFF. |
| 340 | <p> |
| 341 | A single character is enclosed in single quotes, as in <code>'t'</code>. |
| 342 | <p> |
| 343 | An ASCII string is enclosed in double quotes, as in <code>"My string."</code>. |
| 344 | <p> |
| 345 | An arbitrary byte can be included in a string or a character by prefixing exactly two hex digits with <code>\x</code> or <code>\X</code>, as in <code>"Null terminated\x00"</code>. |
| 346 | <p> |
| 347 | A double quote is included in a string by prefixing it with <code>\</code>, as in <code>"She said, \"Hello\"."</code>. |
| 348 | <p> |
| 349 | A single quote is included in a character by prefixing it with <code>\</code>, as in <code>'\''</code>. |
| 350 | <p> |
| 351 | A backslash character is included in a string or character by prefixing it with <code>\</code>, as in <code>"My bash is \\."</code> and <code>'\\'</code>. |
| 352 | <p> |
| 353 | The following letters, when preceded by <code>\</code>, generate non printable characters—<code>b</code> backspace, <code>f</code> form feed, <code>n</code> line feed (new line), <code>r</code> carriage return, <code>t</code> horizontal tab, <code>v</code> vertical tab—in string and character constants, as in <code>"\n Starts on a new line."</code> and <code>'\n'</code>. |
| 354 | <p> |
| 355 | A backslash character followed by any character other than <code>b</code>, <code>f</code>, <code>n</code>, <code>r</code>, <code>t</code>, <code>v</code>, <code>x</code>, <code>X</code>, <code>"</code>, <code>'</code>, or <code>\</code> (except for the second of a pair of <code>\</code>’s) is an error. |
| 356 | <p> |
| 357 | A double quote preceded by a backslash in a character is not necessary but is valid and represents one double quote. |
| 358 | <p> |
| 359 | A single quote preceded by a backslash in a string is not necessary but is valid and represents one single quote. |
| 360 | <p> |
| 361 | A constant used as an operand specifier that occupies less than two bytes is right justified in the two-byte field. |
| 362 | <p> |
| 363 | A constant used as an operand specifier that occupies more than two bytes is an error. |
| 364 | <p> |
| 365 | <a href="#Topics">Scroll to topics</a>. |
| 366 | |
| 367 | <p> |
| 368 | </body> |
| 369 | </html> |