The Retroputer CPU is built around the concept of microtasks. This allows the CPU to decode high level instructions into smaller lower-level tasks. Each microtask is encoded in such a way that it can be run based on the current state of the flags, enabling high-level control constructs.

Microtasks run on what is essentially a very small stack computer. This stack is very small, but it is sufficient for the microtasks that the CPU will encounter. This stack allows more complex tasks such as register selection, addition of two registers, and memory transfer.

Microtask Encoding

Microtasks are stored in a small amount of L0 memory in the Retroputer CPU. As the CPU operates, it is continually pushing new tasks into a queue based on any instructions it has decoded (or just normal operation — such as fetching new instructions).

The encoding of a microtask instruction appears as follows:

< MSB                                                     LSB >
7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0
-------3-------|-------2-------|-------1-------|-------0-------
<<< op-code >>>|<<< <<< <<< <<< 24-bit argument >>> >>> >>> >>>
0 << non-alu >>|            depends on instruction
1 <<< alu >>> F|                    ignored

Microtasks

Instruction to Microtask Mapping

A single instruction, such as the simple BRS NZ -10 is decoded into several microtasks. Sometimes the number of microtasks is quite a bit, as is the case with this instruction.

PUSH_WORD               -10           # push the address on to the stack
GET_REGISTER_AND_PUSH   PC            # Compute absolute address
ADD                                   # of target
GET_REGISTER_AND_PUSH   PC            # Push next instruction (if branch not taken)
SWAP                                  # For negative cases, swap the addresses on the stack
TEST_FLAG_IMM           ZERO          # Check the zero flag; if it's set, we'll put a 1 on the stack
PICK                                  # Pick the desired address
POP_INTO_REGISTER       PC            # Jump to that address

In this case, this instruction consumes eight clock cycles (not counting the cycles required to fetch the instruction from memory), since Retroputer executes one microtask per clock.