A computer from scratch - Eating at NANDos

I am attempting to build a computer from prime principles. Am I crazy? Probably. But I have a plan.

I have a plan

Let's start from the beginning

Why, oh why?

Because not knowing how stuff works bugs me to no end. It's not enough for me to use a programming language. In the past I dabbled and spent more than a little time playing with lower level stuff like assembly. I also spent considerable time thinking architecturally about systems -- in fact I have been a senior software architect (whatever that means, lol). This is to say: I try not to be monodimensional and I like to approach systems from different angles, I like taking a look from orbit and zooming in with a microscope -- and all the views in between.

My knowledge has gaps when going from the transistor to the computer. I know the parts and how to assemble a computer, but not how, for example, to build a CPU or memory chip. I want to find out! I have come across two things that tipped me over the edge and got me started

  • I subscribed to the "From NAND to Tetris" on Coursera and bought the relative book. While the course is very nice, it focuses on understanding the theory behind how a computer is built. It's not about building the hardware.
  • My birthday came about and I bought myself an Arduino kit, which comes with breadboard and components which in turn gave me the tools to get started (almost).

The reason why I want to build a computer is that doing something in practice is way more interesting that studying how it should be done.

The evil plan

I am not deranged enough (yet...) to literally build a computer transistor by transistor. Would you spend years soldering together memory banks bit by bit? It makes no sense. What I plan to do is cheat by removing the tedious parts and leaving the fun ones. I will do so by "scaling". If I built something, say, an adder, I'll let myself buy premade adders like a TI-7483. So as long as what I'm avoiding to do is a repetition of what I've done, I'm fine.

I am not sure if this makes all the step necessary feasible, if not, I'll cheat more, because YOLO. I will take basic electrical components for granted, too -- I know how transistors, resistors, caps, LEDs, etc. work from my physics labs days.

In detail, here's what the current journey plan looks like:

  1. Physics: valves, transistors, caps, LEDs and other basic things. (I am skipping this)
  2. NAND gate. They tell me everything can be built with these.
  3. Basic gates (AND, OR, NOT, XOR)
  4. Adders
  5. ALU
  6. Memory and registers
  7. CPU
  8. Bare bones computer, machine code

I don't know if I'll be able to go to all the way to point 8. Stuff gets harder as we go down the list. On top of that, there are BIOSes, OSes, compilers, etc. Also there's a factor of costs involved to consider. We shall see.

Building a NAND gate

NAND gates are interesting because they are easy to build and you can use them to build every other kind of gate. I think it's a good starting point to build a computer!

I've taken the circuit from hyperphysics and modified it to suit my needs. Here's what I came up with:

nand circuit

Which should look like this once on the breadboard:

nand breadboard

I expect the led to be ON if no buttons are pressed, or if only one button is pressed, and OFF is both buttons are pressed.

I am using a Sunfounder Arduino UNO clone to power this circuit. All schematics made with fritzing.

Result

Success! The circuit behaves as expected. It even ran on the first attempt! Here's a pic of the running circuit, attached to my Arduino as power source.

running nand gate

For someone as fat fingered as I am, with no experience in electronics, this was a lot of fun! I can't wait to take the next step!

(discuss on hacker news)


Hi, I'm Marco Cecconi. I am the founder of Intelligent Hack, developer, hacker, blogger, conference lecturer. Bio: ex Stack Overflow core team, ex Toptal EM.

Read more

Newest Posts

What can Stack Overflow learn from ChatGPT?

Stack Overflow could benefit from adopting a using conversational AI to provide specific answers

Read more
Fan mail

Multiple people with my name use my email address and I can read their email, chaos ensues!

Read more
Intelligent Trip

After years of building, our top-notch consultancy to help start-ups and scale-ups create great, scalable products, I think it is high time I added an update to how it is going and what's next for us.

Read more
Guest blog: Building, in partnership with communities by Shog9

A lesson in building communities by Stack Overflow's most prominent community manager emeritus, Shog9

Read more
Can you migrate a company from on-premise to remote-only?

Some lessons learned over the past 8 years of remote work in some of the best remote companies on the planet

Read more

Gleanings

And the Most Realistic Developer in Fiction is...
Julia Silge • Mar 28, 2017

We can say that Mr. Robot is having a moment. The main character was one of the top choices and thus is perhaps the most/least realistic/annoying/inspiring portrayal of what it’s like to be a computer programmer today.

Read more…