This diagram shows a processor and a memory of sixteen cells, connected by a data bus and an address bus. The memory holds a program that multiplies 3 by 2 by adding 3 twice, and leaves its result in cell 14. The program counter is at 0, ready to start.
A processor and a memory, connected by a data bus and an address bus.
The memory has sixteen cells, numbered 0 to 15, each holding 8 bits.
Cells 0 to 8 hold the program: its instructions, one per cell. It multiplies 3 by 2, by adding 3 twice.
Cells 12 to 15 hold its data, the numbers it works on, in the same memory as its instructions.
The address bus carries 4 bits, enough to pick one of the sixteen cells, as the address inputs of the addressable memory did. The data bus carries the 8 bits of a cell, to the memory or from it.
The processor, an 8-bit CPU, runs the program: it reads each instruction from memory, then does what it says.
Inside the processor: the program counter, the selector, the control unit with its instruction register, the accumulator, the ALU and the clock.
The processor knows none of this: to it, the memory holds only bits. A cell is an instruction or a number only once the processor uses it as one.
Fetch: the clock ticks, and the control unit starts fetching the next instruction from memory.
The control unit tells the selector to let the program counter’s address through, and the memory to read the cell at that address, 0.
The control unit tells the memory to put the bits of cell 0 on the data bus, and the instruction register to take them.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit starts decoding the instruction in the instruction register, to know what to do.
The instruction’s 4 bits of operation are LOAD, and its 4 bits of address 14: the bits of cell 0 were an instruction.
Execute: the clock ticks, and the control unit starts carrying out the instruction.
The control unit tells the selector to let the instruction’s address through, and the memory to read the cell at that address, 14.
The control unit tells the memory to put the bits of cell 14 on the data bus, and the accumulator to take them: the accumulator holds 0.
Fetch: the clock ticks, and the control unit has the memory read cell 1, at the program counter’s address, into the instruction register.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register.
The instruction’s 4 bits of operation are ADD, and its 4 bits of address 12.
Execute: the clock ticks, and the control unit has the memory read cell 12, at the instruction’s address, and has the ALU add it to the accumulator.
The ALU gives back 0 + 3 = 3, and the control unit tells the accumulator to take it: the accumulator holds 3.
Fetch: the clock ticks, and the control unit has the memory read cell 2, at the program counter’s address, into the instruction register.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register.
The instruction’s 4 bits of operation are STORE, and its 4 bits of address 14.
Execute: the clock ticks, and the control unit has the memory write the accumulator’s bits, 3, into cell 14, at the instruction’s address.
Fetch: the clock ticks, and the control unit has the memory read cell 3, at the program counter’s address, into the instruction register.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register.
The instruction’s 4 bits of operation are LOAD, and its 4 bits of address 13.
Execute: the clock ticks, and the control unit has the memory read cell 13, at the instruction’s address, into the accumulator: the accumulator holds 2.
Fetch: the clock ticks, and the control unit has the memory read cell 4, at the program counter’s address, into the instruction register.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register.
The instruction’s 4 bits of operation are SUB, and its 4 bits of address 15.
Execute: the clock ticks, and the control unit has the memory read cell 15, at the instruction’s address, and has the ALU subtract it from the accumulator, with the subtract signal on.
The ALU gives back 2 − 1 = 1, and the control unit tells the accumulator to take it: the accumulator holds 1.
Fetch: the clock ticks, and the control unit has the memory read cell 5, at the program counter’s address, into the instruction register.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register.
The instruction’s 4 bits of operation are STORE, and its 4 bits of address 13.
Execute: the clock ticks, and the control unit has the memory write the accumulator’s bits, 1, into cell 13, at the instruction’s address.
Fetch: the clock ticks, and the control unit has the memory read cell 6, at the program counter’s address, into the instruction register.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register.
The instruction’s 4 bits of operation are JUMPZ, and its 4 bits of address 8.
Execute: the clock ticks. The ALU’s zero wire is off, since its last result was not 0: the control unit leaves the program counter at 7.
Fetch: the clock ticks, and the control unit has the memory read cell 7, at the program counter’s address, into the instruction register.
The control unit tells the program counter to add 1, ready for the next instruction.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register.
The instruction’s 4 bits of operation are JUMP, and its 4 bits of address 0.
Execute: the clock ticks, and the control unit tells the program counter to take the instruction’s address, 0: the program goes back to cell 0.
Fetch: the clock ticks, and the control unit has the memory read cell 0, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: LOAD 14. The program counter has counted to 1.
Execute: the clock ticks, and the control unit has the memory read cell 14, at the instruction’s address, into the accumulator: the accumulator holds 3.
Fetch: the clock ticks, and the control unit has the memory read cell 1, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: ADD 12. The program counter has counted to 2.
Execute: the clock ticks, and the control unit has the memory read cell 12, at the instruction’s address, and the ALU add it to the accumulator: 3 + 3 = 6, which the accumulator takes.
Fetch: the clock ticks, and the control unit has the memory read cell 2, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: STORE 14. The program counter has counted to 3.
Execute: the clock ticks, and the control unit has the memory write the accumulator’s bits, 6, into cell 14, at the instruction’s address.
Fetch: the clock ticks, and the control unit has the memory read cell 3, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: LOAD 13. The program counter has counted to 4.
Execute: the clock ticks, and the control unit has the memory read cell 13, at the instruction’s address, into the accumulator: the accumulator holds 1.
Fetch: the clock ticks, and the control unit has the memory read cell 4, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: SUB 15. The program counter has counted to 5.
Execute: the clock ticks, and the control unit has the memory read cell 15, at the instruction’s address, and the ALU subtract it from the accumulator, with the subtract signal on: 1 − 1 = 0, which the accumulator takes. The result is 0: the ALU’s zero wire is on.
Fetch: the clock ticks, and the control unit has the memory read cell 5, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: STORE 13. The program counter has counted to 6.
Execute: the clock ticks, and the control unit has the memory write the accumulator’s bits, 0, into cell 13, at the instruction’s address.
Fetch: the clock ticks, and the control unit has the memory read cell 6, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: JUMPZ 8. The program counter has counted to 7.
Execute: the clock ticks. The ALU’s zero wire is on, since its last result was 0: the control unit tells the program counter to take the instruction’s address, 8.
Fetch: the clock ticks, and the control unit has the memory read cell 8, at the program counter’s address, into the instruction register, and tells the program counter to add 1.
Decode: the clock ticks, and the control unit decodes the instruction in the instruction register: HALT. The program counter has counted to 9.
Execute: the clock ticks a last time, and the control unit stops it, since the program is done.
The program is done, and the machine has stopped: cell 14 holds its result, 6.