1.1 - Architecture of the CPU

What is a computer?

A computer is an electronic device that takes input, processes data, and produces an output.

This means that every program has an input, processing, and output stage.

There are 3 'parts' to a computer:
- Keyboard (Input)
- Monitor (Output)
- CPU (Processes)

But memory (RAM) is crucial to most architectures.


The parts of a CPU

- Cache: The cache stores (caches) frequently-used and to-be-used-soon data to help speed up performance of the CPU. It is split into L1 (level 1), L2 and L3 caches. It exists to shorten the length data has to travel, since some data won't have to go all the way to main memory (RAM).
- ALU (arithmetic and logic unit): Responsible for carrying out arithmetic calculations and logic operations (AND, NOT, OR and so on).
- CU (control unit): Sends signals to control how data moves around the CPU, and a timing signal for the clock speed. It converts instructions into these signals through a binary decoder.
- Registers: Stores temporary information, are super-fast, and each has a specific purpose.


Von Neumann architecture

- The architecture that modern CPUs follow, and have for many years. - Called this because in 1945, John von Neumann designed an architecture for computers that didn't just have one specific purpose, it could store programs and be reprogrammed.
- Von Neumann architecture has several characteristics: a CPU with a single CU, an ALU, on-board cache, an internal clock (synchronises components depending on the clock speed), and the fetch-decode-execute cycle (more below).
- Programs are made up of a sequence of instructions (also called an algorithm), stored in the main memory outside the CPU. The instructions are fetched one by one and put into the registers for processing.
- In the memory, each instruction is stored in a location, marked by a memory address. This means that the CPU might get some data in memory address one, for example, and bring it back to the processor.
- This architecture makes use of the registers mentioned below.


Processing

Processing happens in a cycle: the fetch-decode-execute cycle.

- In the 'fetch' stage, the CPU fetches the next instruction (the number of which is held in the program counter, but is copied to the Memory Address Register before the data is fetched) from RAM or the cache, and brings it into the Memory Data Register. It then copies it into the instruction register.
- In the 'decode' stage, the CU gets the instruction from the Instruction Register and breaks the instruction down into simple calculations that the ALU (Arithmetic Logic Unit) can do.
- In the 'execute' stage, the CPU carries out the instruction. This can be any task defined by an instruction, for example performing a calculation, storing information in memory, or getting data in memory.
- This cycle occurs billions of times per second (GHz, giga-hertz) on a modern CPU. This is the clock speed, 1Hz = 1 cycle per second.


Registers

- Program counter: tracks current execution point, holds the memory address of the next instruction to be executed. Gets incremented by one, so it points to the next instruction, when the instruction has been executed.
- Instruction register: stores the instruction currently being executed or decoded.
- Memory address register: stores the memory address of where data will be fetched from or stored into.
- Memory buffer/data register: buffers data going to and from memory.
- Accumulator register: ALU results storage.


Factors that effect CPU performance

- Cache size: The higher the cache size, the less time the CPU waits for RAM.
- Cores: Essentially a copy of the executy-bits of a CPU, so the CPU can run two things simultaneously.
- Architecture: CPUs have to be designed, and will have different designs. You will see things like 'x86' and 'ARM' thrown around, and it is worth noting that these are based on Von Neumann architecture. x86 and ARM affect which instructions are supported and the features the CPU has. (I think this is beyond the spec so dw abt it but worth mentioning.)
- Clock speed: The faster the clock speed, the faster instructions can be executed.


Embedded Systems

- An embedded system is a computer system with a function within a larger mechanical and electrical system.
- Most processors are parts of embedded systems, because they are everywhere.
- They are found in everything where processing is needed, from programmable ovens to smart light switches.
- They are also used in medical equipment, traffic lights, and basically anything programmable.
- Modern embedded systems usually use microcontrollers (CPUs with integrated memory), but are still often found on their own.
- They are low-power-consumption, small size, low cost, low processing power, and specific in function.


Whew, that should be everything. Contact me (Wilbur) if something is missing!