“Under the hood”
Learn what’s happening inside your computer to gain a better understanding of our increasingly technological world!
How computers work
A Tampa Devs meetup
on November 15, 2023
Presented by Joey de Villa,
Senior Developer Advocate @ Okta
How computers work
2 UP 003200
TAMPA DEVS
A look at
the inner workings of computers�by way of time travel
to the 1980s
Joey deVilla, November 15, 2023
1 UP 25000
Open browser windows to:
Open browser windows to:
Drinks sponsor!
Pizza sponsor!
Big cloud provider #1
Big cloud provider #2
7
© 2023 | Percona
Joey de Villa
AI attempt to illustrate an anime accordion player.�It’s wrong on so many levels.
linkedin.com/in/joeydevilla
Cosmac Elf
The Raspberry Pi of the 1980s
What will you get out of this presentation?
Will this make you a better techie?
Will you understand tech a little better?
Will this give you an edge?
A thought exercise from
the 20th century…
How many electric motors do you have at home?
Probably more than you think!
A thought exercise for
the 21st century…
How many processors do you have at home?
Intel Core
(a lot of computers)
Apple Silicon
(Apple hardware)
Snapdragon/Exynos
(Android devices)
You (indirectly) use chips like these every day. �Have you ever wondered how they work?
25 billion
37 billion
92 billion
How many transistors
in Apple’s newest chips?
But what is a transistor, anyway?
Short answer: It’s an electronic component that uses electricity to control electricity.
Before the transistor: the vacuum tube!
There’s also the mechanical relay
Many brilliant technologists are one lab accident away from becoming a supervillain.
Hey, it was the 1960s…
Iron Man used to be all about transistors!
Ah, 1960s racist stereotypes…
We need to bring back Iron Man’s roller skates
The transistor’s “birthday” was almost 76 years ago.
The first successful transistor demo was made in Bell Laboratories in Murray Hill, New Jersey on December 23, 1947.
It looked janky AF.
So janky!
Full-sized transistors are everywhere
You’ll typically find them in devices that need to either:
See those three-pronged thingies in the photo? Those are transistors.
What do transistors do?
⚡️
Current can’t flow from
C (collector) to
E (emitter)
until a minimum amount of current is applied to
B (base).
Transistors can be used as switches or amplifiers.
Inside computer chips, they’re used�as switches.
Just as a wall-mounted lightswitch uses a physical object to control the flow of electricity…
…a transistor uses electricity to control the flow of electricity!
C
B
E
What do transistors do?
⚡️
Current can’t flow from
C (collector) to
E (emitter)
until a minimum amount of current is applied to
B (base).
Transistors can be used as switches or amplifiers.
Inside computer chips, they’re used�as switches.
Just as a wall-mounted light switch uses a physical object to control the flow of electricity…
…a transistor uses electricity to control the flow of electricity!
Circuit symbol for a transistor
Here’s another way to look at the transistor — the shower analogy!
Think of the collector (C) as the source of hot water.
Think of the emitter (E) as the shower head.
Think of the base (B) as the shower faucet.
B controls how much water from C goes through E.
The transistor�“shower” analogy
0
1
0
1
false
true
false
true
BELOW a threshold voltage, we consider a transistor’s output to be…
ABOVE that threshold voltage, we consider a transistor’s output to be…
💦
A single switch can be 0 or 1
0
1
A single transistor can represent the number 0 by being in the OFF state…
…and the number 1 by being in the ON state:
0 and 1 are binary digits. We often shorten binary digits to the word “bits.”
JavaScript coders, answer this!
false && false = ???
false && true = ???
true && false = ???
true && true = ???�
Two of them:
&&
&& means “logical AND”
false && false = false
false && true = false
true && false = false
true && true = true�
! means “logical NOT”
!(false && false) = ???
!(false && true) = ???
!(true && false) = ???
!(true && true) = ???�
!(A && B) means “NOT (A AND B)”
!(false && false) = true
!(false && true) = true
!(true && false) = true
!(true && true) = false�
…or as we call it, “NAND”
!(false && false) = true
!(false && true) = true
!(true && false) = true
!(true && true) = false�
out
Here’s the hardware version of NAND, a.k.a. A “NAND gate.”
Vcc just means “the + side of the battery”
“Ground” just means “the - side of the battery”
The “R” components are resistors.
Without them, you’re effectively connecting the + and - sides of the battery directly. That’s called a short circuit.
A | B | out |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
What it looks like on a circuit board
The NAND gate symbol
The 4011 quad NAND chip
You can make all the standard boolean logic gates simply by using one or more NAND gates!
AND gate
NOT gate
OR gate
With 5 NAND gates, you can create a “D flip-flop.”
The only thing you should take away from this is this arrangement of 5 NAND gates stores �1 bit of information:
either a 0 or a 1.
A byte is a group of 8 bits
0
0
0
0
1
1
1
1
×
×
×
×
×
×
×
×
20
21
22
23
24
25
26
27
64
16
4
1
64 + 16 + 4 + 1 = 85
8 flip-flops can store one byte
As a point of reference:
🅰️ The ASCII characters — the letters, numbers, and� characters we typically use in English —� take up only one byte each.
💩 Most emoji take up three bytes each.
💻 The bare minimum recommended amount of
RAM for development today is 8 MB —� 8 million bytes (and they’re 32- or 64-bit “bytes!”).
With 36 NAND gates, you can add two 4-bit numbers.
You need two of these to add two bytes together;
four to add two 16-bit numbers,
and sixteen to add two 64-bit numbers.
Combine enough circuits that can store 0s and 1s…
…with enough circuits that can perform operations on 0s and 1s…
…and you get…
The microprocessor!
Intel 4004
The Busicom 141-PF calculator (1972)
1975
1975
You can tell there was a gas shortage then — just look at those absurdly high prices!
The only desktop computer on the market was the Altair 8800:
$439 kit
($2418 today)
$621 assembled
($3420 today)
Steve “Jerk” Jobs
This chip helped kick-start the personal computer revolution…
…and a lot of computer careers�(including mine!)
Ken Olsen,
Founder of Digital Equipment Corporation, 1977
“There is no reason anyone would want a computer in their home.”
1977
1977
Three home computers (or “personal computers”) were released that year…
Commodore PET
Apple ][
Radio Shack TRS-80
Computer hardware isn’t all that different from the 1970s.
Steve “Woz” Wozniak
Steve “Jerk” Jobs
The Apple I computer
The updated 6502 is still in use today!
Input devices
1
Toys
3
Monitors
2
Other devices
4
As embedded processors in keyboards and mice
Many toys, including toy computers and the Furby use the 6502
They “draw” the on-screen controls for settings
These include digital picture frames, dedicated MP3 players, and more
Today’s computer chips contain billions of miniature transistors!
The 6502 gets by with a mere 4,528 transistors.
That’s about a million times fewer transistors than today’s simplest chips.
What’s the deal with
hexadecimalnumbers?
#FF0000
What color does this value represent?
#FF0000
What color does this value represent?
#00FF00
What color does this value represent?
#00FF00
What color does this value represent?
#0000FF
What color does this value represent?
#0000FF
What color does this value represent?
#FFFFFF
{
{
{
Amount of
red
Amount of
green
Amount of
blue
11111111
11111111
11111111
A hexadecimal digit is just a group of four binary numbers!
Amount of
red
Amount of
green
Amount of
blue
{
{
{
F F
F F
F F
| Binary | Hexadecimal |
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
| Binary | Hexadecimal |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
The deep dark “under the hood” secret of computers
All they do is read and write numbers to and from little slots that we call “memory…”
…they just do it very, very quickly!
Address | Data |
0600 | a9 |
0601 | 01 |
0602 | 8d |
0603 | 00 |
0604 | a9 |
0605 | 05 |
0606 | 8d |
0607 | 01 |
0608 | 02 |
0609 | a9 |
060a | 08 |
060b | 8d |
060c | 02 |
060d | 02 |
CPUs “see” the world�as memory.�
Think of memory as a giant array or a very long spreadsheet column of numbers.
The 6502 sees the world as a spreadsheet column with 65,536 cells.
The number of the cell is its address. For the 6502, the addresses range from 0000 through FFFF, or 0 to 65,535 in decimal.
The number inside each cell is its data. For the 6502, the possible values for data range from 00 through FF, or 0 to 255 in decimal.
In this example, we say that the address 0606 contains the data 8D.
These aren’t just random numbers. This is an actual program you’ll run soon!
In computer engineering, a bus is the “wiring” that connects the CPU to the other hardware components.
The 6502 has 16 of its pins, A0 - A15, dedicated to the address bus.
The 6502 has 8 of its pins, D0 - D7, dedicated to the data bus.
16 pins makes for 16 binary digits, which can represent the numbers 0 through 65,535.
8 pins makes for 8 binary digits, which can represent the numbers 0 through 255.
R/W means “read/write”.�0 = write (data is going out of the processor)
1 = read (data is going into the processor)
Everything that a CPU can connect to has an address!
Everything that the CPU can connect to has a data value,
which can represent:
RAM:
For applications and their data
ROM:
For the programs that tell the computer how to be a computer
CPU:
The brains of the operation
INTERFACE CHIP:
Go-between for the CPU and other devices
Keyboard
Mouse
Display
Hard drive
Internet
Ports
When the CPU READS a memory location
…then sets the current on each address bus wire so that it forms the binary number for the address of that memory location…
…and then reads the current on each data bus wire, which forms the binary number for the value at that address.
It sets the read/write wire to “read”...
When the CPU WRITES TO a memory location
…then sets the current on each address bus wire so that it forms the binary number for that address…
It sets the read/write wire to “write”...
…and then sets the current on each data bus wire so that it forms the binary number to be written at that address.
Everything is an address and a value
Every pixel on your screen is a memory address, and the color of each pixel is determined by the data at that address.
The RAM that holds all the currently running programs is a big collection of memory addresses and their values.
The sound chip on your computer has a memory address that stores the set of numbers that represent sound.
Registers are a CPU’s variables
Register
Register
Register
Registers are single memory locations built into the microprocessor.
Because they’re built-in, the microprocessor can access them very quickly.
The CPU uses them to perform operations like addition, subtraction, and comparison. You might want to think of them as a CPU’s variables.
The 6502 has 3 registers for data
00 - FF
Accumulator
00 - FF
X
00 - FF
Y
The 6502 has 3 registers for data:
The 6502 has 3 other registers
00 - FF
Program counter
00 - FF
Status
00 - FF
Stack pointer
The 6502 has the 3 other registers:
A closer look at the status register
N | V | | B | D | I | Z | C |
Negative | oVerflow | unused | weird Barbie | Decimal | Interrupt disable | Zero | Carry |
This bit is 1 when the result of the most recent operation is “negative” — that is, if its leftmost bit (bit 7) is 1; otherwise its value is 0.
This bit is 1 when the result of the most recent operation is outside the range of -128 to +127; otherwise its value is 0.
This bit is 1 when interrupt stuff happens; otherwise its value is 0. I never used this when I was coding in 6502 assembly.
Set this bit to do binary-coded decimal (BCD) math, which makes doing base 10 operations easier.
Set this bit to disable all interrupts except non-maskable interrupts (NMIs).
This bit is 1 when the result of the most recent operation is 0; otherwise, this bit is 0.
This bit is 1 when the result of the most recent operation involves “carrying the 1;” otherwise this bit is 0.
Open browser windows to:
Open browser windows to: