These 27 instructions are the only things the MSP430 microcontroller knows how to do. It can add two numbers, subtract two numbers, move numbers around, and 24 other simple operations. 27 different operations might not sound like enough to do anything useful, but it’s more than enough to run any conceivable program.

Okay, so a microcontroller has instructions that do something with numbers. But where are the numbers? Registers and memory! Instructions operate on numbers that are stored in registers and memory.

Registers are very fast storage that holds the numbers that instructions operate on. One way to think of it is that a register is a scratchpad for instructions to use. A microcontroller has a small number of registers, typically 8-32. The MSP430 has 16 registers, for example.

Memory is also storage for numbers, but memory is much more plentiful and slower than registers. A microcontroller might have 64KB, 256KB, or more than 1MB of memory. One MSP430 microcontroller (the MSP430F5529) has about 128KB of memory; that’s more than 8000 times the number of registers it has!

Before we get started with some examples, I encourage you to get out a sheet of paper and a pen or pencil and work them out as you read them. Working them out on paper is harder than just reading what I’ve written, and so you will pay more attention to what you’re doing and you stand a better chance of remembering what you learn.

Let’s look at an example of a fictional but representative microcontroller.

Let’s say our microcontroller has 4 registers and 8 memory locations. Registers are usually named creative things like “R0,” “R1,” and so on, and so we’ll do the same. Memory locations are usually referred to by the location number, also called the memory address, starting at 0. Here’s what our registers and memory look like: