C01 Computer Systems - As
C01 Computer Systems - As
Records – rows
Fields - columns
Flat file databases are very simple but they are quick to set up, require less expertise to maintain and are
suitable for storing small amounts of data
1NF:
2NF:
1. Must be 1NF
2. Partial dependencies are removed so that every field is dependent on the primary key
Many-to-many relationships can’t exist so they must be resolved into two one-to-many relationships
using a linking table
3NF:
1. Must be 2NF
2. Transitive dependencies are removed. Fields whose value depends on the value of another field are
moved to their own table to prevent inconsistencies if case should arise when only one value could be
updated
Composite Primary Key - Primary key created by combining two fields (must produce unique values)
Partial Dependency - Where a composite key is needed to uniquely identify a record, a value that depends on
only part of the composite key
Dependency - Where the value of one field depends on another (e.g., the value of car_colour depends on
registration_number)
DATA REPRESENTATION (Two’s Complement, Sign and Magnitude, Floating Point and Binary Arithmetic):
The MSB become the sign bit – no longer represents a weighted value
1 – negative number
0 – positive number
Largest number that can be stored using sign and magnitude is +127 instead of +255
But can now represent negative numbers from -1 to -127
+/- 64 32 16 8 4 2 1
Two’s Complement
To easily write a positive binary number in its negative two’s complement version:
-128 64 32 16 8 4 2 1
0+0=0
0+1=1
1 + 1 = 0 carry 1
1 + 1 + 1 = 1 carry 1
To easily perform binary subtraction is to turn the number we want to subtract into its negative version by
copying every digit up to and including the first 1 and then flip them, 0 becomes 1 and 1 becomes 0, and add
the two numbers together using normal binary addition
Floating Point Binary:
Fixed point binary means the binary point does not move, that means there is a set number of bits for the
integer part and a set number of bits for the fractional part
Floating point binary means the binary point can 'float' or move up and down the number line. It stores the
number itself in the mantissa and the exponent stores the number of moves the binary point needs to make
Mantissa Exponent
There are many different ways to represent a number and we need a consistent way of storing floating point
binary numbers so that there is only ONE way to represent any number, so we normalize the number
Another advantage of normalized floating point binary is the assurance we are storing numbers with the
highest possible degree of accuracy
0 0 1 1 0 . 1 0 0 0
0 1 1 0 . 1 0 1 1
To normalize fractional numbers: 0.25
0 0 0 0 0 . 0 1 0
1 1 1 1 1 . 1 1 0
4. Next move binary point so it sits between the first 1 and 0 (normalized negative numbers start with
10)
5. So move 2 places to right
6.
1 1 1 1 1 1 1 . 0
7. As we had to move binary point 2 places to the right to get to its normalized position, we need to
move it 2 places to the left to put it back in the correct position
8. Last stage is to store mantissa which is the number from the original line (MUST START WITH 10 AS IT
IS NEGATIVE)
1 . 0 0 0 0 1 1 0
Floating Point Arithmetic:
1. Work out where the binary point should be in each number using the exponent
2. Line both numbers up on the normal binary number line so the binary points are in the same position
3. Fill in empty columns with 0s
4. Add numbers normally in binary
0 0 1 1 0 . 0 1 1
1. As number is POSITIVE, we move the binary point in between where the first 0 and 1
2.
0 0 . 1 1 0 0 1 1
3. As we had to move binary point 3 places to left to get to its normalized position, we need to move it 3
places to the right to put it back in the correct position, exponent must be +3
4. Last stage is to store mantissa which is the number from the original number line (MUST START WITH
01 AS IT IS POSITIVE)
0 . 1 1 0 0 0 1 1
5. There is a problem, ran out of space in mantissa and can’t store the final two bits which represent 1/4
and 1/8
6. We can increase the total number of bits we are allowed to use to store the normalized floating point
binary number. If we choose second option we need 10 bits in total: 7 for mantissa and 3 for
exponent
Subtracting normalized floating point numbers:
1. Work out where the binary point should be in each number using its exponent
2. Line both numbers up on the normal binary number line so the binary points are in the same position
3. Fill in empty columns using 0
4. SINCE WE ARE SUBTRACTING, to subtract binary numbers we turn the number we want to subtract
into its negative version and perform normal addition on the two numbers
5. To convert the number into its negative version
a. Start with LSB
b. Copy each bit as it appears up to and including the first 1
c. Swap all remaining bits – 0 becomes 1 and 1 becomes 0
6. Add numbers normally in binary
Paradigms:
Object-Oriented – organizes code into reusable pieces of code called classes (C++, Python, Java)
Assembly code:
Complete list of instructions supported by the processor is called the instruction set. Each instruction has an
operation code called an opcode. Each instruction usually has an address or data called an operand. Each
opcode has an assembly language mnemonic. There is a one-to-one relationship between a mnemonic in
assembly and an opcode in machine code
Indirect –Value stored is the address of where the value to be fetched from is stored
Indexed – Value in accumulator add index register gives the address of stored value needing to be fetched
DATA STRUCTURES (1D, 2D arrays, Binary Search Trees)
An array is a variable that can contain more than one data item
Arrays are a static data structure – you can’t change the size of an array once set up
Can store more than one data Can only store one data type Can store more than one data
type type
Dynamic data structure – size Static data structure – size is Static data structure – size is
can be changed during run-time fixed during run-time fixed during run-time
A linked list is a dynamic data structure. A linked list contains nodes that hold the data itself and a pointer to
the next item in the list in sequence.
A graph is a collection of nodes which are connected between one another. Each connection between two
nodes is called an edge. Graphs can be directed or undirected. They can also be weighted or unweighted.
Adjacency list Adjacency matrix
Only stores data where there is an adjacency (edge) Stores a value for every combination of node
so requires less memory adjacencies so requires more memory
The list has to be scanned to identify whether Adjacencies can be identified more quickly as every
particular adjacencies exist, which increases the combination is already stored. Effectively the
time taken to process the data matrix forms a look-up table of each node to every
other node
Items are pushed onto the top of the stack when they are added to it and popped off at the top when they are
deleted from it. It is also possible to peek at the top item without deleting it.
Peek – returning the value from the top of the stack without removing it
Stack is LIFO – last item to be pushed onto the stack must also be the first item to be popped off. Stack has a
stack pointer that always points to the node at the top
Any attempt to push an item onto a full stack is called a stack overflow
Any attempt to pop an item off an empty stack is called a stack underflow
Items are enqueued at the back of the queue and dequeued from the front of the queue
It is also possible to peek at the front item without deleting it
Queue is FIFO
Queue has a back pointer that always points to the last item – tail pointer
Queue also has a front pointer that always points to the first item – head pointer
Since both back and front pointers are moving in the same direction as items being added and removed, the
array will quickly run out of space
Solution is to cycle the back pointer to the front of the array when it reaches the end
This is called a circular queue
User
Application software
User interface
Hardware
Utility programs
Memory management
File management
Device drivers
Multi-tasking – more than one program open and running at the same time. Processor allocates a small
amount of time to each process and cycles between them. This happens so quickly, it appears as if multiple
programs are executing simultaneously
User management – allows multiple users to log into the same computer
Operating system will keep settings for each user such as icons, desktop backgrounds
Each user may have different access rights to files and programs
Visual
Interactive
Intuitive
Pages – sections of RAM that are all fixed at the same size because they ignore the internal structure of the
program to use up the space available in RAM
Segmentation – sections of RAM that are all different sizes because they follow the internal structure of the
program to use up the space available in RAM
- Slows down performance even when there is no thrashing (computer spends more time swapping
data between RAM and virtual memory than running programs, causing it to slow down)
- Virtual memory wears out HDDs and SSDs especially if thrashing occurs
Interrupts
Processor will need to stop executing its current program to run code for the interrupt, known as the interrupt
service routine
Interrupt service routine is a program with a set of instructions that need to be fetched, decoded and executed
to carry out the operations of the interrupt
The contents of the program counter need to be changed to point to the address for the first instruction of the
interrupt
When an interrupt is received, the values held in the registers are copied into a data structure in memory –
stack
These values are pushed onto the stack in a stack frame – save them for later retrieval
Once ISR A has completed executing, pop the frame off the top of the stack to retrieve the previous values for
the original program, load them back into the processor registers and carry on executing the original program
where we left off
Scheduling - Scheduler manages which process to execute next and the length of time the next process can
execute for
First come first serve (FCFS) – processes are executed in the order they arrive. If process takes a long time,
others behind will have to wait
Shortest job first (SJF) – picks the processes that take the shortest amount of time and runs them until they
finish. The scheduler needs to know how long each process will take
Round Robin (RR) – Each time is allocated a fixed amount of time known as a time slice or quantum. If a
process is not complete by the end of its time slice, it returns to the back of the ready queue
Shortest remaining time (SRT) – SRT is a pre-emptive algorithm meaning processes can be suspended if a
higher-priority process joins the queue
Multi-level feedback queues (MLFQ) – Several ready queues are used, each with different scheduling
algorithm. Jobs can move between queues as their priorities change
MLFQ allow for processes to be shifted between queues. If process has too much CPU time it will be moved to
a lower priority queue.
If the process is waiting too long in a low-priority queue it will be moved to a higher priority queue
Pre-emptive – CPU can stop a running process and switch to a new one if it’s more important or shorter
Non-pre-emptive – once a process starts, it runs to the end without being interrupted
Types of OS:
Multi-tasking OS – computer will manage the user’s various permissions and access rights when they log on
Distributed OS - operating system controls and coordinates the computers, presenting them to the user as if
they were a single system
Embedded OS – tend to run on dedicated hardware so they run with maximum efficiency, using low-powered
processors and very little memory
Real-time OS – used in safety-critical environments processes have to be guaranteed to execute within a
known time frame. Plent of redundancy is built into these systems so they can handle sudden increases in
input
BIOS:
BIOS is responsible for loading the operating system when the computer first turns on. It first checks that all
the hardware it needs is connected an working using a Power-On Self Test (POST)
A boot loader program (bootstrap) is used to load the operating system kernel into memory. The operating
system can take over at this point and boot up the rest of the system
Device Drivers
A piece of software that tells the operating system how to communicate with a device
Document printed from a word processor should look the same no matter what make or model of printer sent
to.
The device driver translates the operating system instructions to print the document into a series of
instructions that a specific piece of hardware will understand
Virtual machine - A program that has the same functionality as a physical computer
Memory Address Register – Stores the address of the next instruction to be fetched or stored
Control Unit – coordinates all and communicates the all parts of the CPU and directs the flow of data between
the CPU and other devices
Busses:
Address bus – carries memory addresses that identify where the data is being read from or written to
Control bus – carries command and control signals to and from every other component of the CPU / computer
What is a computer – an electronic device that takes input, processes data and delivers output
FDE Cycle:
Fetch –PC holds the address of the next instruction. This address is copied to the MAR. A read signal is sent to
main memory via the control bus. The instruction at that address is sent back via the data bus to the MDR. The
instruction is copied into the CIR. The PC is increased to point to the next instruction.
Decode – Instruction held in CIR is now decoded by decode unit. Instruction is made up of two parts. Opcode
tells what to do and operand tells what to do it to. The operand could contain the actual data or an address
where the data is found. By decoding instruction we see the operation.
Execute – we can now execute the instruction that has been decoded
Performance of CPU:
Clock speed – measures how many FDE cycles that can be executed per second
Cache size – temporary storage of data and instructions being read to and written from, located closer to CPU.
Stores copies of recent data and instructions, faster than RAM, quicker to fetch if closer to the CPU than in
RAM
Number of Cores – more cores allows the CPU to process multiple instructions or tasks at the same time,
improving performance for multitasking or multi-threaded programs
Pipelining:
Instruction pipeline consists of the various stages an instruction must move through the processor
The arithmetic pipeline consists of the parts of an arithmetic operation that can be broken down and
overlapped as they are carried out
DATA HAZARD – an instruction depends on the result of a previous instruction that is not available yet
CONTROL HAZARD – a branch (IF statement) changes the next set of instructions to be executed so the
instructions behind the branch in the pipeline are the wrong ones so flush it out.
Harvard Architecture:
SIMD – parallel processing is where a processor carries out a single instruction on multiple data items at the
same time
MIMD – another version where multiple instructions are carried on multiple data items across several cores
Distributed computing – where multiple computers on a shared network each take on part of a bigger problem
Instruction set – set of all instructions written in machine code that can be recognised and executed by a given
processing unit
CISC
RISC
GPUs
Each core has its own private L1 cache (fast and small).
All cores can access shared L2 cache (bigger, a bit slower).
What is a thread - Process running on a core. Each thread keeps track of its own program counter
Parallel processing – processing of program instructions by dividing them between multiple processors or
processor cores
Parallel processing is achieved by the processors or processing cores carrying out a single job split into tasks
with each task able to execute on any unit
The main processor or processing core fetches and decodes an instruction and then farms off the various parts
of the program to other processing units
A multicore system has more than one processing unit in a single processor which can independently process
instructions at the same time