OCR AS and A Level Computer Science - Textbook Notes
OCR AS and A Level Computer Science Notes
- This is an OCR endorsed textbook.
- The textbook is divided into twelve sections.
- Each chapter's material can be taught in one or two lessons.
- Material applicable only to the second year of the full A Level is clearly marked.
- Each chapter contains exercises and questions with answers available in a Teacher's Pack from www.pgonline.co.uk.
- The book covers topics examined in written papers at AS and A Level.
- Sections 10, 11, and 12 focus on problem-solving skills.
- Pseudocode is used for algorithms, with sample Python programs in the Teacher's Pack.
Section 1: Components of a Computer
- Overview of processor components, performance, types, input/output and storage devices.
Chapter 1: Processor Components
- Objectives:
- Describe the function of the ALU (Arithmetic Logic Unit) and Control Unit.
- Describe the Fetch-Execute cycle and the roles of registers like Program Counter, Accumulator, Memory Address Register, Memory Data Register, and Current Instruction Register.
- Central Processing Unit (CPU):
- Also known as the processor.
- Components: Control Unit, ALU, Buses, Dedicated Registers.
- Control Unit:
- Controls and coordinates CPU activities.
- Manages data flow between CPU and other devices.
- Fetches, decodes, manages execution, and stores data.
- Buses:
- Parallel wires connecting computer components (8, 16, 32, or 64 lines).
- Three buses connect the processor to main memory:
- Address Bus: Sends memory location addresses from CPU to memory (unidirectional).
- Data Bus: Bidirectional path for data and instructions between components.
- Control Bus: Transmits commands, timing, and status information (bidirectional).
- System Bus: Collective term for the three buses.
- Shared transmission medium.
- Control Bus Control Lines:
* Bus Request: Device requests data bus use.
* Bus Grant: CPU grants data bus access.
* Memory Write: Data written into addressed location.
* Memory Read: Data placed on data bus from addressed location.
* Interrupt Request: Device requests CPU access.
* Clock: Synchronizes operations. - Address Bus: Transmits memory addresses of operands for instruction execution using memory words (16, 32, or 64 bits).
- ALU (Arithmetic-Logic Unit): Performs arithmetic (ADD, SUBTRACT, MULTIPLY, DIVIDE) and logical (AND, OR, NOT, XOR) operations; also shift operations.
- Registers: High-speed memory cells within the CPU (typically up to 16 general-purpose).
* Accumulator: Single register for arithmetic and logical operations.
* Program Counter (PC): Holds the address of the next instruction.
* Current Instruction Register (CIR): Holds the current instruction (opcode and operand).
* Memory Address Register (MAR): Holds the memory location address for fetching/writing data.
* Memory Data Register (MDR): Temporarily stores data read from/written to memory (also known as Memory Buffer Register). - Fetch-Decode-Execute Cycle:
* Fetch: The address from PC is copied to MAR. The instruction at that address is copied to MDR. Simultaneously, the PC is incremented.
* Decode: Instruction in CIR is decoded, separating opcode and operand. The operand can be an address copied to MAR or the actual data copied to MDR.
* Execute: Instruction/opcode is carried out on the operand by ALU, using the accumulator when needed.
- Factors Affecting CPU Performance:
- Clock Speed: Synchronization of CPU operations; measured in GHz (billions of cycles per second). Greater clock speed results in faster instruction execution.
- Number of Cores: Multiple processors on a single chip (dual-core, quad-core). Enables parallel processing; software must take advantage of multiple cores.
- Cache Memory: Small, fast memory inside the CPU. Instructions fetched from main memory are copied to cache.
- Level 1 Cache: Extremely fast but small (2-64KB).
- Level 2 Cache: Fairly fast and medium-sized (256KB-2MB).
- Level 3 Cache: Some CPUs.
- Pipelining: Improves performance by fetching the next instruction while the processor performs arithmetic/logic operations. Instructions are held in a buffer close to the processor.
* Intel's Pentium chip executes as many as six instructions simultaneously using pipelining. - Words and Word Size:
- Memory words are fixed-size groups of digits (typically 16, 32, or 64 bits).
- Each word has a specific address.
- The width of the address bus determines memory capacity (e.g., 8-line bus allows a maximum memory capacity of 256 memory locations).
- A 32-bit address bus can address 232 (4,294,967,296) memory locations giving an addressable memory space of 4 GiB.
- GiB: Gibibyte (1024^3 bytes ≈ 1.074 billion bytes).
- Data Bus: Transmits data between processor components and memory.
- The size of the data bus relates to the largest operand that is an address or actual value.
- A wider data bus transmits larger values or more characters at a time, or allow more bits per instruction.
Chapter 3: Types of Processor
- Memory and the Stored Program Concept: Computers based on the von Neumann architecture use a shared memory and bus for both data and instructions.
* Programs must reside in main memory to be executed serially by a processor performing arithmetic and logical operations. - Harvard Architecture: A computer architecture with physically separate memories for instructions and data, used extensively with embedded DSP systems.
* Different memories can have different characteristics.
* Some systems use a larger word size for instructions and wider instruction address bus than data bus. - Comparison of von Neumann and Harvard architectures
- von Neumann architecture:
- Conventional processors in PCs, servers and embedded systems.
- Data and programs share the same memory.
- One bus is used for data and instructions.
- Programs can be optimized in size
- Harvard architecture:
- Used in DSP, embedded systems, mobile communication systems, audio, speech and image processing.
- Instructions and data are held in separate memories.
- Parallel data and instruction buses may be used.
- Programs tend to be large
- Contemporary processor architectures
- There is one main memory for holding both data and instructions, but CPU cache memory is divided into an instruction cache and a data cache, and Harvard architecture is used as CPUs access the cache.
- Complex Instruction Set Computers (CISC)
* Uses a large instruction set to accomplish tasks in as few lines of assembly language as possible.
* Complex instructions are built into the machine's hardware.
* Distinguishing feature of a CISC instruction is that it combines a load/store instruction with the instruction that carries out the actual calculation.
* The instruction is equivalent to the high level instruction a = a * b.
* Advantage is very little work had to be done by the compiler, and less RAM required to store instructions, but had to be built into the hardware even though only 20% of them were used in the average program. - Reduced Instruction Set Computers (RISC)
* Employs simple instructions each taking one clock cycle.
* The LDA, R1, A
LDA R2, B
MULT R1, R2
STO R1, A assembly language would do the equivalent instruction a = a * b.
* Compilers has to do more work to translate high-level code into machine code.
* More RAM is required to store the machine code instructions.
* Each instruction takes the same amount of time, making pipelining possible.
* RISC has largely replaced CISC in processor design. - Multi-core CPU Multi-core CPUs distribute workload across multiple CPU cores, achieving significantly higher performance.
* Depends on software's ability to take advantage of parallel processing. - Graphics processing unit (GPU) GPU is a specialised electronic circuit which is very efficient at manipulating computer graphics and image-processing. Its highly parallel structure makes it suitable for tasks where processing of large blocks of visual data is done simultaneously, i.e. in parallel.
- Barcodes: Used for identification in thousands of applications. There are two types:
* Linear barcodes
* 2D barcodes like QR codes - Different Barcode Readers: Pen-type readers, laser scanners, CCD readers, camera-based readers.
- Pen-type readers: Uses a light source and a photodiode to measure reflected light intensity.
* Durable, but requires direct contact with the barcode. - Laser scanners: Use a laser beam as the light source and are reliable and economical for low-volume applications.
- Camera-based readers: Use a camera and image processing to decode 1D or 2D barcodes.
* Can read barcodes on any surface, including damaged or poorly printed ones - Digital Cameras: Use CCD or CMOS sensors to record images. CCD sensors produce higher-quality images with more power consumption. CMOS sensors are more power-efficient and suitable for mobile devices.
- Radio Frequency Identification (RFID): An input device to read the signal from an RFID chip.
* RFID tags identify and track items without line of sight, from up to 300 meters away.
* Active Tags: Larger tags that include a battery to transmit signals.
* Passive Tags: Cheaper tags without a battery rely on radio waves emitted from a reader to send data.
Chapter 5: Output Devices
- Output Devices: Transform computer data into human-understandable forms (text, images, audio, etc.).
- Screens:
* LCD monitors: Use liquid crystals and LED backlights; provide sharper images, vivid colors, and energy efficiency.
* OLED screens: Brighter, thinner, and lighter; use plastic for flexibility; have faster refresh rates and truer colors. They have a shorter lifespan. - Printers:
* Laser printers: High-quality, high-speed printing using toner. Color laser printers are expensive to run because it contains CMYK cartridges and the paper must go through a process four times for each colour. Limited by the 1200 dpi to not take photorealistic quality prints.
* Inkjet printers: Spray minute dots of ink. Resolution, number of color cartridges and paper quality can help produce good quality and photorealistic prints. Cheaper than laser printers but slower.
* Dot matrix printers: Impact printers using a matrix of pins striking the paper through an inked ribbon. Noisy with poor print quality, but operate in damp or dirty environments and can operate when multi-part stationery is required, giving 2 carbon copies along with the original print.
* 3D printers: Can create car/aeroplane parts, medical equipment, fashion accessories. Can create spares for obsolete equipment and prototypes of new products. - Multimedia Projectors: Used to show lesson prep in advance, teach to multiple groups, able to deliver text, graphics, audio and video on the screen, display images or videos from the Internet, display PC applications or programs, and use the screen interactively, adding impact to every lesson.
- Computer Speakers: Output music, voice, and video soundtracks. Ranging from basic inbuilt speaker to a high quality speaker that can connect separately, and when in use, they disable the inbuilt speakers.
- Actuators: Motors used with sensors to control a mechanism (opening windows, starting pumps, etc.).
Chapter 6: Storage Devices
- Need for Secondary Storage: Secondary storage is not directly accessible to the processor and has slower access speeds. But secondary storage retains data when power is off (internal hard disks, optical media, solid state disks).
- How Storage Devices Store Data: All storage devices store data as a 1 or 0 using various techniques all allowing for toggle state without use of power.
- Hard Disk: Use rigid rotating platters coated with magnetic material. Ferrous particles are polarized to represent 0 (North) and 1 (South). The disk spins very quickly at speeds of up to 10000 RPM. Smaller, denser surface areas spinning under the read-write heads mean that newer 3.5 inch disks have capacities of up to 640 GB.
- Optical Disk: Different formats: CD-ROM (read-only), CD-R (recordable), CD-RW (rewritable.). An optical disk works by using a high powered laser to burn sections of its surface, making them less reflective. The added capacity is owing to the shorter wavelength in the laser they use and the greater number to fit in the same space along the track, and also means that the track can be more tightly wound, and therefore much longer.
- CD-ROM holds about 700MB of data, whereas a Blu-Ray disk (designed to supersede the DVD disk) can hold 50GB.
- Solid-State Disk (SSD): Uses NAND flash memory cells. They have faster access speed than hard disks, no need to move a read-write head across the disk (one piece of data can be accessed just as quickly as any other), consume less power, more durable, and are silent in operation. SSDs cannot overwrite existing data. The old data must be erased before data can be written to the same location, and although data can be written in pages, the technology requires the whole block to be erased.
- RAM and ROM: Computers have two kinds of internal memory: random access memory (RAM) and read-only memory (ROM).
* RAM is is used to store programs and data that are currently being used. It is volatile, meaning that its contents are lost when the computer is switched off.
* ROM is used to hold information that needs to be permanently in memory. The bootstrap loader, for example, must be held in ROM. In embedded systems such as the software inside a washing machine, vehicle or camera, for example, never changes so is held in ROM. - Virtual Storage: Uses the hard disk as an extension of memory when RAM is insufficient, slowing down performance.
Section 2: Systems Software
- Overview of operating systems, utility programs, application software, programming language translators.
Chapter 7: Functions of an Operating System
- Operating System (OS):
- Program or set of programs that manages computer operations for the user.
- Bridge between the user and hardware.
- Loader program loads the OS from storage into RAM.
- Functions of an OS:
* User interface.
* Memory Management.
* Interrupt Service Routines.
* Processor Scheduling.
* Backing Store Management.
* Management of Input and Output. - Memory Management: Allocating memory space for programs, files, and data.
- Paging: Divides memory into fixed size pages to allocate space for all tasks running on a PC.
- Segmentation: Division of address space into segments of different length.
- Virtual memory: Using secondary storage (hard disk) as an extension of RAM for more efficient running when lack of memory may cause jobs of temporarily inactive task running in RAM to be swapped out to disk.
- Interrupts: A signal from software, hardware, or a clock to the CPU.
Control is passed to an interrupt handling program.
Priorities used and lower-priority interrupts may be disabled while a higher priority internet is being serviced.
- Interrupt service routines : Interrupts are assigned priorities, and lower priority interrupts may be disabled while a higher priority interrupt is being serviced.
- Processor Scheduling: Allocating processor time to competing applications.
Objectives of the scheduler are to:
maximise throughput, be fair to all users on a multi-user system (provide acceptable response time to all users), ensure hardware resources are kept as busy as possible.
Several possible algorithms: Round Robin, First Come First Served, Shortest Remaining Time, Shortest Job First, Multi-Level Feedback Queues - Backing store management: The operating system is required to keep a directory of where files are stored so that they can be quickly accessed.
- Peripheral management: The data to be printed will then be transferred to an area of memory called a buffer, so that the CPU can continue with another task.
Chapter 8: Types of Operating System
- Distributed Operating Systems: Spreads the load over multiple computer servers. e.g. Intranets.
- Multi-tasking Systems: Run multiple jobs simultaneously.
- Multi-user, Multi-tasking Systems: Time-sharing systems for mainframes and supercomputers.
- Mobile Phone Operating Systems: Combine features of PC OS with cellular and wireless connectivity management.
- Embedded Operating Systems: Found in devices, with minimal UI and input/output management.
Must respond quickly to inputs, deal with many inputs simultaneously and have failsafe mechanisms + redundancy built in. - BIOS (Basic Input Output System): Program stored in EPROM that starts the computer; initialises and tests hardware, and loads the operating system.
- Device Drivers: Programs providing a software interface to hardware devices.
- Virtual Machine Instance: Software takes on the function of a machine, including executing intermediate code or running an operating system, to emulate different hardware.
Chapter 9: The Nature of Applications
- Categories of software: Systems software and applications software.
- Systems software: System software is the software needed to run the computer's hardware and application programs. This includes libraries, operating systems, translators and library programs.
- Application software: Software grouped into different categories such as general-purpose, special-purpose or custom-written (bespoke).
- Utility Programs: Optimise computer performance (disk defragmentation, backup, updating, virus checking, compression).
- Open Source: Software licensed for use without charge; source code is distributed.
- Closed Source (Proprietary): Sold with license restrictions; source code is not accessible.
- Selecting an Application: Factors include functionality, hardware compatibility, cost and reputation.
Chapter 10: Programming Language Translators
- Assembler: Translates assembly code into machine code or bytecode. Assembly code is a low-level language.
- Compiler: Translates high-level languages (Visual Basic, Python) into machine code. Different hardware platforms will require different compilers, since the resulting object code will be hardware-specific.
- Interpreter: Translates high-level language line by line, executing each instruction immediately.
- Bytecode: Many languages use an intermediate representation, which combines compiling and interpreting. Resulting bytecode is executed by a bytecode interpreter.
- Advantages and uses of compilers and interpreters
*A compiler has many advantages over an interpreter: the object code can be saved on disk and run whenever required without the need to recompile, object code executes faster than interpreted code, object code produced by a compiler can be distributed or executed without having to have the compiler present, and the object code is more secure. - Stages of Compilation: Lexical Analysis, Syntax Analysis, Code Generation/Optimisation.
* Lexical analysis: Removing superfluous spaces and comments, some simple error-checking.
* Syntax Analysis: Expressing the language as a set of rules and parsing of each statement to determine whether it is valid.
* Code Generation and Optimisation: The machine code is generated based on the semantics of the program, including techniques for reducing the execution time of the object program - Linkers and Loaders: Linking compiled subroutines and loading object code into memory.
- Use of Libraries: Ready-compiled programs (e.g. for input, output, random number generation) that can be loaded and run when needed.
Section 3: Software Development
- Overview of systems analysis methods, algorithm design, programming paradigms, and assembly language.
Chapter 11: Systems Analysis Methods
- Software Development Aspects: Analysis, Design, Implementation, Testing, Installation, Evaluation.
- Testing Strategies: Black box testing, White box testing, Alpha testing, Beta testing.
- Black box testing: Independent of the code used in program. Looks at program specification and creating a set of test data that covers all the inputs and outputs and program function..
- White box testing: Uses code logic, the program code is studied, and tests are devised and tests each possible path at least once.
- Alpha testing : software developer's in-house testing team.
- Beta testing: Used by new software companies making a software package, given to potential users, reports problems to the developers until confident enough to ship product put on the market
- Waterfall Lifecycle Model: Each step is completed one at a time from beginning to end.
- Spiral model: The Spiral Model uses the same structured steps but introduces the idea of developing the software in iterative (repeating) stages
- Agile Modeling: Stages of software development may not be completed in a linear sequence. Feedback will be obtained from the user, and this is an iterative process during which changes made are incremental as the next part of the system is built.
- Extreme Programming: It is a type of agile software development in which frequent