The VikiD Truth

Knowledge base / Computing / Operating systems & hardware

Previews of Build a Computer in Your Head

Quicklinks | Readinglist | computingFreedom | BCIYH | Picolisp | Picolisp Machine | pil sources | Linux | BASH | C Programmming | Operating Systems | Javascipt | Emacs | vim | Pharo Smalltalk | Computer Security | Python

I am writing a new ‘book’ called Build a Computer In Your Head (BCIYH), pronouced as “Bikih”, and I will be posting excerpts/notes regarding the subject here for you to preview and comment upon.

I have been inspired to do this by a few books and projects which you can find at the bottom of this page.

Turing taught us that computers are essentially finite state machines. On the other Alonzo Church taught us that computation is form of algebraic reduction. A defined method of condensation, or restatement of given facts into simpler facts.

Turing’s picture is based on what a computer ‘is’ Church’s picture is based on what a computer ‘does’

This two view points have been at odds and slowly converging ever since they were first introduced. Building computers based on ‘what they are’ has always been easier (or at least more efficient) than building them by ‘what they do’. So most modern systems lie closer to turnings picture than Church’s.

In Bikih I plan to explore these concepts deeply.

What it is, in plain words

Here is the truth that started this project: a computer is simple enough to hold in your head. It only feels complicated because it is usually explained from the top down, starting with apps and windows. Explained from the bottom up, each layer is small and obvious once you have the one beneath it.

Build a Computer in Your Head is that bottom-up path. Each chapter adds one layer:

flowchart BT
  A[Binary: everything is 0s and 1s] --> B[Logic gates: AND, OR, NOT, NAND]
  B --> C[Arithmetic: adders built from gates]
  C --> D[Memory: flip-flops and registers]
  D --> E[CPU: fetch, decode, execute]
  E --> F[Machine and assembly language]
  F --> G[Compilers, interpreters, Lisp]
  G --> H[Operating system]
  H --> I[Programs you use]

Turing’s picture explains the bottom half: a machine with states and a tape, stepping one instruction at a time. Church’s picture explains the top half: computation as rewriting expressions until they cannot be simplified further, which is exactly what a Lisp interpreter does. Somewhere around the assembly layer, the two pictures meet.

Why it matters

An everyday analogy: learning a city on foot

You can know a city only by its underground map: stations, colour-coded lines, no idea how they connect above ground. Or you can walk it, street by street, until you can find your way anywhere. Most people know computers by their underground map (apps and icons). BCIYH is the walk.

A hands-on example: one bit of arithmetic, three ways

Adding two one-bit numbers needs only two gates: XOR gives the sum, AND gives the carry. That is a half adder, the seed of every CPU’s arithmetic unit.

absum (a XOR b)carry (a AND b)
0000
0110
1010
1101

In C, using the CPU’s own bitwise operators:

#include <stdio.h>
int main(void) {
    for (int a = 0; a <= 1; a++)
        for (int b = 0; b <= 1; b++)
            printf("%d + %d = carry %d, sum %d\n", a, b, a & b, a ^ b);
}

In PicoLisp, building XOR from nothing but NAND, the universal gate:

(de g-nand (A B) (if (and (= A 1) (= B 1)) 0 1))
(de g-xor (A B) (let N (g-nand A B) (g-nand (g-nand A N) (g-nand B N))))
(de g-and (A B) (g-nand (g-nand A B) (g-nand A B)))
(de half (A B) (list (g-and A B) (g-xor A B)))   # (carry sum)

(for A (0 1) (for B (0 1) (println A B '-> (half A B))))
# 0 0 -> (0 0)
# 0 1 -> (0 1)
# 1 0 -> (0 1)
# 1 1 -> (1 0)

PicoLisp already has nand and xor built in, which is why these are prefixed g-. Chain half adders into full adders, full adders into a 64-bit adder, add registers and a clock, and you have the heart of a CPU. That is the whole plan of this book in miniature.

Common misconceptions

Connections

The chapters

A very highly recommend these books and projects to anyone really interested in learning the fundamentals of how computers and the languages written to control them work.

Last edited · 18 revisions

Tags: #Computing