Computer Structure
The Processor
The processor is the part of the computer system that handles the instructions used to ensure that hardware and software respond as expected. Processors can handle millions of instructions per second.
Processors must be able to:
fetch, decode and execute instructions from RAM
perform arithmetic calculations
perform logical operations
control read, write, clock, interrupt and reset lines
Control Unit
manages the flow of data around the computer
uses a clock to synchronise events
has a read line which tells memory that data is being read to the processor
has a write line which tells memory that data is being written from the processor
has a reset line to reset the contents of the registers
has an interrupt line which is used to signal that there is an event needing attention
Arithmetic and Logic Unit (ALU)
carries out calculations e.g. adding / subtracting numbers
compares numbers e.g. 5 > 4
performs logical operations using AND / OR / NOT
Registers
are fast temporary storage locations on the processor
store data, intructions or addresses being used by the CPU
Memory
The computer has memory known as RAM (Random Access Memory).
RAM is:
a block of storage locations connected to the processor by the data bus and address bus
used to store data, programs and the operating system
volatile meaning its contents are cleared when it has no power i.e. the computer is switched off
Each memory location has its own unique address which is used by the address bus to read/write data to the correct place.
Buses
Buses transfer data between the processor and memory.
The data bus:
carries data from memory to be used by the processor
carries data from the processor to be stored in memory
is bi-directional because data can travel in both directions
The address bus:
tells memory which memory location is being read from
tells memory which memory location is being written to
is uni-directional because the address always goes from the processor to memory
Translating Code
A translator converts the high level program (source code) into binary (machine code).
A translator is required because:
humans understand high level languages e.g. Python, C++, Java
computers understand binary
There are two types of translator:
Interpreter
Compiler
Interpreters
An interpreter translates source code into machine code one line at a time.
Advantage:
Errors are flagged after each line has been interpreted making debugging easier
Disadvantages:
Slower because statements in a loop are translated repeatedly
The interpreter must remain in memory to allow the program to run
Compilers
A compiler translates the entire source code program to object code in one go.
Advantages:
A program only needs to be compiled once, and would only need compiled again if further changes have been made
The compiler does not need to remain in memory once the program has been compiled, as the object code can run independently
Disadvantage:
Harder to debug because all of the errors are reported once the program has been compiled