A tiny, piston-less, Turing-complete 4-bit hexadecimal CPU with the following parts:
- (Pink) A 7-tick 4-bit ALU with four functions (add, subtract, add immediate, and subtract immediate) and one flag (outputs true if the last ALU operation resulted in a value greater than zero)
- (Lime Green) Four 4-bit duel-read registers for a total memory of 16 bits
- (Yellow) A control unit that supports a 4-bit opcode with three 4-bit operands along with the following functions: jgz (jump if greater than zero), jmp, add, sub, adi, and sbi
- (Light Blue) ROM that supports sixteen 16-bit instructions for a total storage capacity of 256 bits (7.56 blocks per bit)
- (Purple) A program counter that can be incremented by one and supports both conditional and unconditional jumping
- (Dark Blue) A clock that outputs a pulse once every 40 ticks (for a 0.25 Hz clock speed) that's used to write to the program counter and registers at the end of each instruction's execution
Dimensions and Volume: 18x13x37 for a total volume of 8658 blocks
The CPU is also equipped with one output port (but no input ports), a lever for toggling the CPU on and off, and a lever and button on the back side for manually pulsing the clock.
Near the coordinates specified above, there is a lever that toggles the CPU between on and off. When the lamp is on, the program loaded into ROM will start executing from the first line (line 0). When the lamp is turned off, the program counter is reset to line 0, the clock is halted, and all registers are reset. At the back of the CPU, there is a lever and a button. When the lamp on the other side is turned on, but the lever is flicked off, then the clock will stop but the CPU will not reset. The allows you to press the button to pulse the clock and increment to the next line for debugging purposes. DO NOT MANUALLY PULSE THE CLOCK FASTER THAN 0.25 HERTZ. At the time of writing this, a simple Fibonacci program is loaded into ROM to be executed. The sequence will start at 1 and go all the way up to 13 before restarting back at 1.
Programming Guide:
The ISA at the back of the CPU contains a list of all six instructions along with their opcodes and their supported operands. Here is a simple countdown program using these instructions. This program will start at ten and then count down by one. When it reaches zero, the program will restart back at 10 (one thing to also note is that the value stored in register 1 is what is outputted):
0 adi $1, $0, 10
1 adi $2, $0, 1
2 sub $1, $1, $2
3 jgz 2
4 jmp 0
Here is the code above converted into machine code:
0x310A
0x3201
0x6112
0x1200
0x5000
When coding the machine code in ROM, the bottom barrel is the opcode, with the three ascending barrels above that being the three operands.
Comments
Text formatting gone wrong
I don't know how I missed this yesterday, but it seems every line is merged into one (no paragraphs etc.), so I apologize for the bullet points and example code all being in one line instead of multiple.
Absolutely fine, if we knew
Absolutely fine, if we knew how to fix that we would...
(I can press edit to see it more properly formatted)
Approved
Cute little CPU you got there :)
Enjoy Plot & WE.