Kingdom

Concepts

KC Icon

Non Programmer's Guide to Computers

Joseph Miller

12/14/2023

First off, let's get some things out of the way. Ya'll need to stop it with the "I can't understand computers." mindset. Just stop it already!

If you aren't willing to get rid of that mindset and be genuinely curious then I highly recommend you quit reading right now. If you believe you can't, YOU ARE RIGHT, and this will be a waste of your time.

Now that that is taken care of, moving on...

Consider the lowly light switch. When you flip it a light goes on and off. A light switch is a very simple computer with one digit. Off = 0 and on = 1. A computer works in exactly the same way, it just has millions of "light switches".

Yep, that is right. Computers have only two numbers, 0 and 1. On and Off.

This is called binary. Numbers in binary are a little different than numbers using ten digits. 0 is zero, 1 is one but after that things get a little more complicated. Since we are limited to ones and zeros we cannot have a 2 so we need to add another decimal place. This means that 10 is 2, 11 is 3, and so on.

A table of the numbers from zero to nine.

numberbinary
00
11
210
311
4100
5101
6110
7111
81000
91001

One switch, or one on off circuit is called a bit. A byte is made up of 8 bits. In computer language a byte is synonymous to a character in the English language.

For example, this is the letter A as a byte. 01000001

Computers have what are called registers. A register is simply a place to store a byte of data and is just eight little switches that can be individually set to on or off. Think of registers as little note pads where values can be stored.

Computers can only add, subtract and move bytes of data from one register to another. That's it.

If you want to multiply a number by 5 for example, you need to add it to itself 5 times. Division is done by consecutive subtraction. 10 divided by 5 turns into, how often can I subtract 5 from 10?

Each of the operations a computer can do is represented by an op code. An op code is simply a byte. To program a computer at the most basic level all you need to do is put all the right op codes in the right order and the computer will walk down the list and execute them one at a time. Simple.

So lets do that previous example of subtraction. Lets say we have to registers. Register A contains the value 100 and register B contains the value 10. We want to divide A by B.

== set register C to zero
LD RC 0              
-- subtract A from B 
SUB RA RB
-- add one to register C
INC RC
-- if greater than jump to SUB
JP GT 02
-- stop execution
HALT

Explanation time. First we set register C to zero using the load command. Then we subtract A from B, the result of this operation will be in A. For example if we subtract 10 from 100 the value in A will be 90. Then we increment register C, which means we add one to whatever was there. In this case, zero. Then we check to see if the last subtraction that was done ended up less than zero. If not, which means A was still greater than B, we jump 2 instructions back to the SUB command and resume execution there. And the process repeats.

The 10th time we do this though the value in A will be less than B which means the jump back command will not run and the computer will go on to the next command which is halt and register C now contains the answer.

To be clear, this is an oversimplification and there are cases where the above code would fail but we won't get into that.

Now almost no developers actually write code like this. Nowadays we have compilers and languages that are very close to the English language but under the hood all code is compiled down to byte sized instructions that the computer executes one after another to do what needs to be done.

For example in java-script the code would be written like this.

let A = 100;
let B = 10;
let C = A / B;

Have fun thinking about all this the next time you use a computer. ;-)