But how does the CPU know where to get its instructions?

On the CPU, there is a tiny amount of memory. It does various things, such as hold something called the "instruction pointer". The instruction pointer holds the location of the next instruction, and increments itself after every instruction. So basically, the CPU reads the instruction pointer, fetches the next instruction, does it, increments the instruction pointer and then goes back to step one.

The value of the instruction pointer itself can be set to some arbitrary location in memory. You ever wonder what an infinite loop is? It's what happens when an instruction pointer is set to instructions that keep telling the instruction pointer to set itself to that same set of instructions.

<left 7/8 next>

source code - donate - contact