Ground Embedded KO Subscribe

Notes / Computer Architecture

Inside the CPU: fetch, decode, execute

Registers, the ALU, the program counter, and the loop that fetches and executes instructions. This loop is all a CPU does.

GROUND EMBEDDED · NOTEComputer Architecture 02Inside the CPUMCU

Components

  • Program counter (PC): the address of the next instruction to run
  • Register file: very fast storage inside the CPU. Cortex-M has r0 to r15
  • ALU: the calculator that adds, subtracts, does bit operations and compares
  • Control unit: decodes the instruction and signals each part what to do
  • Status register: flags recording whether the result was zero, negative, or produced a carry

Instruction cycle

Fetchthe instruction PC points toDecodewhich instruction?Executecalculate, storePC advances
The three steps a CPU repeats forever.
  1. Fetch: read the instruction at the address the PC points to
  2. Decode: work out which operation it is and which registers it uses
  3. Execute: the ALU calculates, or memory is read or written
  4. Move the PC to the next instruction and go back to 1

A branch instruction changes the PC directly and sends the flow elsewhere. if and for become a compare instruction + a conditional branch in machine code.

From the embedded point of view

A 72 MHz CPU that handles most instructions in one clock executes about 72 million instructions a second. This number is the starting point when you work out the time budget of a control loop.

FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →