Software - Tiny CPU - Spec

This CPU consists of a program counter (PC), three registers (A, B, and C) and 256 bytes of memory.

Instructions are one byte, with additional bytes to specify operands when needed. Instructions may have a target and a source specified in them.

codeoperand
0A
1B
2C
3mem[next byte]

The operand code of 3 indicates that the next byte will be read after the instruction and the memory byte at that address will be used. If both operands require another byte to be read, the first byte will specify the target and the next will specify the source.

codeoperationnotes
00010001JMP Jset PC to J
00100001SCPset mem[A] to mem[B] and increment A and B
01TT0001MVL Tset T to the literal value in the next byte
10TT0001CAL T Jset mem[T] to PC then set PC to J
11TT0001RET Tset PC to mem[T]
SSTT0010MOV T Scopy the value at S to T
SSTT0011MFR T Sset T to mem[S] (move from reference)
SSTT0100MTR T Sset mem[T] to S (move to reference)
SSTT0101JEQ T S Jif T==S set PC to J
SSTT0110JNE T S Jif T!=S set PC to J
SSTT0111JLT T S Jif T<S set PC to J (signed)
SSTT1000ADD T Sset T to T+A
SSTT1001SUB T Sset T to T-A
SSTT1010MUL T Sset T to T*A (signed)
SSTT1011DIV T Sset T to T/A (signed)
SSTT1100MOD T Sset T to T%A (signed)
SSTT1101AND T Sset T to the bitwise and of T and S
SSTT1110OR T Sset T to the bitwise and of T or S
SSTT1111XOR T Sset T to the bitwise and of T xor S

Jump operations that require an address J will read the byte to be used for A after the instruction and and operand bytes it requires.

The CPU outputs to an 8 x 4 character screen that is mapped into memory starting at address 0.

When the CPU is started the user's code is loaded into memory starting at address 0x20 (32), PC is set to 0x20 (32) and execution begins.