We saw that Pong is built from a great many tiny yes/no decisions made by logic gates. Those gates are wired into counters, an adder, and small bits of memory that keep track of things like where the ball is. All of it was wired together in one fixed arrangement, so the result was an arcade machine that could play one game and only one game. How do we make a machine that can play Pong, or Pac-Man, or Space Invaders? It needs to be programmable.
The trick is to stop wiring circuits into a particular game. Instead, we build a small set of general-purpose circuits once and never change them: circuits to add, subtract, compare, copy a number from one place to another, and jump to a different step. A program is a list of instructions. Each instruction names one of these operations and the numbers it should use: "Add these two numbers. Store the result here. If the result is zero, go back to step 4." An adder that did one fixed job in Pong can now do any job a program gives it, in Pong or in Pac-Man.
The chip at the heart of the Arduino works exactly this way. Its arithmetic logic unit (ALU) is built from the same parts we saw in Pong. It has an adder like the one in Pong, and it uses that adder to subtract and compare as well. It also has AND and OR gates that combine numbers bit by bit. In Pong, each circuit was wired to one job. In the ALU, each one is available for any job. The chip also has 32 registers, each holding one number, where it keeps the numbers it's working on right now.
The chip has two kinds of memory. Flash memory holds the program, a long list of instructions, each just a pattern of 1s and 0s. A larger working memory (RAM) holds everything else the program needs to keep track of, like the ball's position or the score. The ALU can only work on numbers in registers, so to use a number from RAM, the chip first copies it into a register, does the arithmetic there, and copies the result back.
A counter like the ones in Pong, called the program counter, keeps track of which instruction comes next. The chip repeats one cycle, sixteen million times a second:
Fetch the instruction the program counter points to.
Decode it. The instruction's bits feed into a circuit called the decoder, which is itself made of logic gates. Its outputs act like switches. They open the paths that send two registers' numbers into the ALU, tell the ALU to add rather than subtract, and route the answer back to a register.
Execute. The numbers flow through the circuits that were just switched on. The program counter adds one, unless the instruction said to jump somewhere else.
Nothing gets rewired. The instruction's bits only set the switches for one step. The chip understands 131 instructions, many of them small variations on each other. Some tell the ALU what to do, some move numbers between registers and memory, and some jump to a different place in the program. Blinking an LED, playing Pong, and every other program anyone writes for this chip are all long sequences of those few steps.