Architecture of the CPU
Basic computer system model
A computer system is made up of hardware and software. Hardware is any physical component that makes up a computer. Software is any program that runs on a computer.
Computer systems are all around us. They are not just the PCs on a desk but include mobile phones, cash machines, supermarket tills and the engine management systems in a modern-day car.
The diagram below shows the basic model of a computer system.
[Memory]
↑↓
[Input] → [CPU (processor)] → [Output]
↑↓
[Secondary storage]
All computer systems must have a central processing unit (CPU), also called simply the processor, and at least one input device that gets data from the real world. This could be a mouse and keyboard on a conventional PC, a temperature sensor (thermistor) in a commercial greenhouse or the microphone on a mobile phone.
Input devices take real world data and convert it into a form that can be stored on the computer. The input from these devices is processed and the computer system will generate outputs. The output device could be, for example, a conventional computer screen, an actuator that opens or closes a greenhouse window, or the speaker that produces sound on a phone.
The computer must have memory (primary storage), used for holding instructions currently being executed and data that is being used.
Any computer system will have these four basic components.
The fifth component is secondary storage. The computer system may need to use stored data to perform the processing and, as a result of processing input, may generate data that is then stored. Storage devices such as hard disks can hold large amounts of data including databases, text documents, programs, music files and photographs.
Q1: Name three input, output and storage devices.
Common CPU components and their function
The Central Processing Unit (CPU) of a computer is the hardware that executes programs and manages the rest of the hardware. Think of the CPU as the brain of the computer. Just as your brain contains parts that remember things, parts that think and parts that make the rest of your body operate, the CPU does the same for the computer. The computer also contains main memory and cache memory. Cache (pronounced "cash") is very fast memory, close to the CPU, used to temporarily hold data or instructions that are likely to be needed again by the processor in the course of running a program.
Control Unit
The Control Unit coordinates all the activities taking place inside the CPU. Its functions may be summarised as follows:
- It controls the execution of instructions in the correct sequence
- It decodes instructions
- It regulates and controls processor timing using regular pulses from the system clock
- It sends and receives control signals to and from other devices within the computer
The Arithmetic and Logic Unit (ALU)
The ALU carries out the following functions:
- Logical Operations: These include AND, OR and NOT.
- Shift Operations: The bits in a computer word can be shifted left or right by a certain number of places.
- Arithmetic Operations: These include addition, subtraction, multiplication and division.
Von Neumann architecture
With the very first computers, it was not possible to store programs, and programs were generally input by setting switches. John Von Neumann developed the concept of the stored program computer in the 1940s. The Von Neumann architecture used the idea of holding both programs and data in memory. Data would then move between the memory unit and the processor.
[Storage]
↑↓
[Input devices] → [Processor (CPU)] → [Output devices]
↑↓
[Cache]
↑↓
[Main Memory]
Fetch-Decode-Execute cycle
When a program is to be run (executed) on a computer it first has to be loaded into main memory. From here it can be accessed by the processor, which runs each instruction in turn. When the program is loaded, the processor is given the start address of where it is held in main memory.
[Fetch an instruction from main memory] → [Decode the instruction] → [Execute the instruction] → (Loop back)
To run the program the processor fetches an instruction, decodes it and then executes it. The processor executes one instruction at a time. This is called the Fetch-Decode-Execute cycle, or simply the Fetch-Execute cycle.
The processor contains the Control Unit (CU), the Arithmetic Logic Unit (ALU) and registers.
Special-purpose registers
A register is a special very fast memory location within the CPU used in the execution of instructions.
A CPU has number of special-purpose registers, listed below:
- The Memory Address Register (MAR) holds the address (location in memory) of the instruction or piece of data to be fetched or stored.
- The Memory Data Register (MDR) holds data or a program instruction temporarily when it is fetched from memory or is to be sent to memory.
- The Program Counter (PC) holds the memory address of the next instruction to be processed.
- The Accumulator (ACC) is a special-purpose, memory location in which results of operations carried out in the ALU are temporarily stored. (N.B. Most processors have several general-purpose registers, instead of a single accumulator, which are used as temporary fast storage.)
For example, the assembly code below fetches a value from main memory, adds 80 to it and stores the result of the addition back into memory. Each location in memory has its own unique address.
ADD #80 adds the value 80 to the present content of the accumulator
STA 2560 stores the content of the accumulator in memory location 2560
In order to execute the first instruction, LDA 2560, the address, the address 2560 is passed to the Memory Address Register (MAR) and the computer transfers the data from this memory location to the Memory Data Register (MDR). From here the data is passed to the accumulator to be used in the calculation.
When you write an instruction in Python or Visual Basic, for example:
it is broken down into these three basic instructions.