Retro CPU emulator
Program a small 8-bit computer in assembly: assemble, step or run, and watch registers, flags, memory, the stack and output change.
How to use
- Load an example or write your own program, one instruction per line. A label ends with a colon (loop:); a semicolon starts a note.
- Press Assemble. The listing shows the address and bytes of every line; the memory table shows all 256 bytes.
- Press Step to run one instruction and watch the registers, flags and memory change, or Run to go until HLT (at most 100,000 steps).
- Instructions: LDA / LDB (load A or B: #5 a value, label or $20 an address, [B] the address held in B), STA / STB (store), ADD, SUB, CMP (with B, #value or an address), AND, OR, XOR (#value), INC and DEC (A or B), SHL, SHR, TAB (copy A to B), TBA (B to A), JMP, JZ, JNZ, JC, JNC, CALL, RET, PUSH and POP (A), OUT (print A as a number), OUTC (print A as a letter), HLT, NOP. Data: DB 1, 2, $FF, 'x', "TEXT".
Keyboard and touch
| Tab | Move between the program box and the buttons |
| Enter or Space | Press the focused button (Step is handy to press again and again) |
Tips
- Numbers wrap around: 255 + 1 is 0 with the carry flag set. That is how the Fibonacci example knows when to stop.
- CMP works like SUB but keeps A: use it with JZ (equal) and JC (A was smaller).
- Values are written in decimal, in hex with $ or 0x, or as a letter in single quotes.
- CALL pushes the return address on the stack at the top of memory; watch the s marker move down and back.
- Programs and data share the same 256 bytes, so a program can change itself. Old home computers worked the same way.
About this tool
PT-8 is our own teaching design, kept small enough to read every byte, in the spirit of the 8-bit chips of the late 1970s. Each instruction is one byte, followed by one byte of value or address when it needs one. Flags: Z is set when a result is 0, N when its top bit is 1, C on a carry out of ADD, a borrow in SUB and CMP, or the bit shifted out by SHL and SHR; AND, OR and XOR clear C. The stack starts at address $FF and grows down. The assembler works in two passes so labels can be used before they are defined.
It is not a copy of any real processor. Everything runs in your browser.