When an instruction is executed, the CPU follows the fetch, decode, execute, and store steps. The instruction is first read from memory, interpreted, and then executed. This process repeats for each instruction in the same manner, that is why it is called the CPU cycle.
Memory elements in CPUs are called registers. These are small, high-speed storage units that temporarily hold data, memory addresses, and other information. Registers can be general-purpose or special-purpose, such as the program counter, instruction register, and status registers.
The ALU is responsible for performing arithmetic (addition, subtraction, etc.) and logic operations (AND, NAND, etc.) while interacting with the registers and the control unit. There is one ALU per processor core.
There are different types of memory, two groups are volatile (forgetful) memory and non-volatile memory, which remembers data even after power is removed. The types also differ in speed, manufacturing cost and capacity. There are several types in an MCU, each with its own use within the system.
SRAM (Static RAM) is fast but expensive, DRAM (Dynamic RAM) is cheaper but slower. RAM itself is random access memory, which means that any part of it can be accessed immediately in random order.
A non-volatile memory that is used for reading only. Typically used to store firmware, subtypes are PROM, EPROM or EEPROM (for example Flash). They have a limited lifetime, which is why Flash memories use a separate control unit to efficiently distribute information, usually with the addition of a cache.
Communication between the processor, memory and peripherals takes place on buses. All the information is put on the bus and the elements take off what they need. Even a simple microcontroller contains countless different bus systems, depending on the architecture and the peripherals available.
In the example, R1 and R2 are registers that currently store some value. The CPU receives the instruction in binary, depending on the architecture of the specific device. In plain text, the instruction says to add the values of R1 and R2 together and write the result to register R1, similar to R1 = R1 + R2 in other languages.
The PC (Program Counter or Instruction Pointer) tells the CPU where the next instruction is located in memory, and the CPU reads it from there. The instruction is written into the instruction register (IR).
The control unit (CU) in the processor recognises that an addition operation is required, which the ALU will perform. It identifies the operands, that are the two registers as source (R1 and R2) and destination (R1).
The value of the two registers is sent via the data bus to the ALU, which performs the addition operation, and the result is then sent to its output. There are some operations that are not performed by the ALU (e.g. LOAD).
Once the ALU produces the result of the addition, it is written to register R1, completing the instruction.