Computer Architecture Hnd1 Notes
Computer Architecture Hnd1 Notes
Computer architecture
Learning objectives
● 1.3.2 - show understanding of the basic Von Neumann model for a computer system and the stored
program concept (program instructions and data are stored in main memory and instructions are
fetched and executed one after another)
● 1.3.2 - describe the stages of the fetch-execute cycle, including the use of registers and buses
Introduction
"A computer processor does moronically simple things — it
moves a byte from memory to register, adds a byte to
another byte, moves the result back to memory. The only
reason anything substantial gets completed is that these
operations occur very quickly. To quote Robert Noyce, ‘After
you become reconciled to the nanosecond, computer
operations are conceptually fairly simple.'" - Giorgos
Petkakis
There are a couple of ways the Von Newmann architecture of a CPU might be illustrated.
● Simplified representation
Bus:
● Buses are the means by which data is transmitted from one part of a computer to another, connecting
all major internal components to the CPU and memory.
● A standard CPU system bus is comprised of a control bus, data bus and address bus.
● Think of a bus as a set of wires, one for each bit. Eg: In a 64 bit processor, the bus will have 64 wires.
Fetch:
● Program Counter (PC) contains the address of the next instruction.
● PC copies the address of the next instruction to Memory Address Register (MAR).
● MAR places the instruction address on the address bus. This causes the data in memory stored at
that address to be loaded into the Memory Data Register (MDR).
● Instruction Register (IR) (also the Current Instruction Register (CIR) ) loads the instruction from the
MDR
● Program Counter will increment to point to the next instruction.
Decode:
● CU: Determines (decodes) what is required to complete the instruction pending in the IR.
Execute:
● The instruction is performed
● ALU: Performs any calculation required by the CU instruction. The ACCumulator is used as an internal
“working memory” register for the ALU. Data is moved in and out of the ALU via the MAR/MDR.
Sourced from:
Learning objectives
1.3.5 Memory, storage devices and media
● show understanding of the difference between: primary, secondary and off-line storage and provide
examples of each, such as: primary: Read Only Memory (ROM) and Random Access Memory (RAM)
secondary: hard disk drive (HDD) and Solid State Drive (SSD); off-line: Digital Versatile Disc (DVD),
Compact Disc (CD), Blu-ray disc, USB flash memory and removable HDD
● describe the principles of operation of a range of types of storage device and media including
magnetic, optical and solid state
● describe how these principles are applied to currently available storage solutions, such as SSDs,
HDDs, USB flash memory, DVDs, CDs and Blu-ray discs
● calculate the storage requirement of a file
Introduction
Read: Sections 6.4 of iGCSE Computer Science by Watson & Williams
DRAM vs SRAM
● Remember back to when we looked at logic circuits. The "d-latch" logic circuit we looked at is an
example of how a "flip-flop" can be created.
● For an online demo of a d-latch in action, visit https://logic.ly/demo or
https://www.youtube.com/watch?v=peCh_859q7Q (from about 6:00 onward)
● Be aware of the difference between FLASH and EEPROM based SSDs. Which type do you have?
Questions
The supermarket uses secondary storage and off-line storage to store data about its stock.
Explain what is meant by (a) secondary storage and (b) off-line storage. [4] (June 2018, p11, q8d)
Identify three similarities between CDs and DVDs. [3] (June 2018, p13, q11)
Five storage devices or media are listed. Show whether each storage device or media is an example of
primary, secondary or off-line storage.
● External HDD
● RAM
● Internal SSD
● ROM
● DVD
A sports events company uses a digital camera attached to a drone (small flying system), to video their
events from the sky. The video is stored as it is captured, on a device that is attached to the drone.
● Identify the most suitable type of storage to store the video
Optical OR Magnetic OR Solid state [1]
● Explain the reasons for your choice .
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
A computer uses RAM and ROM to store data. Indicate which statements apply to each type of memory:
RAM ROM
Sarah stores data electronically. Describe three methods that she could use to avoid loss of stored data.
Method 1 ..........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Method 2 ..........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Method 3 ..........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Describe two differences between Read Only Memory (ROM) and Random Access Memory
(RAM).
Difference 1 .......................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Difference 2 ......................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
State which types of storage device or media would be most suitable for these scenarios.
For each device or media, justify your choice.
(a) Creating a backup of 150 GB of data.
...................................................................................................................................................
Justification ...............................................................................................................................
................................................................................................................................................... [2]
(b) Storing applications on a tablet device.
...................................................................................................................................................
Justification ...............................................................................................................................
................................................................................................................................................... [2]
(c) Storing a 1200 MB high-definition promotional movie about a new car. The movie is to be given to people
who are interested in buying a new car.
...................................................................................................................................................
Justification ...............................................................................................................................
................................................................................................................................................... [2]
3. Memory & storage file formats
Learning objectives
● 1.1.3 - show understanding that sound (music), pictures, video, text and numbers are stored in
different formats
● 1.1.3 - show understanding of the concept of Musical Instrument Digital Interface (MIDI) files, JPEG
files, MP3 and MP4 files
● 1.3.5 - calculate the storage requirement of a file
● What is the file compression algorithm used by MP3? What sounds does it remove?
● What is the consequence of using a LOSSY format?
● If an MP3 has a bit rate of 200 kilobits/second, how many megabytes would a 3 minute (180 second)
recording be?
● What is the key difference between MP3 and MP4?
● Complete activity 6.1
● If a RAW Bitmap photo is taken on an 8 megapixel camera, how many Megabytes of storage would
this consume?
● What factors does JPEG compression rely on to maintain the quality of an image?
● Complete activity 6.2
● Why is formatting of a text file important for programs to correctly interpret the content of text files?
● What is different about the compression used with text files, and why does it matter?
● What is a common program on your computer that can be used to read/write text files?
Exercises
Create a simple Python "file storage calculator" that will prompt the user for pixel dimensions for a photo, plus
the bit-colour depth (unless specified in the question, colour depth should be assumed to represent the entire
pixel rather than each colour channel).
It should output the resulting file size in kilobytes and megabytes (to one decimal place). Remember 8 bits =
1 byte, 1024 bytes = 1 KB, 1024 KB = 1 MB.
For example:
File size calculator!
Pixels wide? 640
Pixels high? 480
Bits of color depth: 8
Working...
The resulting bitmap will be 300.0 KB or 0.3 MB
Questions
An image is to be stored electronically.
The image is 256 pixels high by 200 pixels wide with a 16-bit colour depth.
Calculate the file size of the image. You must show all of your working.
Jamelia wants to store an image file. The image has an 8-bit resolution and is 150 pixels by
100 pixels in size. Calculate the file size of the image. Give your answer in kilobytes (kB). Show all of your
working.
File size ...........................................................................................................kB [3]
Explain the difference between a Musical Instrument Digital Interface (MIDI) file and a MP3 file.
..........................................................................................................................................................
..........................................................................................................................................................
4. Compression
Learning objectives
1.1.3
● show understanding of the principles of data compression (lossless and lossy) applied to
music/video, photos and text files
Introduction
Read: Sections 6.3 of iGCSE Computer Science by Watson & Williams
Why break with tradition? Here are a couple of great Tom Scott videos on compression! :-p
● Lossly compression as seen in video https://www.youtube.com/watch?v=r6Rp-uo6HmI
● Huffman lossless compression https://www.youtube.com/watch?v=JsTptu56GM8
Exercises
Python has a built in compression library you can easily experiment with.
test = """Programmers are in a race with the Universe to create bigger and better
idiot-proof programs, while the Universe is trying to create bigger and better
idiots. So far the Universe is winning. (Rich Cook)"""
test = test.encode('utf-8') # Convert to utf-8 bytes string
# Download a photo
url = "https://apod.nasa.gov/apod/image/1908/5D4_5485seeley_1067.jpg"
response = requests.get(url)
● What are the parts of the image that are the first to deteriorate?
● At what minimum level of quality was the image "acceptable" to you?
● How significant was the difference in file size for each level of quality? What would make the best
"happy median" in your view?
● What would be the features of a photo that might determine if you selected a higher or lower quality?
Questions
Michele wants to email a file to Elsa. The file is too large so it must be compressed.
(a) Name two types of compression that Michele could use.
Compression type 1 ..................................................................................................................
Compression type 2 .................................................................................................................. [2]
(b) The file Michele is sending contains the source code for a large computer program. Identify which type of
compression would be most suitable for Michele to use.
Explain your choice.
Compression type ......................................................................................................................
Explanation ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
................................................................................................................................................... [4]
Large files can be compressed to reduce their file size. Two types of compression that can be used are lossy
and lossless. Explain how a file is compressed using lossless compression.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
The following are four different file formats that use compression.
State whether each file format uses lossy or lossless compression.
● JPEG
● MP3
● MP4
● ZIP
5, 6. High & low level languages; compilers; assembler
Learning objectives
1.3.7 High- and low-level languages and their translators
● show understanding of the need for both high-level and low-level languages
● show understanding of the need for compilers when translating programs written in a high-level
language
● show understanding of the use of interpreters with high-level language programs
● show understanding of the need for assemblers when translating programs written in assembly
language
Introduction
Read: Chapter 7 of iGCSE Computer Science by Watson & Williams
As we know, a computer program is a list of instructions that enable a computer to perform a specific task.
The languages that we use to write our computer programs in are generally split into two categories,
depending on the task and the hardware being used. These are high level languages and low level languages.
When we think about computer programmers, we are probably thinking about people who write in high-level
languages.
High level languages are written in a form that is close to our human language, enabling the programmer to
just focus on the problem being solved.
No particular knowledge of the hardware is needed as high level languages create programs that are portable
and not tied to a particular computer or microchip.
These programmer friendly languages are called ‘high level’ as they are far removed from the machine code
instructions understood by the computer.
Advantages
Modern high level languages would come with features such as:
Low level languages are used to write programs that relate to the specific architecture and hardware of a
particular type of computer. They are closer to the native language of a computer (binary), making them
harder for programmers to understand. Low level languages include Assembly Language and Machine Code.
Assembly Language
● Few programmers write programs in low level assembly language, but it is still used for developing
code for specialist hardware, such as device drivers.
● It is easily distinguishable from a high level language as it contains few recognisable human words
but plenty of mnemonic code.
● Typical assembly language opcodes include: add, subtract, load, compare, branch, store
Advantages
● Can make use of special hardware or special machine-dependent instructions (e.g. on the specific
chip)
● Translated program requires less memory
● Write code that can be executed faster
● Total control over the code
● Can work directly on memory locations
Machine Code
Hello world in C
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
; ---------------------------------------------------------------------------------
; Writes "Hello, World" to the console. Runs on 64-bit Linux only.
; To assemble and run:
; nasm -felf64 hello.asm && ld hello.o && ./a.out
; ---------------------------------------------------------------------------------
global _start
section .text
_start: mov rax, 1 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to write
mov rax, 60 ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
section .data
message: db "Hello, World", 10 ; note the newline at the end
There is an online simulator that uses a slightly simplified assembler we can experiment with. It is based on
an 8-bit cpu and has 256 bytes of memory.
● http://schweigi.github.io/assembler-simulator/
All instructions (code) and variables (data) need to fit inside the memory. For simplicity every instruction (and
operand) is 1 byte. Therefore a MOV instruction will use 3 bytes of memory. The simulator provides a console
output which is memory mapped from 0xE8 to 0xFF. Memory mapped means that every value written to this
memory block is visible on the console.
A detailed look at the instructions available in the simulator are available here:
http://schweigi.github.io/assembler-simulator/instruction-set.html
As an example, the following is my implementation of a simple counter, that outputs 0 through 9. Can you
modify it? A couple of suggestions:
● Turn it into a countdown
● Make it work for values greater than 10 (more complicated than it might initially think)
; Counts from 0 to 9
start:
loop:
; PART 1 - PRINT VALUE OF i
MOV D, 232 ; Address of output buffer
MOV A, i ; Look up the address of var `i`
MOV C, [A] ; Look up value at the address in A
ADD C, 48 ; Convert from integer to character by adding 48
MOV [D], C ; Copy value in C to address of output buffer
; PART 2 - INCREMENT i
MOV A, i ; Look up the address of var `i`
MOV B, [A] ; Look up value at the address in A
INC B ; Increment the value
MOV [A], B ; Copy value back to the address referred to by A
Question: Why does adding 48 convert the integer to a character? (make sure I discuss this in the lesson,
don't let me forget)
(don't worry if you don't get anywhere with this… it is waaaaaay beyond the course and just included for some
nerdy fun. It took me a solid hour just to make this above code sample)
Questions
Translators, such as a compiler and an interpreter, are used when writing and running computer
programs. Describe how a compiler and an interpreter translates a computer program.
Compiler ...........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Interpreter .........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.......................................................................................................................................................... [6]
Dimitri is writing a computer program in a high-level language. He needs to send just the machine code for
the program to his friend, electronically. It is important that the program is executed as quickly as possible.
Identify which translator will be most suitable for Dimitri to use. Explain your choice.
Type of translator .............................................................................................................................
Explanation ......................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Explain two reasons why a computer programmer may choose to write a program in a high level
language, rather than a low-level language.
Reason 1 ..................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Reason 2 ..................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4] (Winter 2018, p12, q6b)
Three examples of computer code are given in the table. Indicate whether the computer code is a high level
language, assembly language or machine code.
10110111 FOR X = 1 TO 10 INP X
11001100 PRINT X STA X
01011100 NEXT X LDA Y
David is writing a program using a high-level language. The program will be published and sold for
profit.
(a) David uses an interpreter when creating the computer program. State three features of an interpreter.
Feature 1 ..................................................................................................................................
...................................................................................................................................................
Feature 2 ..................................................................................................................................
...................................................................................................................................................
Feature 3 ..................................................................................................................................
................................................................................................................................................... [3]
(b) David compiles the program when he has completed it. Explain two benefits of compiling the program.
Benefit 1 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Benefit 2 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................[4]
(Winter 2018, p13, q7)
If you want to see what full x86 assembler looks like, try this emulator
● https://carlosrafaelgn.com.br/asm86/
7. Operating systems & interrupts
Learning objectives
1.3.6 Operating systems
● describe the purpose of an operating system (Candidates will be required to understand the purpose
and function of an operating system and why it is needed. They will not be required to understand
how operating systems work.)
● show understanding of the need for interrupts
Introduction
Read: Sections 4.1, 4.2, 4.3 of iGCSE Computer Science by Watson & Williams
In more detail, various roles of the operating system include (be able to provide a definition or basic
description of each)
● Human computer interface (HCI)
● Multi tasking
● Multi programming
● Batch processing
● Error handling
● Loading and running of application software
● Management of user accounts
● Providing file utilities (copy, save, sort, delete files etc)
● Processor management
● Memory management
● Real-time processing
● Interrupt handling
● Security
● Input and output devices
Interrupts
● An interrupt is a signal sent to the processor that interrupts the current process. It may be generated
by a hardware device or a software program. A hardware interrupt is often created by an input device
such as a mouse or keyboard. - From https://techterms.com/definition/interrupt
import sys
from datetime import datetime
import time
interrupts = 0
while interrupts < 3:
try:
while True: # Infinite loop we can't escape from
print('The time is ', datetime.now().strftime("%H:%M:%S"))
time.sleep(0.2)
except KeyboardInterrupt:
print("You interrupted me. That wasn't very nice. You can't stop me tho.")
interrupts += 1
print("Fine, you win, I'll stop")
Questions
One of the roles of an operating system is to deal with interrupts.
(a) Explain the term interrupt.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
(b) Identify three devices that make use of interrupts.
Device 1 ....................................................................................................................................
Device 2 ....................................................................................................................................
Device 3 ....................................................................................................................................
Describe the purpose of an interrupt in a computer system. [4] (Winter 2018, p12, q8)