Docsity

A-Level Computer Science Notes, Study Guides, Projects, Research of Computer science

Partial preview of the text

Download A-Level Computer Science Notes and more Study Guides, Projects, Research Computer science in PDF only on Docsity!

Created by Turbolearn Al Computer Science OCR AS and A Level PG ONLINE Study Guide Components of a Computer This section covers the fundamental components of a computer system: Processor components Processor performance Types of processor Input devices Output devices Storage devices Chapter 1 - Processor Components . Objectives: * Describe the function of the ALU and Control Unit * Describe the Fetch-Execute cycle and the role of the following registers: © Program Counter Accumulator Memory Address Register Memory Data Register 0 000 Current Instruction Register Buses « A busisa set of parallel wires connecting two or more components of a computer. * Typically consists of 8, 16, 32, or 64 lines. « Each bus is a shared transmission medium, so only one device can transmit along a bus at any one time. Direction of Transmission Along the Buses * Data and control signals travel in both directions between the processor, memory, and I/O controllers. « Addresses travel only one way along the address bus. Types of Buses: Page 1 Created by Turbolearn Al « Data Bus: © Typically consists of 8, 16, 32, or 64 separate lines. © Provides a bi-directional path for moving data and instructions between system components. « Address Bus: © Transmits the memory addresses of words that are used as operands in program instructions. o Used so that data can be retrieved and sent back to the processor. * Control Bus: © Transmits command, timing, and specific status information between system components. o Ensures that access to and use of the data and address buses by the different components of the system does not lead to conflict. © Bi-directional. Control Lines Include: « Bus Request: Indicates that a device is requesting the use of the data bus. « Bus Grant: Indicates that the CPU has granted access to the data bus. * Memory Write: Causes data on the data bus to be written into the addressed location. « Memory Read: Causes data from the addressed location to be placed on the data bus. « Interrupt Request: Indicates that a device is requesting access to the CPU. « Clock: Used to synchronize operations. Arithmetic-Logic Unit (ALU) « Performs arithmetic and logical operations on the data. « Can perform instructions such as ADD, SUBTRACT, MULTIPLY, DIVIDE on fixed or floating-point numbers. * Can also perform shift operations, shifting bits to the left or right within a register. « Can carry out Boolean logic operations, comparing two values and using operators such as AND, OR, NOT, XOR. Registers « Special memory cells that operate at very high speed. « Allarithmetic, logical, or shift operations take place in registers. « There are typically up to 16 general-purpose registers in the CPU. Special-Purpose Registers: Page 2 Created by Turbolearn Al 1. Clock Speed: The system clock generates a series of signals, switching between 0 and 1 several million times per second and synchronizing CPU operations. Each CPU operation starts as the clock changes from 0 to 1 (or in some systems from 1 to 0), and the CPU cannot perform operations faster than the clock cycle (the time the clock takes to go from 0 to 1 and back to 0). One clock cycle per second = 1 Hertz (Hz), and clock speed is measured in Gigahertz (GHz), about 1 billion cycles per second. Typical speeds for a PC are between 2 and 4 GHz. © The greater the clock speed, the faster instructions will be executed. 2. Number of Cores: A dual-core processor has two processors linked together in the same integrated circuit, and a quad-core computer has four linked processors. © Each core is theoretically able to process a different instruction at the same time with its own fetch- execute cycle, making the processor two or even four times faster with a quad-core chip. © However, although a dual-core processor has twice the power, it does not always perform twice as fast because the software may not always be able to take full advantage of both processors. 3. Amount and Type of Cache Memory: Cache is a small amount of expensive, very fast memory inside the CPU. o When an instruction is fetched from main memory it is copied into the cache, so if it is needed again soon after, it can be fetched from cache, which is much quicker than going back to main memory. e As cache fills up, unused instructions or data still being held are replaced with more recent ones. © There are different "levels" of cache: = Level 1 cache is extremely fast but small (between 2-64KB). = Level 2 cache is fairly fast and medium-sized (256KB-2MB). = Some CPUs also have Level 3 cache. ° ° ° Pipelining Pipelining is a technique used by some processors to improve performance. Processor pipelining is sometimes divided into an instruction pipeline and an arithmetic pipeline. © The instruction pipeline consists of the stages in which an instruction is moved through the processor, including its being fetched, buffered, and then executed. © The arithmetic pipeline represents the parts of an arithmetic operation that can be broken down and overlapped as they are performed. Using pipelining, the computer architecture allows the next instructions to be fetched at the same time as the processor is performing arithmetic or logic operations, holding them in a buffer close to the processor until their instruction can be performed. Without pipelining, the steps in the Fetch-Execute cycle take place one after the other. While the next instruction is being fetched, the ALU, the arithmetic part of the processor, is idle. Pipelining is now common in microprocessors used in personal computers. Intel's Pentium chip uses pipelining to execute as many as six instructions simultaneously. . Words and Word Size Page 4 . . . Created by Turbolearn Al Each word, or group of bytes, in memory has its own specific address. When the processor wishes to read a word of data from memory, it first puts the address of the desired word on the address bus. The width of the address bus determines the maximum possible memory capacity of the system. © For example, if the address bus consisted of only 8 lines, then the maximum address it could transmit would be (in binary) 11111111 or 255, giving a maximum memory capacity of 256 (including address 0). © Asystem with a 32-bit address bus can address 2°? = 4, 294, 967, 296 memory locations, giving an addressable memory space of 4GiB. (This is the memory capacity of an average PC in 2016.) The data bus transmits the data held in a word of memory, between processor components and memory. The largest operand (which is either an address or an actual value) that can be held in a word is therefore related to the size of the data bus. How This Relates to Assembly Language . . If the data bus is 16 bits wide, a word cannot hold an integer greater than 2!° — 1, or more than two characters. A wider data bus can transmit larger values, or more characters at a time, or allow more bits per instruction. In assembly language, the operation code (opcode) will be expressed as a mnemonic such as ADD, SUB, LDA (load into the accumulator), etc. With only six bits for the opcode, there cannot be more than 2° different instructions. The operand has to be held in only 8 bits. This would clearly not be practical in a general-purpose computer which is more likely to have a word size of 32, 64, or 128 bits. The basic structure of a machine code instruction in a computer with a 16-bit word may take the format shown below: Operation code Operand(s) Basic machine operation Addressing mode 010001 010000011 Chapter 3 - Types of Processor Objectives: . Describe von Neumann, Harvard, and contemporary processor architecture. Describe the differences between, and uses of, C/SC and RISC processors. Describe GPUs and their uses. Describe multi-core and parallel systems. Memory and the Stored Program Concept The stored program concept can be defined as follows: machine code instructions are fetched and executed serially by a processor that performs arithmetic and logical operations. The von Neumann Machine Page 5 Created by Turbolearn Al Embedded systems include special-purpose computers built into devices often operating in real time, such as those used in: « Navigation systems * Traffic lights « Aircraft light control systems * Simulators Harvard Architecture The Harvard architecture has two different memories that can have different characteristics. For example, in embedded systems: Instructions may be held in read-only memory « Data memory requires read-write memory Complex Instruction Set Computers (CISC) A Complex Instruction Set Computer (C!SC) architecture uses a large instruction set to accomplish tasks in as few lines of assembly language as possible. The processor hardware is capable of understanding and executing the series of sub-tasks that make up a single instruction. The CISC architecture combines a "load/store" instruction with the instruction that carries out the actual calculation. For example, to multiply two values held in different memory locations A and B, storing the result in A. Reduced Instruction Set Computers (RISC) A Reduced Instruction Set Computer (RISC) architecture uses only simple instructions, each taking one clock cycle. The multiplication instruction described above might be written in several steps, using several general- purpose registers. Comparison of CISC and RISC cisc RISC Instruction Set Large Small Instruction Complexity Complex Simple Clock Cycles per Instruction Variable One Compiler Work Less More RAM Requirements Less More Co-processor Systems A co-processor is an extra processor used to supplement the functions of the primary processor (the CPU). It may be used to perform: * Floating point arithmetic « Graphics processing « Digital signal processing « Other functions Page 7 Created by Turbolearn Al Graphics Processing Unit (GPU) A Graphics Processing Unit (GPU) is a specialized electronic circuit which is very efficient at manipulating computer graphics and image-processing. A GPU has a massively parallel architecture consisting of thousands of smaller, more efficient cores designed for handling multiple tasks simultaneously. Multi-core and Parallel Systems Multi-core processors are able to distribute workload across multiple CPU cores, thus achieving significantly higher performance. * The IBM Blue Gene supercomputer has 4,098 processors, allowing 560 Teraflops of processing. « Supercomputers are used on problems such as weather forecasting, running climate change models, processing Big Data, or sequencing DNA. Input Devices input devices take data from the user and convert it into a form that the computer can understand. Examples of input devices include: « Keyboard * Mouse « Scanner * Barcode reader Barcode Readers A barcode reader is an input device that reads barcodes and converts them into a digital format. There are two different types of barcode: Linear barcodes and 2D barcodes. Types of Barcode Readers Type Description Pen-type readers Use a light source and a photo diode to read barcodes Laser scanners Use a laser beam to read barcodes CCD readers Use a charge-coupled device to read barcodes Camera-based readers Use a camera to read barcodes Output Devices Output devices take data from the computer and convert it into a form that the user can understand. Examples of output devices include: * Monitor ¢ Printer * Speaker * Actuator Organic LED (OLED) Screens Page 8 Created by Turbolearn Al Solid-state disks are packaged to look like hard disk drives, typically 2.5 and 3.5 inches. SSDs consume less power than traditional hard drives, extending battery life and staying cooler. SSDs are less susceptible to damage, silent, lighter, and highly portable. Solid state memory comprises millions of NAND flash memory cells and a controller. NAND flash memory cannot overwrite existing data. Data is stored in pages (typically 4 KiB), grouped into blocks of say 512 KiB. Separate block mirrors data to be transferred. Original block contents marked as "invalid" or "stale" and erased when new data is written. Each cell works by delivering a current along the bit and word Lines to activate the flow of electrons from the source towards the drain. The current on the word line forces electrons across an insulated oxide layer into a floating gate, where they are trapped. The state of the NAND cell is determined by measuring the charge in the floating gate. © No charge (no electrons) is considered a 1. © Some charge is considered a 0. « Solid state media have faster access speeds than hard disks. Virtual Storage Computers have two kinds of internal memory: random access memory (RAM) and read-only memory (ROM). RON is used to hold information that needs to be permanently in memory. The bootstrap loader, for example, has to be held in ROM. In embedded systems, software never changes and is held in ROM. Hard disk is used as an extension of memory = called virtual memory. RAN 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. What is an Operating System? An operating system is a program or set of programs that manages the operations of the computer for the user. It acts as a bridge between the user and the computer's hardware. The operating system is held in permanent storage, for example on a hard disk. Asmall program called the loader is held in ROM. When a computer is switched on, the loader in ROM sends instructions to load the operating system by copying it from storage into RAM. Regardless of whether the operating system is embedded within an MP3 player or is the latest version of Windows installed on a desktop computer, all operating systems share the same basic functions. Functions of an operating system: Providing a user interface Memory management Interrupt service routines Processor scheduling Backing store management Management of all input and output Multitasking machine 0 000000 Memory Management - Paging, Segmentation, and Virtual Memory Page 10 Created by Turbolearn Al The allocation and management of space is controlled by the operating system. Using a paging system, memory is divided into fixed size pages of 4KB each, and a process currently in memory may be held in several non-contiguous pages. A page table uses mapping to store a link between the physical memory address and the logical address space of each process. As more and more jobs are loaded into memory, the operating system may swap pages of temporarily inactive jobs out to disk, thus using secondary storage as an extension of memory. . . Segmentation is the logical division of address space into varying length segments which depend on the program structure. As with paging, it is possible to load only a part of a program into memory initially. Processor Scheduling « With computers able to run multiple applications simultaneously, the operating system is responsible for allocating processor time to each one as they compete for the CPU. * While one application is busy using the CPU for processing, the OS can queue up the next process required by another application to make the most efficient use of the processor. * Acomputer with a single processor can only process one instruction at a time, but by carrying out small parts of multiple larger tasks in turn, the processor can give the appearance of carrying out several tasks simultaneously. This is what is meant by multi-tasking. Interrupts . When the CPU receives an interrupt signal, it suspends execution of the running program or process and disables all interrupts of a lower priority. It then puts the values of the program counter (PC) and of each register onto the system stack, while an interrupt Service Routine is called to deal with the interrupt. Depending on the type of interrupt, a particular routine will be run in order to service it. An interrupt is a signal from a software program, hardware device, or internal clock to the CPU. A software interrupt occurs when an application program terminates or requests certain services from the operating system. * A hardware interrupt may occur, for example, when an I/O operation is complete or an error such as 'Printer out of paper' occurs. Interrupts are also triggered regularly by a timer, to indicate that it is the turn of the next process to have processor time. « Because a processor can be interrupted, multi-tasking can take place. « The scheduler is the operating system module responsible for making sure that processor time is used as efficiently as possible. Interrupt Service Routines . « Interrupts are assigned priorities, and lower priority interrupts may be disabled while a higher priority interrupt is being serviced. « A test for the presence of interrupts is carried out at the end of each fetch-decode-execute cycle. Scheduling Algorithms Objectives of the scheduler: Page 11 Created by Turbolearn Al Multi-Tasking System A multi-tasking operating system may run on a standalone computer, such as a PC or laptop. Distributed Operating Systems A distributed operating system is a form of parallel processing system which spreads the load over multiple computer servers. « Examples: Linux, Unix, and Windows. Multi-User, Multi-Tasking System A single powerful mainframe or supercomputer is connected to dozens or hundreds of terminals all using the mainframe CPU. Each user gets a slice of processor time according to a scheduling algorithm. Operating Systems Used by Mobile Phones * Mobile operating systems combine the features of a personal computer operating system with features useful for mobile use such as managing cellular and wireless connectivity as well as phone access. * Smartphones have two operating systems: © The main system operating the user interface and running the application software © Asecond, low-level proprietary real-time operating system which operates the radio and other hardware Real-Time Operating System Found in the flight-control system of a "fly-by-wire" airliner. It must respond very quickly to any inputs or sensors. It must be able to deal with many inputs simultaneously. It must have "failsafe" mechanisms designed to detect and take appropriate action if a hardware component fails. It must incorporate redundancy: if one component fails, it must automatically switch to backup hardware. . . Embedded Operating Systems « Found in all kinds of hardware from a washing machine or microwave oven, to the control system of a passenger aircraft or a space shuttle. « Main features of the operating system: © It will have a minimal user interface, probably consisting of a few buttons or a dial and maybe a small screen. © It will accept input from sensors, and send output to control devices. © There is a limited amount of RAM so a complex memory management system is not required. © There will not be any permanent data storage devices to be managed. BIOS (Basic Input Output System) BIOS is the program stored in EPROM (Erasable Programmable Read-Only Memory) that gets your computer started after you turn it on. Page 13 Created by Turbolearn Al * The fundamental purpose of BIOS in modern PCs is to initialize and test the system hardware components and to load the operating system (or the key parts of it) from the hard disk into RAM. + In more modern computers, BIOS is not used after loading the operating system. Device Drivers A device driver is a computer program that provides a software interface to a particular hardware device. « Enables operating systems to access hardware functions without needing to know the details of the hardware being used. « Drivers are hardware dependent and operating system specific. * Adriver typically communicates with the device via the system bus or communications subsystem to which the hardware connects. Virtual Machine A virtual machine can be defined as any instance where software is used to take on the function of the machine, including executing intermediate code or running an operating system within another to emulate different hardware. The Nature of Applications System software is the software needed to run the computer's hardware and application programs. This includes the operating system, utility programs, libraries, and programming language translators. Classification of Software « Software can be broadly classified into: o Systems software © Applications software Categories of Software Category Description A set of programs that lies between applications software and the computer hardware, and has many different functions. Designed to help analyze, configure, optimize or maintain a computer. They are used to support the infrastructure — in contrast to application software, which is aimed at directly performing tasks| that benefit ordinary users. Ready-made programs that can be bought from software vendors. They are general-purpose and can be used by a wide range of users. Software tailored for the specific needs of an organization. Software which is free to use and can be modified and distributed by anyone. Software which is owned by a specific company or individual. It is typically sold under a license and cannot be freely copied or distributed. Functions of an Operating System Page 14 Created by Turbolearn Al Special-Purpose Software Special-purpose software performs a single specific task or set of tasks. Examples include: « Payroll and accounts packages * Hotel booking systems « Fingerprint scanning systems + Browser software Software may be bought "off-the-shelf," ready to use, or it may be specially written by a team of programmers for a particular organization. "Off-the-Shelf" vs. Bespoke Software Off-the-Shelf Bespoke Software Less expensive (cost is shared among all More costly (requires expertise to analyze and buyers) document requirements) May contain unwanted features; some desirable Features customized to user requirements; other features may be missing features can be added as needs arise Ready to be installed immediately May take a long time to develop Well documented, well-tested, and error-free May contain errors that do not surface immediately Compression Software Zipped or compressed files can be transmitted much more quickly over the Internet. Sometimes there is a limit to the size of a file that can be transmitted. For example, a user may not be able to email a 15Mb photograph if there is a 5Mb limit on attachments. Even if the file can be received, it may take several minutes to download without a broadband connection. General-Purpose Software General-purpose software, such as a word processor, spreadsheet, or graphics package, can be used for many different purposes. For example, a graphics package may be used to produce advertisements or animations, manipulate photographs, or draw vector or bitmapped images. Several utility programs are supplied as part of the operating system. These include utilities to copy, move, and delete files, create, move, and delete folders, and provide screensavers. Other utility programs, such as WinZip for compressing and sharing files, have to be purchased from independent suppliers. Applications software can be categorized as general-purpose, special-purpose, or custom-written (bespoke) software. Open Source vs. Closed Source Page 16 Created by Turbolearn Al Open Source Closed Source (Proprietary) Tends to be more organic - changes over time as developers Sold in the form of a license to use modify source code and distribute new versions. it. No commercial organization behind the software, so there Regular updates available, probably won't be a helpline or regular updates, just a community technical support lines, training of enthusiastic developers. courses, and a large user base. Must be distributed with the source code so anyone can modify it. Developers can sell the software they have created. Any new software created from Open Source software must also be "open," meaning that it must be distributed or sold in a form that other people can read and also edit. The users will not have access to , the source code and will not be allowed to modify the package and sell it to other people. Note: Open Source is different from Freeware (free software) which may be free to use, but the user does not get access to the source code. Freeware usually has restrictions on its use as well. Selecting an Application Criteria for selecting suitable software for a particular purpose: + Does it provide all the necessary functionality? * Does it run on the available hardware? « Is it available "off the shelf," or will it have to be specially written? * How much will it cost? « Is it well-used, tried, and tested? Software Categories Software Use Category Firewall software installed on the web server Utility software Store's own online ordering system designed for their products and systems Bespoke software Graphics software to crop product images suitable for uploading to the site General-purpose application software Online payment verification software Special-purpose software Programming Language Translators Compiler A compiler is a program that translates a high-level language such as Visual Basic, Python, etc. into machine code. The code written by the programmer, the source code, is input as data to the compiler, which scans through it several times, each time performing different checks and building up tables of information needed to produce the final object code. Different hardware platforms will require different compilers, since the resulting object code will be hardware- specific. For example, Windows and the Intel microprocessors comprise one platform, Apple and PowerPC processors another, so separate compilers are required for each. Assembler Page 17 Created by Turbolearn Al A big advantage of bytecode is that you can achieve platform independence. Any computer that can run Java programs has a Java Virtual Machine JVM), a piece of software which masks inherent differences between different computer architectures and operating systems. The JVM understands bytecode and converts it into the machine code for that particular computer. The program may run slower than a compiled program, because each statement has to be translated to machine code each time it is encountered. So if a loop of 10 statements is performed 20 times, all 10 statements are interpreted 20 times. A second advantage of using, for example, Java bytecode is that it acts as an extra security layer between your computer and the program. You can download an untrusted program, and you then execute the Java bytecode interpreter rather than the program itself, which guards against any malicious programs. Most interpreted languages such as Python and Java use an intermediate representation which combines compiling and interpreting. The resulting bytecode is then executed by a bytecode interpreter. It is also possible to compile from Python into Java bytecode (using the Jython compiler) and then use the Java interpreter to interpret and execute it. The bytecode may be compiled once and for all (as in Java) or each time a change in the source code is detected before execution (as in Python). A compiler would therefore be appropriate when a program is to be run regularly or frequently, with only occasional change. It is also appropriate when the object code produced by the compiler is going to be distributed or sold to users outside the company that produced the software, since the source code is not present and therefore cannot be copied or amended. Advantages and Uses of Compilers and Interpreters Feature Compiler Interpreter * Object code can be saved on disk andrun _* Useful for program development as there is whenever required without the need to no need for lengthy recompilation each time an recompile. error is discovered. * The source code can be run on any machine that has the appropriate interpreter available (e.g., Java's bytecode). * 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. * Object code is more secure, as it cannot be read without a great deal of reverse engineering. * If an error is discovered in the program, the whole program has to be recompiled. * the source code can be run on any machine interpreter available e.g. Java's byte code) Stages of Compilation Many languages are only compiled or only interpreted or have various possibilities in between. The symbol table plays a central role in the compilation process. It will contain an entry for every keyword (reserved word) and identifier in the program. The exact format of the entries in the table will vary from compiler to compiler, but typically, entries in the table will show: Page 19 Created by Turbolearn Al Identifiers (e.g., variable names) used in the source code are replaced by 'tokens' (unique symbols). « Numbers will be converted to their run-time representation. Identifiers will be replaced by a pointer to an address in the symbol table. « Keywords such as input and print will be replaced by a single item code. * A pointer to accessing information (e.g., for an array, the bounds of the array, or for a procedure, information about each of the parameters). There are three stages of compilation: lexical analysis, syntax analysis, and code generation and optimization. Lexical Analysis Lexical analysis performs the following functions: 1. Superfluous spaces are removed. 2. All comments, identified, for example, by # or /, will be removed from the program. 3. Some simple error-checking is performed. For example: eo An attempt to assign an illegal value to a constant, such as a value of the wrong type or one that causes overflow or underflow. © Anidentifier (such as X&Y or tent in Python) would be flagged as an error. 4. All keywords, constants, and identifiers are 'tokenized’. (The lexical analyzer will not detect misspelled keywords or undeclared variables; this is the job of the syntax analyzer.) Symbol Table Typical entries in a symbol table: Item Name Kind of Item Type of Item Run-Time Address or Value Pointer input keyword pi constant real 3.14159 radius variable real (a) area variable real numSides array integer fy 2 3 4 * operator 5 6 7 operator Syntax Analysis and Semantic Analysis Syntax analysis is the process of determining whether the sequence of input characters, symbols, items, or tokens forms a valid sentence in the language. In order to do this, the language has to be expressed as a set of rules, using, for example, syntax diagrams or Backus-Naur form. Note that the lexical analyzer puts the identifier and its run-time address in the symbol table, so that it can replace them in the source code by "tokens". It will not fill in the 'kind of item! and 'type of item'; this is done later by the syntax analyzer. The semantics of the program will also be checked in this phase. Semantics define the meaning rather than the grammar of the language; it is possible to write a series of syntactically correct statements which nevertheless do not obey the rules for writing a correct program. Page 20