hello-world-machine
← → on the keyboard; one step per screen
before everything · how to read the symbols on this page
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
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
code
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.
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
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
drawer
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.
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
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
the table: the same combination in every machine on the planet
| letter | O | l | á | , | ␣ | M | u | n | d | the | ! |
|---|---|---|---|---|---|---|---|---|---|---|---|
| number | 79 | 108 | 225 | 44 | 32 | 77 | 117 | 110 | 100 | 111 | 33 |
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.
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
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
bit
byte
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.
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
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"
| letter | bytes | in bits |
|---|---|---|
| O | 1 | 01001111 |
| l | 1 | 01101100 |
| á | 2 | 11000011 10100001 |
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.
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
3 · bit → current
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
relay
threshold
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.
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
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
state
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.
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
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
address
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.
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
6 · number → order
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
program
program counter
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.
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
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
operating system
assembler: one line, one order
| what the person writes | what it becomes | what it does |
|---|---|---|
| LXI DE,Text | 11 09 01 | point to the sentence |
| MVI C,9 | 0E 09 | ask for service 9: show text |
| CALL 5 | CD 05 00 | call the system |
| RET | C9 | return |
| DB 'Hello!$' | 48 65 6C 6C 6F 21 24 | the sentence, byte by byte |
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.
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
8 · execution → screen
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
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.
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
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.