instructions

We’ve built a calculator that can dynamically switch between addition and subtraction. We send it two pieces of data:

  • An operation telling it to add or subtract
  • The numbers A and B we want it to operate on

We call this bundle of data an instruction. A list of instructions might look something like this:

binarymeaning
01010001011ADD 1 3
1000101010SUBTRACT 27 4
2110000101SUBTRACT 1 19
3101001001ADD 40 44

This is called a program.

definition

An instruction is a piece of data that commands a computer to do an action.
A program is a list of instructions.

The calculator knows how to perform two operations: ADD and SUBTRACT. This group of available operations is called the instruction set.

definition

The instruction set is the list of basic operations that a computer can do.

Everything that a computer does is just a combination of operations from its instruction set.

running a program

When we run a program:

  • The computer stores the program as a list of instructions.
  • It takes the first instruction and executes it.
  • It advances to the next instruction, and executes that, and so on.
  • Once it runs out of instructions, it stops.

Technically our calculator can run simple programs, but it doesn’t feel very computer-y yet. What’s missing?

For one thing, our instruction set is too small. Real computers typically have dozens of operations available. Think of the instruction set as the computer’s “toolbox” — to do anything interesting, we need to give it access to more tools, which we’ll do in the next tutorial.

continue