Basics of Instruction Execution

CPU (central processing unit): contains ALU (arithmetic-logic unit), instruction interpreter, a little bit of memory. The memory in the CPU is called ``registers.'' We need to have memory actually in the CPU because getting it from ``memory'' takes too long (one of the major determiners of how powerful a computer is, is how much memory it has in the CPU, and how much can be transferred at a time between ``memory'' and the CPU); one of the ways to make a program run faster is to make sure you have the most-used data present in the CPU at all times.

We'll be introducing the memory present in the CPU a little bit at a time, as needed. For today, we need the PC (program counter) register, and the B accumulator.

The PC always contains the address of the next instruction to be executed. B is a register where we ``accumulate'' results.

Let's take a look at a fragment of code in memory. Suppose we have

f802:  CB
f803:  12
Also, let's suppose that before we start, the PC contains f802 and B contains 24. Here's what the CPU is going to do with this:
  1. Read from memory location f802, getting the data CB back. This is the instruction fetch.
  2. Add one to the PC.
  3. Figure out what CB means. We can find out what it means by looking in the pocket guide on page 15 (middle of the page). Looking across the line that this appears on, we see: If we look up the ADD instruction in the reference manual on page 496, we get a little more information about what's going on. This process of figuring out what the instruction is going to do is the instruction decode.
  4. Looking at ADDB(IMM) in the table, we see we've already accomplished the first cycle shows: we read a byte from the address of the instruction, and gotten an CB back.
  5. On the next cycle, we put the new value of the PC on the bus, and read again. What we read is our operand, (ii), which we've decided will contain a 12.
  6. Add one to the PC again.
  7. Add the value we read from memory (12) to the value in accumulator B (24), and put the result back in accumulator B.