The program ROM, the terminal and Kestrel assembly
A program ROM that holds Kestrel assembly and a text terminal that shows what it prints: the parts around the computer you build from gates.
They belong to the path From gates to a computer. Like the bit parts they are ideal logic parts with no supply pins.
Program ROM (progrom)
256 instructions for the Kestrel CPU. The address goes in on A0 to A7. The
instruction at that address comes out as two bytes: the code byte on C0 to C7
and the constant byte on K0 to K7. A read takes 10 ns, like a gate.
The program property is the program itself, in Kestrel assembly (below). It is
assembled when you press Run, and a mistake stops the run with the line it is on.
| Property | What it does |
|---|---|
program |
The program, one instruction a line. |
Terminal (terminal)
A text screen of six lines of twenty characters. On each rising edge of CLK while
WE is 1, the byte on D0 to D7 is written. In text mode a byte is a character:
10 starts a new line, 12 clears the screen and 8 rubs out the last character. In
numbers mode every byte is shown as a decimal number.
| Property | What it does |
|---|---|
mode |
text or numbers. |
The Kestrel
The Kestrel is Mokxi's own small CPU, and the last chip on the path. It has four
8-bit registers, R0 to R3, an 8-byte RAM, and a program counter. Every
instruction takes one tick of the clock. An instruction is 16 bits: the code byte
holds a 4-bit opcode, the destination register d and the source register s, and
the constant byte holds a number or an address.
| Instruction | Opcode | What it does |
|---|---|---|
NOP |
0 | Nothing. |
LDI Rd, k |
1 | Rd = k. |
ADDI Rd, k |
2 | Rd = Rd + k. |
LD Rd, [Rs] |
3 | Rd = the RAM byte at address Rs. |
ST Rd, [Rs] |
4 | The RAM byte at address Rs = Rd. |
OUT Rd |
5 | Rd goes to the terminal. |
JMP k |
6 | Go to address k. |
JZ Rd, k |
7 | Go to address k when Rd is 0. |
ADD Rd, Rs |
8 | Rd = Rd + Rs. |
SUB Rd, Rs |
9 | Rd = Rd - Rs. |
AND Rd, Rs |
10 | Rd = Rd AND Rs. |
OR Rd, Rs |
11 | Rd = Rd OR Rs. |
XOR Rd, Rs |
12 | Rd = Rd XOR Rs. |
NOT Rd |
13 | Rd = NOT Rd. |
MOV Rd, Rs |
14 | Rd = Rs. |
JNZ Rd, k |
15 | Go to address k when Rd is not 0. |
Numbers are 8 bits and wrap: 255 + 1 is 0. The RAM uses the low three bits of the address, so address 9 is the same byte as address 1.
Writing assembly
One instruction a line. A ; starts a comment. A label is a name and a colon, and a
jump can name it instead of an address. A constant can be decimal (42), hex
(0x2A), binary (0b101010), a character in single quotes ('A'), or negative
(-1, which is 255). .word 0x1234 puts a raw 16-bit word in. Capitals do not
matter.
LDI R1, 3 ; count down from 3
loop: OUT R1
ADDI R1, -1
JNZ R1, loop
stop: JMP stop ; a program ends by jumping to itself
What the model gets right
The ROM is combinational, like a real one: change the address and the new word appears a gate delay later. The terminal writes on the clock edge, exactly when the CPU's registers do.
What it does not model
Neither part is a real chip. There is no access time beyond one gate delay, no supply, and the terminal has no cursor you can move.
Common mistakes
Forgetting RESET. A CPU built from gates powers up not knowing what is in its program counter. Hold RESET at 1 for a tick of the clock, then set it to 0.
See it in action
Your first computer on /templates, and the last lessons on the path From gates to a computer, under Learn.