Computer Organization IB Computer Science Topic 2 Outline the four phases of the machine instruction cycle. [8 marks] Draw a block diagram showing the basic components of the CPU and how they interact with memory. [8 marks] Machine Instruction Cycle Overview Fetch next instruction read from memory and loaded into CIR, program counter incremented. Decode Store Instruction decoder translates instruction for ALU. Results of calculations written to memory. Execute Instruction is executed, ALU performs required actions. Components of the CPU You need to be able to reproduce this diagram and discuss everything in it Control Unit Address Bus Registers Arithmetic Logic Unit MAR MDR Memory [01] [02] [..] [FF] Data Bus The Fetch Phase The PC (Program Counter) stores the address of the next instruction in memory. The contents of the PC are copied to the MAR and the PC is incremented. The address is put onto the address bus. The data at that address (i.e., the next machine code instruction) is read into the MDR. The data returns on the data bus. The Decode Phase The instruction carried by the MDR is copied to the IR (Instruction Register) The instruction is translated into a format that the ALU can understand. The Execute Phase The ALU carries out the operation, e.g. ADD, MUL, CMP, JMP, STO, etc. The Store Phase (optional) This is almost exactly the same as the Fetch phase, except that the control bus carries a "write" signal instead of a "read" signal. Therefore, instead of reading the data stored at the MAR address into the MDR, the data stored in the MDR is written to the location at the MAR address. Registers Registers are the smallest and fastest unit of memory in a computer system, and are used to store information that the CPU is working on at that exact moment. Registers you need to know about: Program Counter: Stores the address of the next instruction Memory Address Register: Stores the address (i.e., the memory address) that is to be read or written. Memory Data Register: Stores the data that has been read (from memory) or is to be written (to memory). Instruction Register (aka Current Instruction Register): Stores the current (machine code) instruction being processed. Accumulator: A set of general purpose registers used for storing temporary intermediate results of the CPU's calculations. Assembly Language mov ax, [1000h] (from http://simple.wikipedia.org/wiki/Assembly_language) // read (load) a 2-byte object from address 4096 // (0x1000 in hexadecimal) into a 16-bit register // called 'ax': mov bx, ax // move (copy) the value in register ax into register bx sub bx, 100 // subtract 100 from bx, store the result back into bx jge continue // if the result of the previous calculation is // greater than or equal to zero, then // jump to label ‘continue ’ mov ax, 100 // put the value 100 into register ax continue: mul ax, ax // multiply the value in ax times the value in ax, // and store the result back in ax Questions Draw a block diagram showing the basic components of the CPU and how they interact with memory. [8 marks] Explain why the address bus is unidirectional and the data bus is bidirectional. [4 marks] Outline the four phases of the machine instruction cycle. [8 marks] Compare the roles of the Memory Address Register and the Memory Data Register. [4 marks] Operating Systems Operating System: Software (a collection of programs) that controls the execution of programs. May provide services such as resource allocation, scheduling, input/output control, and data management. How many operating systems can you name? Main functions of an operating system: Input/Output (IO) control File management Software/hardware interface Memory management User interface Scheduling Program execution control Security Operating Systems and Security User management: login with password System of privileges, determining which user or process can do what (e.g., delete files, shut down the system, etc.). Permissions for files and directories (e.g., read-only, etc.) Memory management: keeping one process’s (or one user's) memory space separate from another’s Built-in firewall (a program, or set of programs, that protects the resources of a private network from users of other networks.) Types of Memory Primary Memory Registers: Smallest, fastest memory, used to hold data that the CPU is currently working on. Cache: Small, fast memory, used to hold very frequently used data. RAM: Random Access Memory. Holds data and instructions from running programs. ROM: Non-volatile memory, used to hold the operating system's bootstrap loader (small start-up program) or BIOS (Basic Input/Output System). Secondary Memory Disk storage Magnetic tape USB flash drives Operating Systems and Memory Management Multi-tasking environment: keeping the memory space of each process safe from other running processes (see Security) Multi-user environment: keeping the memory space (primary and secondary) of each user safe from other users (see Security) Operating systems allocate and deallocate memory for each process Paging: Dividing virtual memory up into equalsized blocks (pages) Paging allows OSs to allocate non-contiguous chunks of memory to the same process, thus reducing fragmentation problems Virtual memory: The use of secondary memory as if it were primary memory. By creating virtual memory, the OS makes it easier for programs to reference memory because they don’t need to worry about the complications of the underlying physical structure of memory and disk (another example of abstraction) Applications (memorize this slide) An application is a computer program that allows a user to perform some useful activity. Examples are: Word processor: Text document management Spreadsheet: Mathematical and financial calculations Database: Organisation of information Email: Electronic mail Web browser: Viewing HTML pages Graphics processing: Editing, cropping and enhancing images Computer-Aided Design (CAD): Creating and editing designs for engineering or manufacturing Note that you are not allowed to use proprietary names in your exam. So you say "spreadsheet software" and not "MS Excel", etc. Common Features of Applications The IB Guide refers to features: "Including toolbars, menus, dialogue boxes, graphical user interface GUI) components. Students should understand that some features are provided by the application software and some by the operating system." Operating systems make services available to applications: I/O (input/output) operations File system manipulation (reading/writing files) Frameworks of GUI components Program execution Hardware interface Error detection All applications need these services, so it makes sense to centralise their provision. They make the development of software simpler because potentially complex interaction with hardware is avoided. Questions Outline the main functions of an operating system. [4 marks] Explain the advantages of virtual memory. [4 marks] In what ways can an operating system improve information security in a computer? [4 marks] Binary Representation Definitions Bit: The smallest amount of data that can be represented. Short for "binary digit". Represented as either a 0 or 1. Byte: 8 bits Denary/Decimal: The base 10 counting system. The normal placevalue counting system in which a new column is created when a power of 10 is reached. Hexadecimal: The base 16 counting system. Requires six new symbols in addition to 0-9, which are A-F. Since 24 = 16, one Hex digit can be used to represent 4 bits, and two Hex digits can be used to represent a byte. Data Representation The Guide mentions: Strings, integers, characters, colours. The most basic point is that more bits allows more different values to be stored. 0 1 00 01 10 11 000 001 010 011 100 101 110 111 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001 11010 11011 11100 11101 11110 11111 No bits No diff values 1 2 = 21 2 4 = 22 3 8 = 23 4 16 = 24 5 32 = 25 n = 2n More bits means: • More different values • Data is larger Raster images Also called bitmaps, raster images use a grid of points of colour But how many different colours can one point be? Colour depth is the number of bits per pixel (generally "bit depth") (The number of pixels makes a difference too.) Obvious tradeoff between picture quality vs file size Questions An image file is made up of a grid of 200 x 300 pixels and has a colour depth of 8 bits. How many different colours can each pixel represent? [2 marks] What is the size of the file? [2 marks] A friend argues that if you increase the colour depth of this file, you will improve its quality. To what extent is he correct? [4 marks] RGB (see http://www.rapidtables.com/web/color/RGB_Color.htm ) What does RGB stand for? How many colours can RGB represent? What are the RGB values for: white? black? What colour is: 888888? 00FFFF? Why is ASCII vs Unicode relevant to this topic? Explain one advantage and one disadvantage of Unicode over ASCII. (see http://stackoverflow.com/questions/2241348/what-is-unicode-utf-8-utf-16 ) Logic Gates The Guide mentions AND, OR, NOT, NAND, NOR, XOR Which of these are binary operators and which are unary operators? Construct truth tables for each. Look at the logic diagram below. Construct a truth table for X given the inputs A, B and C. A AND B NOT XOR C X Redraw each of these diagrams using fewer gates A NOT AND B X NOT NOT A AND OR B AND NOT X