How the CPU uses its general purpose registers

Background information:

  • All variables (data) are stored in the (computer) memory

  • Arithmetic and logic operations are performed by the ALU circuit inside the CPU

  • Therefore:

      • Data (in variables) must be transfered from the memory into the CPU before any operation can be performed on the data !!!

How the CPU uses its registers to execute z = x + y

Initial situation:

Notice that:   the values of the variables x, y and z are stored in the memory

Suppose that the the variables x, y and z are stored in memory addresses 200, 204 and 206, respectively

How the CPU uses its registers to execute z = x + y

Step 1: the CPU fetch the value from variable x into a (general purpose) register

The CPU will issue a read command to read the value in memory at address 200

The value on the data bus will be stored in one of the general purpose register (in example: register R0)

How the CPU uses its registers to execute z = x + y

Step 2: the CPU fetch the value from variable y into another (general purpose) register

The CPU will issue a read command to read the value in memory at address 204

The value on the data bus will be stored in a different general purpose register (in example: register R1)

How the CPU uses its registers to execute z = x + y

Step 3: the CPU can now perform the addition operation with the data in its registers

The result of the operation will be stored in a general purpose register

Notice that:   the variable z in the memory has not yet been updated (it's value = 0, which is not equal to 9 !!!)

How the CPU uses its registers to execute z = x + y

Step 4: update the variable z in memory

The CPU will issue a write command to update the value in memory at address 206

Notice that:   only after this step is the variable z in the memory updated !!