1 of 99

“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

2 of 99

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

3 of 99

  • 6502.cdot.systems
  • globalnerdy.com/6502
  • globalnerdy.com/6502slides

Open browser windows to:

Open browser windows to:

4 of 99

Drinks sponsor!

Pizza sponsor!

5 of 99

Big cloud provider #1

Big cloud provider #2

6 of 99

7 of 99

7

© 2023 | Percona

8 of 99

9 of 99

Joey de Villa

AI attempt to illustrate an anime accordion player.�It’s wrong on so many levels.

  • Senior Developer Advocate @ Auth0 by Okta
  • Publisher of weekly tech events list at�GlobalNerdy.com.
  • Co-organizer of Tampa AI Meetup, Apple Coders Meetup, and Coders, Creatives, and Craft Beer.�
  • Went to high school in the 1980s, where they had Commodore PET and Apple ][ computers.
  • Learned a lot about software and hardware at a computer store in Toronto that let me hang out and use their computers if I answered customer questions.�
  • Teaching an online Python programming course for Computer Coach starting Monday, Nov. 27.

linkedin.com/in/joeydevilla

10 of 99

Cosmac Elf

The Raspberry Pi of the 1980s

11 of 99

12 of 99

13 of 99

What will you get out of this presentation?

14 of 99

Will this make you a better techie?

15 of 99

Will you understand tech a little better?

16 of 99

Will this give you an edge?

17 of 99

A thought exercise from

the 20th century…

How many electric motors do you have at home?

18 of 99

Probably more than you think!

19 of 99

A thought exercise for

the 21st century…

How many processors do you have at home?

20 of 99

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?

21 of 99

25 billion

37 billion

92 billion

How many transistors

in Apple’s newest chips?

22 of 99

But what is a transistor, anyway?

23 of 99

Short answer: It’s an electronic component that uses electricity to control electricity.

24 of 99

Before the transistor: the vacuum tube!

25 of 99

There’s also the mechanical relay

26 of 99

27 of 99

28 of 99

Many brilliant technologists are one lab accident away from becoming a supervillain.

29 of 99

Hey, it was the 1960s…

Iron Man used to be all about transistors!

30 of 99

Ah, 1960s racist stereotypes…

31 of 99

We need to bring back Iron Man’s roller skates

32 of 99

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!

33 of 99

Full-sized transistors are everywhere

You’ll typically find them in devices that need to either:

  • Amplify electrical power, e.g. sound systems, including the speakers in your laptop and phone
  • Electronically switch power on and off, e.g. the power switch in your laptop and phone

See those three-pronged thingies in the photo? Those are transistors.

34 of 99

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

35 of 99

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

36 of 99

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

37 of 99

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…

💦

38 of 99

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.”

39 of 99

JavaScript coders, answer this!

false && false = ???

false && true = ???

true && false = ???

true && true = ???

Two of them:

&&

40 of 99

&& means “logical AND”

false && false = false

false && true = false

true && false = false

true && true = true

41 of 99

! means “logical NOT”

!(false && false) = ???

!(false && true) = ???

!(true && false) = ???

!(true && true) = ???

42 of 99

!(A && B) means “NOT (A AND B)”

!(false && false) = true

!(false && true) = true

!(true && false) = true

!(true && true) = false

43 of 99

…or as we call it, “NAND”

!(false && false) = true

!(false && true) = true

!(true && false) = true

!(true && true) = false

44 of 99

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

45 of 99

What it looks like on a circuit board

46 of 99

The NAND gate symbol

47 of 99

The 4011 quad NAND chip

48 of 99

You can make all the standard boolean logic gates simply by using one or more NAND gates!

AND gate

NOT gate

OR gate

49 of 99

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.

50 of 99

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

51 of 99

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!”).

52 of 99

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.

53 of 99

Combine enough circuits that can store 0s and 1s…

…with enough circuits that can perform operations on 0s and 1s…

…and you get…

54 of 99

The microprocessor!

55 of 99

56 of 99

Intel 4004

  • The world’s first commercially produced microprocessor
  • Released on November 15, 1971that’s right, today is its 52nd birthday!
  • Made specifically for…

57 of 99

The Busicom 141-PF calculator (1972)

58 of 99

59 of 99

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)

60 of 99

Steve “Jerk” Jobs

This chip helped kick-start the personal computer revolution…

…and a lot of computer careers�(including mine!)

61 of 99

62 of 99

Ken Olsen,

Founder of Digital Equipment Corporation, 1977

“There is no reason anyone would want a computer in their home.”

63 of 99

1977

1977

Three home computers (or “personal computers”) were released that year…

Commodore PET

Apple ][

Radio Shack TRS-80

64 of 99

Computer hardware isn’t all that different from the 1970s.

Steve “Woz” Wozniak

Steve “Jerk” Jobs

The Apple I computer

65 of 99

66 of 99

67 of 99

68 of 99

69 of 99

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

70 of 99

71 of 99

72 of 99

Today’s computer chips contain billions of miniature transistors!

73 of 99

The 6502 gets by with a mere 4,528 transistors.

That’s about a million times fewer transistors than today’s simplest chips.

74 of 99

What’s the deal with

hexadecimalnumbers?

75 of 99

#FF0000

What color does this value represent?

76 of 99

#FF0000

What color does this value represent?

77 of 99

#00FF00

What color does this value represent?

78 of 99

#00FF00

What color does this value represent?

79 of 99

#0000FF

What color does this value represent?

80 of 99

#0000FF

What color does this value represent?

81 of 99

#FFFFFF

{

{

{

Amount of

red

Amount of

green

Amount of

blue

82 of 99

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

83 of 99

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

84 of 99

The deep dark “under the hood” secret of computers

85 of 99

All they do is read and write numbers to and from little slots that we call “memory…”

…they just do it very, very quickly!

86 of 99

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!

87 of 99

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)

88 of 99

Everything that a CPU can connect to has an address!

  • Every memory location in ROM and RAM
  • Every pixel on the screen
  • The speaker
  • The keyboard and mouse
  • The drives
  • Every port

Everything that the CPU can connect to has a data value,

which can represent:

  • All or part of a machine code instruction
  • A number
  • A text character (or part of one)
  • A color
  • A very small part of a sound
  • A very small part of a file being read from/written to a drive
  • A very small part of data being read from/written to the network

89 of 99

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

90 of 99

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”...

91 of 99

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.

92 of 99

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.

93 of 99

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.

94 of 99

The 6502 has 3 registers for data

00 - FF

Accumulator

00 - FF

X

00 - FF

Y

The 6502 has 3 registers for data:

  • Accumulator:�For reading and writing data to and from memory, and also for most arithmetic and comparison operations.
  • X and Y:�For reading data to and from memory, a little math, and for indexing (think arrays) and iterating (think loops).

95 of 99

The 6502 has 3 other registers

00 - FF

Program counter

00 - FF

Status

00 - FF

Stack pointer

The 6502 has the 3 other registers:

  • Program counter:�Contains the address of the instruction to run.
  • Status:�Contains a number representing the outcome of the previous instruction.
  • Stack pointer:�Contains the address of the next free space in the stack (I’ll explain in a bit).

96 of 99

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.

97 of 99

98 of 99

  • 6502.cdot.systems
  • globalnerdy.com/6502
  • globalnerdy.com/6502slides

Open browser windows to:

Open browser windows to:

99 of 99

Thanks!

Do you have any questions?

joey@joeydevilla.com

joey.devilla@okta.com

globalnerdy.com

Please keep this slide for attribution

CREDITS: This presentation template was created by Slidesgo, including icons by Flaticon, infographics & images by Freepik and illustrations by Storyset.