Figuring out the TD4 4-bit DIY CPU made from logic chips...

https://emalliab.wordpress.com/2025/09/18/td4-4-bit-diy-cpu/

#TD4

TD4 4-bit DIY CPU

I was looking for DIY CPU projects, as I like kits that help me think at the lowest level of processing. It helps keep me grounded in how far technology has come over the years. Some of the options…

Kevin's Blog

My TD4 kit has arrived.

And wow, that really is a lot of diodes...

#TD4

It works! That was a great build :)

Details here: https://emalliab.wordpress.com/2025/09/28/td4-4-bit-diy-cpu-part-2/

#TD4

A simple 4-bit "Larson Scanner" - just a sequence of OUT instructions and a jump.

https://makertube.net/w/gwjtRveafD98M4PdqEcaoR

#TD4

TD4 4-bit CPU "Larson Scanner"

PeerTube

And now with some notes on programming and some example programs.

BTW - Anyone think of a way to multiply two numbers given only two registers and no other storage...?

https://emalliab.wordpress.com/2025/10/01/td4-4-bit-diy-cpu-part-3/

#TD4

TD4 4-bit DIY CPU – Part 3

Having now spent some time thinking about and building my TD4 4-bit CPU this has a look at some code that I can run on it. Part 1 – Introduction, Discussion and Analysis Part 2 – B…

Kevin's Blog
@emalliab Maybe it's possible to add the logarithm of both? Don't know if it's possible to do that accurately.

@Segebodo I'd guess that would need some kind of look up table to do?

To be honest, my solution so far is a look up table for the only four sums I'm actually able to process anyway on a 4-bit computer with a single input :)

@emalliab Here's a program that sums the log 2 of any amount of consecutive inputs.
It uses

IN A, x (which is A = IN + data)
JNC label

to implement

if A <= (15-x) goto label

@emalliab
//multiply any amount of numbers
//returns the sum of the approximate log 2 values (log2 of the product)
//any input that's zero is ignored
next_number:
OUT B //show result
OUT 15 //signal for next input

IN A 14
JNC next_number //if x<=1 -> log2(x)=0
ADD B 1
IN A 12
JNC next_number //if x<=3 -> log2(x)=1
ADD B 1
IN A 9
JNC next_number //if x<=6 -> log2(x)=2
ADD B 1
IN A 3
JNC next_number //if x<=12 -> log2(x)=3
ADD B 1
JMP next_number //else log2=4

@emalliab
I used the assembler compiler and simulator from https://www.philipzucker.com/td4-4bit-cpu/
and made a lot of changes (added compiler errors, added label functionality).
Here's the python code:

https://www.onlineide.pro/playground/share/9e52afd6-ab3f-4f06-946a-e9eb05cc307d

(Link expires after 1 month)
I don't have the full or claim any copyright for the code.

Guide to the TD4 4-bit DIY CPU

I bought a cute little 4 bit cpu kit from Aliexpress called the TD4. It has 2 registers, some LEDs, and 16 bytes of program ROM. Quite limited but still very cool and teaches a lot of principles of computer architecture.

Hey There Buddo!
@Segebodo Haha - great - I'll take a look a bit later :)

@Segebodo I've added your algorithm to the post - many thanks!

Am right though - the answer is the log2 sum answer?

Anyway, all good fun :)