hello-world-machine

The life of Olá, Mundo!

← → on the keyboard; one step per screen

read assigns
phraseO
key79
number79
bits01001111
the áC3 A1
relayseight switches
count+1 = P
address0109
orderCD 05 00
wordCALL 5
lightpoints
loopconserves

before everything · how to read the symbols on this page

Seven signals, and how each is read

Each expression on this page comes with the reading aloud right below. This sheet says what each type of signal is.

number(o)

name in straight letters, with parentheses: a rule with a name, applied to what is inside the parentheses. read as: number of o.

v, t

slanted lowercase letter: a quantity that varies. read as: see, have.

st

index below: at which instant, or at which position. read as: ess at instant tee.

28

small number on top: how many times to multiply the number by itself. read as: two to the eighth.

(79 + 1) mod 256

mod: the remainder of division by. read as: seventy-nine plus one, modulo two hundred and fifty-six.

signals → meanings

arrow between two sets: a rule that takes each thing from the left to a thing on the right. read as: takes signals into meanings.

4F

number in hexadecimal: a number written with the digits from 0 to 9 and the letters from A to F, which are worth 10 to 15. read as: four-ef, which is seventy-nine.

No sign appears before it is on this sheet. In every step, the new words come explained before they appear. Where the symbol is shorter than the sentence, the sentence wins.

0 · before any machine

The sentence is already a code.

Saying Olá, Mundo! out loud is a code. Writing it is another. Blinking a flashlight is a third.

before, the words of this step

signal

  • What it is: anything that can be perceived: a sound, a mark on paper, a light turned on.
  • Why it exists: it's what travels from the speaker to the listener; the message itself doesn't travel alone.

code

  • What it is: a combination about what each signal means.
  • Why it exists: for the message to cross a medium that is not the voice: paper, light, wire.
CODE 1 · VOICECODE 2 · PAPERCODE 3 · LANTERN Olá, Mundo! Olá, Mundo! sound in the airline on the sheetonly two signals: short and long
Petzold, ch. 1

Code here is not a secret: it's an agreement about what each signal means. Changes the medium, stays the message. The lantern already forces a choice: two types of blinking, and nothing more.

see it on the board → ola-mundo, cycle 1: the first step: the machine wakes up and goes to fetch what it has to do

the math here · one-to-one correspondence

code: signals → meanings

read as: code assigns each signal a single meaning, and it's reversible.

where this comes from
Charles Petzold · ch. 1 — Best Friends
In this book, the word code usually means a system for transferring information among people, between people and computers, or within computers themselves.Neste livro, a palavra código geralmente significa um sistema para transferir informação entre pessoas, entre pessoas e computadores, ou dentro dos próprios computadores.cap. 1 — Best Friends

½ · key → number

The key becomes a number

Pressing the key O closes a switch. The machine looks at a special drawer, number 8200, and finds 79. The key turned into a number.

before, the words of this step

switch

  • What it is: a part that opens or closes a path. The light switch is a switch; so is every key.
  • Why it exists: to turn something on or off with a touch.

drawer

  • What it is: a place inside the machine where a number fits, with a number at the door to be found again.
  • Why it exists: the machine cannot see the key; it only knows how to look at drawers. The keyboard leaves its number in one of them.
TECLA · a switch that the finger closes · the drawer 8200h stores the code O the key closed switch = passes 8200h 4F the keyboard drawer LDA 8200h A 4F inside the machine 79 is the O; 0 is “nobody pressed”. The machine looks at the drawer all the time: check the keyboard.
Petzold, chap. 25

The machine looks at the drawer all the time and almost always finds zero: no one pressed it. The book calls this checking the keyboard. When it finds 79, it copies to the screen and zeros the drawer, ready for the next key.

see on the board → echo, cycle 22: the drawer 8200 delivers the 79 to the machine; ten steps later it is on the screen

the math here · a rule of time in numbers: 0 while releasing, the code while pressed

key(t) = 79 while the O is pressed, and 0 afterwards

read as: key of tee equals seventy-nine while the O is pressed, and zero afterwards.

where this comes from
Charles Petzold · ch. 25 — Peripherals
The accumulator would then contain a code indicating what key has been pressed.O acumulador passaria então a conter um código indicando qual tecla foi apertada.cap. 25 — Peripherals
It's tempting to assume that this code is the ASCII code for the key. But it's neither practical nor desirable to design hardware that figures out the ASCII code.É tentador supor que esse código é o código ASCII da tecla. Mas não é prático nem desejável projetar hardware que descubra o código ASCII.cap. 25 — Peripherals
One approach is for the program to check the keyboard very frequently. This approach is called polling.Uma abordagem é o programa consultar o teclado com muita frequência. Isso se chama polling.cap. 25 — Peripherals

1 · letter → number

Each letter receives a number

The O is 79. The l is 108. The comma is 44 and the space, 32. The sentence becomes a line of eleven numbers.

before, the words of this step

table

  • O que é: a list in which each letter has its number next to it, like a roll call.
  • Why it exists: the machine only stores numbers; the table is the combination that says which number is which letter.

the table: the same combination in every machine on the planet

letterOlá,␣Mundthe!
number7910822544327711711010011133
Petzold, ch. 13

There is nothing of O in the 79. It's a position in a table that the whole world agreed to use. That's why the same O is 79 in any machine.

see on the board → ola-mundo, cycle 8: the number 79, written 4F, which is the letter O, arrives at the machine

the math here · one-to-one correspondence between letters and numbers

number(O) = 79

read as: number of O is equal to seventy-nine.

where this comes from
Charles Petzold · ch. 13 — From ASCII to Unicode
The biggest advantage of UTF-8 is that it's backward compatible with ASCII. This means that a file consisting solely of 7-bit ASCII codes stored as bytes is automatically a UTF-8 file.A maior vantagem do UTF-8 é ser compatível com o ASCII: um arquivo só de códigos ASCII de 7 bits, guardados como bytes, já é automaticamente um arquivo UTF-8.cap. 13 — From ASCII to Unicode

2 · number → bits

Each number becomes eight places of yes or no

79 becomes 01001111. Eight places, each one only 0 or 1. Eight places can hold 256 different things.

before, the words of this step

house

  • What it is: a position in the writing of a number. In 79, the 7 is in one place and the 9 in another.
  • Why it exists: the place is what says how much each digit is worth: the 7 in 79 is worth seventy.

bit

  • What it is: a place that only accepts 0 or 1.
  • Why it exists: it is the smallest amount of information there is, and it is what a switch can hold: off or on.

byte

  • What it is: eight bits side by side.
  • Why it exists: it is the size of one letter, and the chunk the machine moves at a time.
ONE BYTE = EIGHT BITS · each place is worth double its neighbor 1286432168421 0 1 0 0 1 1 1 1 64 + 8 + 4 + 2 + 1 = 79 = O bit = a house · the painted houses add up, the empty ones don't count
Petzold, caps. 11 and 12

It is the same idea as 79 = 70 + 9, except that each place is worth double its neighbor, not ten times. 256 is the number of combinations, not a size.

see on the board → ola-mundo, cycle 9: the eight points of the data row, lit and unlit: 0 1 0 0 1 1 1 1

the math here · positional notation in base two

79 = 64 + 8 + 4 + 2 + 1

read as: seventy-nine equals sixty-four, plus eight, plus four, plus two, plus one.

28 = 256

read as: two to the eighth equals two hundred and fifty-six: the size of the set of lists of eight zeros or ones.

where this comes from
Charles Petzold · ch. 11 — Bit by Bit by Bit · ch. 12 — Bytes and Hexadecimal
As an 8-bit quantity, a byte can take on values from 00000000 through 11111111, which can represent decimal numbers from 0 through 255, or one of 28, or 256, different things.Como quantidade de 8 bits, um byte vai de 00000000 a 11111111, o que representa os números de 0 a 255, ou uma entre 2⁸, isto é, 256, coisas diferentes.cap. 11 — Bit by Bit by Bit · cap. 12 — Bytes and Hexadecimal

2½ · the step that the character brought

The á does not fit in a byte

225 is greater than 127, and the original agreement only had 128 letters, without an accent. The á costs two bytes.

starting with 110 and 10 is the mark of "comes in pairs"; the 0 in front of o says "comes alone"

letterbytesin bits
O101001111
l101101100
á211000011 10100001
Petzold, ch. 13

Eleven letters, twelve bytes. Byte is not a letter: a letter can cost one, two, three, or four. Whoever counts bytes to count letters makes a mistake, and the whole web has already made this mistake.

see it on the board → ola-mundo, cycle 19: on this machine’s screen the á fits in a single byte, E1; the two bytes belong to the file

the math here · code of variable length, without any word being the start of another

bytes(o) = 1, bytes(á) = 2

read as: bytes of o equals one; bytes of á equals two.

where this comes from
Charles Petzold · ch. 13, com o £ (U+00A3) como exemplo; o á (U+00E1) está na mesma faixa
Thus, in UTF-8 the two bytes C2h and A3h represent the British £ sign. It seems a shame to require 2 bytes to encode what is essentially just 1 byte of information, but it's necessary for the rest of UTF-8 to work.Assim, em UTF-8 os dois bytes C2 e A3 representam o sinal de libra. Parece pena gastar 2 bytes para codificar o que é essencialmente 1 byte de informação, mas é necessário para o resto do UTF-8 funcionar.cap. 13, com o £ (U+00A3) como exemplo; o á (U+00E1) está na mesma faixa
here it stops being written and becomes electricity

3 · bit → current

Each place becomes current in a relay

A 1 is current flowing; a 0 is current stopped. Eight relays in a row hold the O; ninety-six hold the phrase.

before, the words of this step

current

  • What it is: electricity moving through a wire, like water moving through a pipe.
  • Why it exists: it is what makes the lamp light up, the motor turn and, here, the switch flip.

relay

  • What it is: a switch that a current activates: the current of one wire closes the path of another.
  • Why it exists: it is the first piece that allows a chain to control another, without any finger.

threshold

  • What it is: the line that separates little from much. Above it the current counts as 1; below it, as 0.
  • Why it exists: the current is never exactly the same; the line is what makes two different values become the same signal.
RELAY · closed switch = current = 1 · open switch = 0 0 1 0 0 1 1 1 1
Petzold, chs. 7 and 8

The number is not in the relay. The relay only knows how to pass or not pass; we are the ones who agreed that passing is worth 1. Eight relays, eight places: the whole O fits in one row. How relays become gates and arithmetic is the story of the other page, the ladder.

view on the board → ola-mundo, cycle 9: each lit point in the row is a wire with current passing

the math here · threshold: an entire interval of voltages becomes a single symbol

bit(v) = 1 if v ≥ 2 volts, and 0 if v ≤ 0.8 volt

read as: bit of see is equal to one if see is greater than or equal to two volts, and equal to zero if see is less than or equal to zero point eight volt.

where this comes from
abstraction-ladder — the ladder of abstractions · electromagnet → relay (Petzold chap. 7) · relay → logic gate (chap. 8), with the tool “two relays become one gate”
These two relays wired in series are known as an AND gate because it is performing a Boolean AND operation.Esses dois relés ligados em série são conhecidos como porta AND, porque executam a operação booleana E.eletroímã → relé (Petzold cap. 7) · relé → porta lógica (cap. 8), com o instrumento “dois relés viram uma porta”

4 · current → count and remember

The bits learn to add and to stay still.

Ports connected in one way sum two bytes. Connected in another, hold a bit after the input sums.

before, the words of this step

logic gate

  • What it is: a piece made of switches that responds yes or no to what comes to it. Two switches in a row only allow current with both closed: it's a gate.
  • Why it exists: with yes-or-no questions linked together, you build a calculation.

state

  • What it is: the way a piece is now: what it holds at this moment.
  • Why it exists: a piece that remembers its state; one that only responds no does not.
ADDER · does calculation 01001111 + 00000001 = 01010000 = P THE PIECE THAT REMEMBERS entered 1, the input disappeared, the output stays 1
Petzold, caps. 14, 17, 19 to 21

Adding 1 to O gives P, the next letter: the table was made for this to work. Now the number can be operated on and can wait. Remembering is what allows the next step.

see it on the board → ola-mundo, cycle 11: one part holds where the machine is and another adds 1: remembering and counting

the math from here · arithmetic modulo 256, and state that depends on the previous one

(79 + 1) mod 256 = 80

read as: seventy-nine plus one, modulo two hundred and fifty-six, is equal to eighty.

st+1 = f(st, xt)

read as: the state at instant tee plus one is f of: the state at instant tee, and the input at instant tee.

where this comes from
abstraction-ladder — the abstraction ladder · gate → adder (cap. 14) · gate → flip-flop (caps. 17 and 19) · edge-triggered flip-flop → counter and register (cap. 20) · adder → ALU (cap. 21)
A half adder is an XOR gate and an AND gateUm meio-somador é uma porta XOR e uma porta AND.porta → somador (cap. 14) · porta → flip-flop (caps. 17 e 19) · flip-flop de borda → contador e registrador (cap. 20) · somador → ULA (cap. 21)

5 · byte → address

Each byte gets a place with a number

Memory is a row of drawers, each with a number on the door. The O is in drawer 0109; the l, in 010A.

before, the words of this step

memory

  • What it is: many drawers in a row, each with a byte inside.
  • Why it exists: to keep the entire sentence stored while the machine works on it, one letter per drawer.

address

  • What it is: the number on the door of a drawer.
  • Por que existe: to find again what was stored, without searching drawer by drawer.
DRAWER · inside, the content · on the door, the address 4F0109O 6C010Al C3010Bá A1010C· 2C010D, 20010E␣ 4D010FM 750110u 6E0111n 640112d 6F0113o 210114! 4F is 79 in hexadecimal: eight bits shortened to two symbols · the á takes two neighboring drawers
Petzold, chapter 19

Now there are two numbers per letter: what it's worth and where it is. The order of the letters has become the order of addresses. Reading the sentence is like going through neighboring drawers.

see it on the board → ola-mundo, cycle 9: the machine points to drawer 8000 and stores the 4F in it

the math of here · memory is a rule that takes each address to a byte

mem(0109) = 4F

read as: mem of zero, one, zero, nine is equal to four-efe, which is worth seventy-nine.

where this comes from
Charles Petzold · ch. 19 — An Assemblage of Memory
That's called writing to memory, and the value of Data In is said to be stored in memory at the address 010.Isso se chama escrever na memória, e diz-se que o valor da entrada fica guardado na memória no endereço 010.cap. 19 — An Assemblage of Memory
here it stops being a circuit and becomes a language

6 · number → order

A number is read as an order, not as a quantity.

In the same memory, next to the letters, live other bytes. CD is not a letter: it is the order “call”. C9 is “return”.

before, the words of this step

order

  • What it is: a number the machine reads as “do this”: add, copy, store, call, return. The book calls it an instruction.
  • Why it exists: without orders, the machine would only store numbers; it's the order that puts it to doing something with them.

program

  • What it is: a queue of orders, one after the other, stored in memory like any other thing.
  • Why it exists: it's like a person tells the machine what to do, all at once, so the machine can do it by itself.

program counter

  • What it is: a special drawer of the machine that stores the address of the next order.
  • Why it exists: so the machine knows which byte to read as an order now, and which comes next.
ORDERS · 9 bytesLETTERS · 7 bytes 11 09 01 0E 09 CD 05 00 C9 48 65 6C 6C 6F 21 24 load · move · call · return H e l l o ! $ PROGRAM COUNTER: walks only the blue side; the bronze side it points to, as data
Petzold, chapters 23 and 27

Nothing in the byte says if it is a letter or an order. What decides is where the program counter points, and that counter is also a number stored in the machine. The machine governs itself with the same material that governs.

see on the board → ola-mundo, cycle 7: the program counter points to drawer 0004 and byte 36 is read as order: store the letter

the math here · the machine is a step rule: from the state of now to the next

next = step(counter, A, mem)

read as: the next state is step of: the program counter, the number stored in A, and the memory.

where this comes from
Charles Petzold · ch. 27 — Coding · ch. 23 — CPU Control Signals
The first 3 bytes are the LXI instruction, the next 2 are the MVI instruction, the next 3 are the CALL instruction, and the next is the RET instruction. The last 7 bytes are the ASCII characters for the five letters of “Hello,” the exclamation point, and the dollar sign.Os 3 primeiros bytes são a instrução LXI, os 2 seguintes a MVI, os 3 seguintes a CALL, e o próximo a RET. Os últimos 7 bytes são os caracteres ASCII das cinco letras de “Hello”, o ponto de exclamação e o cifrão.cap. 27 — Coding · cap. 23 — CPU Control Signals
A value called the program counter. This is the 16-bit value that accesses instructions. It starts at 0000h and sequentially increases until a HLT instruction.Um valor chamado contador de programa. É o valor de 16 bits que acessa as instruções. Começa em 0000 e cresce em sequência até uma instrução HLT.cap. 27 — Coding · cap. 23 — CPU Control Signals

7 · words → orders

Someone writes the orders in words

No one memorizes that “call” is CD. You write CALL 5 in text, and the assembler replaces each word with the correct byte.

before, the words of this step

assembler

  • What it is: a program that reads a text with the orders written in words and replaces each word with the correct byte.
  • Why it exists: because a person remembers a word, and a machine only reads a number. Someone has to make the switch, and a program does it without error.

operating system

  • What it is: a program that already lives in the machine and provides services to other programs, like displaying text on the screen.
  • Why it exists: so each new program doesn’t need to know how the screen works.

assembler: one line, one order

what the person writeswhat it becomeswhat it does
LXI DE,Text11 09 01point to the sentence
MVI C,90E 09ask for service 9: show text
CALL 5CD 05 00call the system
RETC9return
DB 'Hello!$'48 65 6C 6C 6F 21 24the sentence, byte by byte
Petzold, ch. 27

This is where delegation begins: a person writes the intention, the machine executes. The operating system already knows how to perform services, like displaying text, so each program doesn’t need to know.

see on the board → ola-mundo, cycle 7: in the list next to it, MVI M, 'O' became 36 4F; the machine only sees the bytes

the math here · translation that preserves meaning

run(assemble(text)) = meaning(text)

read as: running what was assembled from the text gives the same as the meaning of the text.

where this comes from
Charles Petzold · ch. 27 — Coding
An assembler such as ASM.COM reads an assembly-language program (often called a source-code file) and writes out to a file containing machine code—an executable file.Um montador como o ASM.COM lê um programa em linguagem de montagem (o chamado arquivo-fonte) e escreve um arquivo com código de máquina: um executável.cap. 27 — Coding
here it stops being a number and goes back to being light

8 · execution → screen

The order turns into points of light.

The screen is also memory: each three bytes are a colored point. Showing the o is writing numbers in the correct drawers of that block.

before, the words of this step

pixel

  • What it is: a dot on the screen, too small to see on its own, with a single color.
  • Why it exists: the screen doesn’t draw letters; it lights up points, and the letter is what the points form together.
PIXEL · a point on the screen · three bytes: red, green, blue this pixel 16 23 3F each one from 0 to 255 screen of 1920 × 1080 points 1920 × 1080 × 3 = 6 220 800 bytes read 60 times a second
Petzold, chapters 12 and 25

Sixty times per second the screen reads the block and lights up. Olá, Mundo! returns to being something that we read, made of numbers. How the 79 becomes the drawing of the O is the next question, still without an answer on this page.

see it on the board → ola-mundo, cycle 59: the last letter enters the screen and the whole phrase is there, made of numbers

the mathematics here · a rule that takes each point of the grid to a color

color(3, 4) = 16 23 3F

read as: color of three and four is equal to one-six, two-three, three-ef: red, green, and blue.

where this comes from
Charles Petzold · ch. 25 — Peripherals · ch. 12 (pixel = três bytes)
The contents of the display are stored in a special block of memory, and the individual pixels of the display are refreshed sequentially, starting left to right with the row at the top, and continuing down the display.O conteúdo da tela fica guardado num bloco especial de memória, e os pixels são atualizados em sequência, da esquerda para a direita a partir da linha de cima, descendo pela tela.cap. 25 — Peripherals · cap. 12 (pixel = três bytes)
For a 1920 × 1080 display, each of the 2 million pixels requires 3 bytes for the red, green, and blue components, for a total of 6 million bytes, or 6 megabytes.Numa tela de 1920 × 1080, cada um dos 2 milhões de pixels precisa de 3 bytes, para o vermelho, o verde e o azul: 6 milhões de bytes, ou 6 megabytes.cap. 25 — Peripherals · cap. 12 (pixel = três bytes)

closing

At each step, one thing is conserved and one is forgotten

Mathematics refers to the world by what is conserved. Each layer is a promise: “You can forget the rest, this I guarantee.”

0 code

conserves the message; forgets the medium.

½ key → number

conserves the letter's code; forgets the switch, the finger.

1 letter → number

conserves which letter it is; forgets shape and sound.

2 number → bits

conserves the exact number; forgets the base ten.

2½ the á

conserves the letter and the 128 old ones; forgets “one byte, one letter”.

3 bit → current

keeps 0 and 1; forgets the physics.

4 count and memory

preserves arithmetic; forgets relays.

5 address

conserves the order of the letters; forgets the time.

6 number → order

conserves common matter; forgets “what to do” and “about what”.

7 words → orders

conserves the meaning; forgets the words.

8 order → light

keeps the recognisable shape; forgets the number.

The whole ladder is the chain of these promises, and execution is what's left when all have been fulfilled.

PT