When a ticket machine adds €5 to a €7 fare, how does its CPU know what to do?
You see seven euro become twelve on a ticket machine when a five euro charge is added. The processor needs more than those two numbers. How does it find the instruction that tells it to add them?
RAM can hold the instructions for a running program. Inside the CPU, registers are small storage locations that hold values the CPU is using. Logic gates work together to add binary numbers. You'll see the values in decimal here so you can focus on where they go.
The program counter holds twenty, the next instruction address. The CPU copies it into the memory address register. RAM uses that address and returns the whole instruction, add five, to the memory data register. The CPU copies that word into the instruction register. This is the fetch.
Suppose the program counter holds thirty and RAM at address thirty contains the instruction add two. Before RAM sends back the instruction, what does the CPU copy into the memory address register? Pick one answer.
Once add five is in the instruction register, the control unit interprets its two parts. The operation code says to add. Here, the operand gives the number five directly, so the CPU doesn't have to read another memory location to get it.
The control unit tells the arithmetic logic unit, or A L U, to add. The A L U takes seven from the accumulator and five from the instruction register. It produces twelve, which the CPU stores back in the accumulator, replacing seven.
Start with P C at twenty and the accumulator at seven. Copy the address into M A R. Read add five through M D R into I R. Each instruction occupies one word here, so advance P C to twenty-one. The control unit decodes add five. Add and store twelve in the accumulator.
Now start at address forty with eight in the accumulator. The instruction there is add three, and the next instruction is at forty-one. After one full cycle, what do the program counter and accumulator hold? Pick the pair.
If you put twenty-five in the program counter, you've wrongly used the operand to change the address and left seven in the accumulator. In this model, the counter moves to the next word address, twenty-one. The A L U adds five to seven, and the accumulator stores twelve.
If asked to describe the fetch-decode-execute cycle, trace the address and instruction separately during fetch. Include how the program counter moves to the next instruction address. For decode, say how the control unit interprets the instruction. For execute, name the operation and say where the result is stored.