Transcript
Here's a sixteen-bit number. In memory, it could be a color or a letter. But when the processor reads it as an instruction, it means: add register two to register one. Today: how numbers become commands.
Every processor has a fixed list of things it can do, called its instruction set. Each instruction has its own code number. Let's make up a tiny one. Our instructions are sixteen bits long, cut into fields. The first four bits are the opcode: which operation to do. Zero zero one zero means add. The next two bits pick a register, and the two after that pick a second register. Our processor has four, numbered zero to three. The last eight bits hold a number or a memory address, when the instruction needs one. Writing ones and zeros is painful, so people write a short name instead: ADD R1, R2. That's called assembly language. A program called an assembler turns it back into numbers.
There are a few ways for an instruction to say where its data comes from. They're called addressing modes. Immediate: the number is inside the instruction itself. LOAD R1, five puts five straight into register one. Register: the data is already in registers. ADD R1, R2 adds the two registers. Direct: the instruction holds a memory address. LOAD R1, from address twelve, fetches whatever is stored in memory cell twelve. Indirect: a register holds the address. LOAD R1, from the address in R2. Change R2, and the same instruction reads a different cell. That's how a program walks through a list.
A program is just these numbers, one after another in memory. Here's one that adds five and three, and stores the answer in cell fifteen. Load five. Load three. Add. Store. Four instructions, sixty-four bits.
Real instruction sets come in two main styles. RISC, a reduced instruction set, keeps every instruction simple: the same length, one small job each. CISC, a complex instruction set, has many more instructions. Some are long, and one instruction can do several steps, like loading from memory and adding, in one go. Phones, and many newer laptops, use RISC designs. Most desktop PCs use a CISC design, though inside, the chip breaks big instructions into small, simple steps anyway.
So: an instruction is a number with fields, an opcode and where to find its data. A program is a list of them. But who reads these numbers one by one, and actually carries them out? Next time: how the CPU runs a program. See you there.
Next episode: how a CPU actually runs a program. Fetch, decode, execute.