Last time, I introduced the microcontroller and its instructions, registers, and memory. I started with a simple fictional microcontroller and ran through a few examples of how its instructions worked. The microcontroller ran instructions when I said “let’s run this ADD instruction now.” But of course a real microcontroller doesn’t have someone feeding it instructions as it runs, so it has to get the instructions from somewhere. This post will make our fictional microcontroller more realistic by answering the question, “Where does a microcontroller get instructions from?”

The short answer is: That somewhere is memory. Read on to learn more!

When a microcontroller powers up it looks in a defined memory location for the first instruction to run. It runs that first instruction, and then looks at the next memory location for the second instruction, runs it, and so on.

Let’s make this more concrete using our ADD, SUB, and MOVE instructions from last time.

For this example we'll assume that each instruction is two bytes long. So if an ADD instruction starts at memory location zero, it occupies memory locations zero and one. For example, memory might look like this: