Unit 4
Computers
The stored program concept
The stored program concept was the brainchild of Alan Turing and John von Neumann in the
1940s. They wanted to make a computer that was easy and quick to reprogram so that it could
carry out a variety of tasks. Previously, computing machines were built to perform just one job.
Programmable computers
The term computer architecture refers to the structure of a computer system – the hardware
components it has and how they work together to execute programs.
Von Neumann devised a new computer architecture for a programmable machine.
Being able
to store
programs
in memory
was a
Key facts about main memory
It is short-term, working memory. It only holds the program instructions and data that
the CPU is currently using. The contents of main memory are continually changing.
It consists of a collection of storage locations, each with its own unique address. A
storage location can hold a program instruction or an item of data.
It is often referred to as RAM – short for random access memory – because storage
locations can be read from and written to in any order.
It is classed as primary storage because the CPU has fast, direct access to it.
It is volatile. It needs power to retain its contents. When the computer is switched off, its
main memory is completely wiped.
Modern laptops, tablets and phones typically have between 4 and 32 GiB of RAM. This
enables them to store several programs in memory at the same time.
The central processing unit (CPU)
The CPU is the hardware component that decodes and executes program instructions.
Components of the CPU
The clock
The CPU’s clock is a tiny quartz crystal that vibrates at a constant rate. Each ‘tick’ of the clock
triggers the CPU to carry out one action.
The clock’s speed is measured in cycles per second: 1 hertz = 1 cycle per second. Modern
CPUs have clock speeds of around 3 gigahertz (GHz).
Every CPU requires a fixed number of clock cycles to execute an instruction. The higher the
clock speed, the more instructions that can be executed per second. Some CPUs need two
cycles to fetch an instruction. One to get the instruction and the second to get the data needed
to carry it out. Others fetch both in one cycle.
Buses
A bus is a collection of wires that is used to transfer data between components of a computer
system. The CPU uses three buses:
The control bus carries signals between the CPU and other parts of the computer
system.
The address bus holds the address of the memory location that the CPU will read from
or write to. The number of wires in the address bus (its bandwidth) determines how
much addressable memory there is.
The data bus transfers program instructions and data between memory and the CPU.
Buses may
be
The fetch-decode-execute cycle
The fetch-decode-execute cycle is the sequence of steps carried out repeatedly by the CPU
when a program is being executed. Instructions are fetched one at a time from memory into the
CPU, where they are decoded and executed. Modern CPUs carry out billions of cycles per
second.
The fetch stage
To fetch an instruction.
The decode stage
Next, the control unit looks up the instruction in the CPU’s instruction set. Every CPU has its
own unique instruction set – a list of all the operations that it can carry out.
The execute stage
Finally, the control unit coordinates the actions of the other components of the CPU to carry out
the operation. If an arithmetic or logic operation is required, the control unit signals that the ALU
is to carry it out.
Once a cycle is complete, the next one starts.
The need for secondary storage
Secondary storage provides long-term storage for programs and data.
Why secondary storage is needed
A computer’s main memory is short-term. It only holds programs and data while they are being
used by the CPU.
When the power is switched off, main memory is wiped clean.
Secondary storage, on the other hand, is non-volatile. It does not need an uninterruptable
power supply and can therefore provide long-term storage for programs and data. Without
secondary storage, a program and all its associated data would have to be keyed in every time
it was required.
A computer’s main memory is its primary storage. It provides the CPU with fast, direct access
to running programs and their data. A computer’s hard drive provides secondary storage and
stores programs and data when they are not in use.
How primary and secondary storage work together
When a user opens an application, it is loaded into main memory from secondary
storage.
Any data files that are opened for use in that application are also loaded into main
memory.
When the user saves a file, it is transferred from main memory into secondary storage.
When the application is closed, it is removed from main memory.
Differences between primary and secondary storage
Primary storage Secondary storage
Volatile and power dependent. Its contents are Non-volatile. Its content is retained even when the
lost when the power is switched off. power is switched off.
Short-term Long-term
Program and data must be transferred to memory
It is directly accessed by the CPU.
in order for them to be accessed by the CPU.
Large storage capacity (a magnetic hard drive
Limited storage capacity (between 500 MiB
can store up to 4 TiB of data). Can be expanded
and 8 GiB) and only limited scope for
by using external devices, such as portable hard
expansion.
drives and USB memory sticks.
Types of secondary storage
There are three main types of secondary storage: magnetic, optical and solid-state.
Magnetic storage
Magnetic storage devices, such as hard disk drives (HDDs) and magnetic tape drives, use
magnetic storage.
An HDD contains a stack of circular, metal platters that spin at high speed. Both surfaces of
each platter are coated with a substance that can be magnetized.
Each platter has its own read-write head.
To write data: an electromagnetic in the read-write head magnetises the surface of the platter
to one of two polarities: north-south or south-north. These represent 1 or 0 respectively. Data is
stored on a series of concentric tracks, subdivided into sectors.
To read data: the read-write head detects the magnetic state of the platter.
Optical storage
Optical storage devices, such as CD and DVD drives, use patterns of light to store data on
removable disks.
To write data: a laser is used to burn the surface of the disk, changing its form to become more
reflective or less reflective. Reflective areas are called lands; less reflective areas are called
pits. A land represents 1 and a pit 0.
Data is stored as a series of lands and pits on a single track that spirals out from the centre of
the disk.
To read data: a laser beam is shone onto the surface of the disk. A pit reflects light more dimly
than a land. The amount of light reflected off the surface is detected by a light sensor and
translated into 1s and 0s.
Solid-state storage
Portable computing devices, such as mobile phones and smart watches, use solid-state
storage. It consists of a grid of transistors.
To write data: an electrical current is applied to the transistor. This forces electrons through a
barrier, trapping them in pools. A full pool represents 0 and an empty pool 1.
To read data: a small voltage is applied. If the electron pool is empty, the transistor turns on
and a 1 is read out. If it is full, the transistor does not turn on and a 0 is read out.
Comparison of different storage technologies
Used in Advantages Disadvantages
Magnetic Internal/external hard drives High capacity Has moving parts that will
Tape drives Fast data access eventually fail
Noisy
Optical CD, DVD and Blu-ray drives Portable Slow to access
Disks are cheap Prone to scratches
Solid- Solid-state drives Very fast data access Relatively expensive
state USB sticks No moving parts Has a limited number of
SSD cards Low power read-write cycles
Mobile devices and wearables Quiet
Embedded systems
An embedded system is a small computer on a chip, that performs a dedicated task within a
bigger system. Most embedded systems work in real-time – they must respond immediately to
an external event or request.
Features of embedded systems
single-purpose – designed for a specific task
customized hardware and software
limited memory and processing power
low power consumption
wireless connectivity
minimal or no user interface
small physical size
responsive to their environment
low maintenance
usually operate in real time
Hardware components of an embedded system
Plus, firmware – the program that tells the device what to do. Once installed on the device,
firmware does not need to be modified.
Examples of devices that use embedded systems
A washing machine that regulates water usage according to the size of its load.
A drinks dispenser that sends a recorder request to the supplier when stock is running
low.
An insulin pump that monitors blood glucose levels and delivers insulin to the patient.
An anti-lock braking system that prevents a vehicle from skidding.
A burglar alarm that sends a message to the homeowner’s phone if it detects an
intruder.
The internet of things (IoT)
The IoT is a network of physical objects that use embedded systems and wireless technology to
collect and exchange data with little or no human interaction. There are several privacy and
security issues associated with it. For example, many IoT devices are dispatched from factories
with a default password set. If purchasers do not change the password, hackers can gain
access to the device using a simple script.
Operating system 1
The operating system (OS) is the program that acts as an interface between the hardware and
other software in a computer system, enabling them to communicate with each other.
It also provides a way for users to interact with the computer. Microsoft Windows, Apple iOS
and Linux are three well-known operating systems.
Main tasks performed by an operating system
Process management: overseeing the execution of programs by the CPU and
allocating each of them a share of main memory and CPU time.
File management: organizing and keeping track of the contents of secondary storage,
managing files and folders and using permissions to control user access to programs
and files.
User management: providing a user interface to enable users to interact with the
computer.
Peripheral management: communicating with device drivers to control peripheral
devices.
Process management
When a program is opened, it is copied from secondary storage into main memory so that it can
be executed by the CPU. While they are stored in memory, programs are referred to as
processes. Modern computers are multitasking – they can execute several processes
concurrently (at the same time).
Since the CPU can only execute one instruction at a time, it is up to the OS to ensure that every
process loaded into main memory gets a share of CPU time. The OS uses a scheduling
algorithm to do this.
Memory management
When a process is loaded into main memory from secondary storage, the OS allocates it a
block of addresses called pages.
Occasionally, a computer’s memory may become full. When this happens, the OS frees up
space by temporarily moving inactive processes out of main memory into an area of the hard
drive designated as virtual memory.
It uses a paging algorithm to determine which processes to swap out. Processes are swapped
back in again when it is their turn to use the CPU.
Round-robin
Round-robin is a commonly used scheduling algorithm.
Each process is allocated a time slice, with higher priority tasks being
given more time slices.
While they are waiting their turn to use the CPU, processes are held
in a queue. The process at the front of the queue is next in line to use
the CPU.
During its time slice, a process has exclusive use of the CPU.
At the end of its time slice, if the process is unfinished it goes to the
back of the queue to wait for its next turn.
Operating system 2
Three important functions performed by the operating system (OS) are file, user and peripheral
management.
File management
The OS is responsible for managing and keeping track of the files stored on a computer’s hard
drive. Files are stored in hierarchical tree structure.
The tree elements are called ‘nodes’. The lines connecting elements are called ‘branches’. The
top node of the tree is the root directory. A directory is a folder containing other items. Nodes
lower down are either sub-directions or files.
User management
Access control: In shared computers and networks, the OS uses login names and passwords
and/or some form of biometric identification to authenticate users and control who can log on.
User interface: The OS provides a user interface to enable users to interact with the computer.
Graphical user interface (GUI): A GUI, such as Windows or Android, has windows, icons,
drop-down menus and pointers.
Command line interface (CLI): A CLI only allows users to type in commands. They are mainly
used by expert users, who want more control over the function of the computer.
File permissions control who can do what with each file.
A user can be granted one of four levels of access to files:
Read: They can only view contents of files.
Write: They can read and make changes to files but cannot delete them.
Execute: They can run files (assuming they are executable).
Delete: Gives full access rights, meaning the user can read, write and delete files.
The OS enforces the permissions associated with each user.
Peripheral management
A peripheral device is an additional item of hardware, such as a printer, a keyboard, a graphics
card or a microphone that is connected to a computer.
The OS uses specialist programs called device drivers to enable it to communicate with
peripheral devices. The drivers are installed on the computer’s hard drive and have to be kept
up-to-date so that peripherals continue to work as expected.
Utility software
Utility software is a collection of small, specialized programs, each of which performs a specific
task.
Data compression software
Purpose: To reduce the size of a file so that it takes up less space in secondary storage and is
quicker to transfer across networks.
How it works: It repackages (lossless compression) or removes (lossy compression) some of a
file’s data to reduce its size.
File repair software
Purpose: To recover data from and repair files that have become corrupted by a computer
malfunction or cyberattack.
How it works: It scans the damaged file, extracts as much data from it as possible and stores it
in a new usable file.
Disk defragmentation software
Purpose: To speed up access to files stored on a magnetic hard drive.
How it works: It rearranges individual file blocks for each file so that they are stored in
contiguous (adjoining) blocks on the disk.
Backup software
Purpose: To keep a copy of files so that, should a file get lost or damaged, the most recent
backup can be restored.
How it works: Backup copies of files are made at regular intervals and stored on a separate
device in a different location to the live working environment – possibly in the cloud.
Solid-state drives get just as fragmented as magnetic hard drives but,
because they have no moving parts, it does not affect the data access
speed.
Anti-malware software
Purpose: To protect computer systems and data from damage caused by malware, such as
viruses, worms and spyware.
How it works: Some types of anti-malware software use a database of malware signatures (the
patterns associated with a known piece of malware). If the anti-malware detects a file that has a
pattern that matches a known signature, it deletes or quarantines it.
Some use heuristic analysis to detect suspicious behaviour, such as a program that tries to
remain resident in memory after it has finished executing.
Why fragmentation occurs
When a file is saved to the hard drive, it gets split up into blocks.
Ideally, all blocks belonging to one file are saved in adjoining sectors
on the disk. As files are changed, blocks have to be saved wherever
there is a free space.
Fragmentation slows down read operations, because more disk
accesses are needed to retrieve all the blocks of a single file.
Robust software
A program is deemed robust if it can handle unexpected actions without crashing or producing
incorrect output and if it is free from vulnerabilities that could be exploited by criminals.
Code vulnerabilities
A program may have hidden weaknesses that could pose a security threat. Criminals can
exploit such code vulnerabilities to cause damage or gain access to sensitive information.
Three things programmers can do to make their programs robust:
Adhere to good programming practices
Carry out regular code reviews
Keep an audit trail.
Known vulnerabilities
Some programming languages contain known vulnerabilities.
For example, programs written in C can access computer memory
directly. This allows hackers to implement a ‘backdoor’ entry into
systems.
Bad programming practices include:
poor planning that does not take account of potential
security issues.
using a quick fix rather than taking time to solve a problem
properly
poorly structured code that does not adhere to agreed
standards
insufficient testing.
Code reviews
The purpose of a code review is:
to check that software adheres to agreed standards
to find any instances of inefficient code
to identify potential vulnerabilities.
Reviews are carried out by other programmers or by specialized software that checks the code
to make sure it meets a pre-defined set of rules. It can detect bugs and security issues and may
suggest ways to fix them.
If a code review identifies any issues, they must be put right before proceeding any further.
Audit trails
An audit trail helps improve accountability by keeping track of who made what changes and
when during the development process. Should a problem be discovered, it can be tracked back
to its source and the code rolled back to a version before the flaw was introduced.
Version control software is often used alongside audit trails, especially when a team of
programmers is working on a large or complex project. It uses a database to keep track of every
modification to the code. If a mistake is made, programmers can revert to an earlier version.
Programming languages
A programming language consist of a set of instructions and syntax rules, which are used to
write code. Programming languages can be grouped into two categories, low-level and high
level, based on how close they are to a recognizable ‘human’ language.
Low-level languages
Machine code and assembly language are low-level languages that work directly with a
computer’s hardware. A programmer must have detailed knowledge of a computer’s
architecture in order to write a program in a low-level language. They must be familiar with the
CPU’s instruction set (binary instructions, opcodes, that it recognizes and acts upon).
Machine code is written in binary, with even a simple program made up of thousands of 1s and
0s. This makes it extremely difficult for programmers to write and debug.
Assembly language is a bit easier for humans to work with. Instead of binary, it uses short
memorable keywords called mnemonics to represent instructions. Programs have to be
translated into machine code before they can be executed by the CPU.
Use: Device drivers and firmware for embedded systems are often written in low-level
languages.
High-level languages
High-level languages, such as Java and Python, are closer to human languages than low-level
languages. They use keyboards such as ‘print’, ‘if’ and ‘return’.
High-level languages are problem-oriented. They enable programmers to focus on their
program’s logic, rather than on how it will be implemented on a computer’s hardware.
High-level languages come with libraries of ready-made functions, integrated development
environments and editing tools to make it easier to write code.
A program written in a high-level language must be translated before it can be executed by a
CPU.
A single line of code written in a high-level language often requires multiple lines of machine-
code instructions to implement.
Use: Most software is now developed using a high-level language.
Low-level languages High-level languages
Are difficult and time-consuming to use. Are programmer-friendly.
Have few tools to help with maintenance Have tools that make maintenance and
and debugging. debugging easier.
Are machine-specific – programs written Are machine-independent (portable) –
in a low-level language will not run on a they will run on computers with different
computer with a different type of CPU. types of CPU.
Interact directly with the hardware, Are generally less memory efficient.
enabling memory to be used efficiently.
Interpreters and compilers
Programs written in a high-level language must be translated into machine code before the
processor can execute them. Compilers, interpreters and assemblers are examples
Compiler
A compiler translates the source code into a stand-alone machine code program (object code)
that can then be executed by the processor.
The translation is done once only and as a separate process.
The program that is run is already translated into machine code so it can be executed
more rapidly.
It protects the software from competitors who would otherwise be able to see the source
code.
If it encounters any errors, it carries on trying to compile the program and reports the
errors at the end. The programmers then have to use the error messages to identify and
remove the bugs.
You cannot change the program without going back to the original source code, editing
that and recompiling.
Interpreter
An interpreter translates the high-level code line by line into machine code. It is needed each
time the program is run.
When an error is found, the interpreter reports it, stops and pinpoints the error so that
the programmer knows where it has occurred.
The code is not platform-specific and can be run different operating systems and
platforms as long as there is an interpreter,
The program can be easily edited as it always exists as source code.
Every line has to be translated each time it is executed, and therefore it is slower to run.
Assemblers
Assemblers translate the mnemonics of assembly language into machine-code instructions.
Assembly language is very similar to machine code. There is one assembly language instruction
for each machine-code instruction