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
andB
we want it to operate on
We call this bundle of data an instruction. A list of instructions might look something like this:
binary | meaning | |
---|---|---|
0 | 1010001011 | ADD 1 3 |
1 | 000101010 | SUBTRACT 27 4 |
2 | 110000101 | SUBTRACT 1 19 |
3 | 101001001 | ADD 40 44 |
… | … | … |
This is called a program.
The calculator knows how to perform two operations: ADD
and SUBTRACT
. This group of available operations is called the instruction set.
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