1 CAMBRIDGE IGCSE COMPUTER SCIENCE 0478 UNIT 2 U n i t 2 Numbers, processors and operating systems 2 Unit 2: Numbers, processors and operating systems This unit looks at the way in which numbers are represented within a computer system, the structure of the central processing unit and its functions, and the role of the operating system in managing the components of a computer system and interactions with the user. Contents Understand binary notation and to convert denary numbers to and from binary ...................... 3 Recognise the use of binary numbers in computer systems ...................................................... 4 Understand hexadecimal notation and to convert hexadecimal integers to and from binary and denary......................................................................................................................................... 5 Understand the significance of hexadecimal in computer systems ........................................... 7 Show understanding of the basic Von Neumann model for a computer system and the stored program concept......................................................................................................................... 7 Describe the stages of the fetch-execute cycle ........................................................................ 10 Describe the purpose of an operating system .......................................................................... 11 Show understanding of the need for interrupts ........................................................................ 12 U n i t 2 Numbers, processors and operating systems 3 Understand binary notation and to convert denary numbers to and from binary Computers are made up hardware that stores and processes data. If you break a computer down into its most basic components you have millions of circuits that either allow electricity to flow, or not. The computer uses electronic circuits to store one of two values using a switch – the switch is either on (1) or off (0). Using a number of these switches provides us with many possible combinations of 1s and 0s which we can use to represent numeric values. This is called Binary. A single 1 or 0 is called a binary digit or bit for shot. A group of eight bits is called a byte. Four bits, half a byte, is called a nibble. Denary: A system of numbers using ten digits, 0 and 1-9 (also called base-10 system) Binary: A system of numbers using only 2 digits, 0 and 1 (also called base-2 system) x2 x2 x2 128 64 2x2x2x2x2x2x2 2x2x2x2x2x2 27 26 32 2x2x2x2x2 25 x2 16 2x2x2x2 24 8 2x2x2 23 x2 x2 x2 4 2x2 22 2 2 21 1 1 10 To convert Binary to Denary To convert the binary 111001 into a denary number use the column headings. 128 0 64 0 32 1 16 1 8 1 4 0 2 0 1 1 The number is 32+16+8+1 = 57 (add up the column headings where there is a 1) To convert Denary to Binary Use the same column headings. You need to find the biggest column heading that you can take away from the number and start there: Let’s convert 57 into binary: The biggest column heading we can take out of 57 is 32 (the next one is 64, which is too big) Write a 1 under the column heading 32. That leaves us with 57-32 = 25. Write a 1 under the column heading 16 (because we can take 16 out of 25. 25-16 leaves 9) You should be able to see now that 9 is an 8 and a 1 so we end up with: 128 0 64 0 32 1 16 1 8 1 4 0 2 0 Always double check by adding the columns up at the end. They should give you the number you started with 32+16+8+1=57 U n i t 2 Numbers, processors and operating systems 1 1 4 Recognise the use of binary numbers in computer systems In base 10 we have some important numbers we give names to: for example 10x10x10 is 1000 which we call a thousand; and 1 thousand multiplied by 1 thousand which we call 1 million; and so on. In base 10 we are also used to the metric system which uses kilo to mean a thousand, for example kilometre or kilogram. In binary we also have names to describe key values. The basic unit is 0 or 1 – this is a binary digit or a bit. A group of 8 bits is called a byte and half a byte (4 bits) is called a nibble. We also use the kilo prefix to represent the same sort of scale as we do in base 10. But 1000 is not correct in binary which is 210 or 2x2x2x2x2x2x2x2x2x2 = 1024. Using this approximation to 1000 we can now define a whole set of names commonly used to describe binary numbers 8 bits 1024 bytes 1024 kilobyte 1024 megabytes 1024 gigabytes 1 byte 1 kilobyte 1 megabyte 1 gigabyte 1 terabyte Registers Computer systems only operate in binary (1s and 0s). Within the processor unit there are areas known as registers which have a number of uses. Consider the following example in Robotics. A car manufacturing company uses robotics to spray their new cars with paint. A special edition model is being made which is only available in 4 colours and 2 paint finishes (metallic and nonmetallic). An 8-bit register is used to determine whether it is alright to paint the car and to choose the correct paint colour and finish. Is a car present? Is a car in position ? Is spray gun fill level OK? Metallic finish? Black Paint? Red Paint? White Paint? Blue Paint? Note that all the above conditions give a 1 value; otherwise a 0 value. Thus, if an 8-bit register contains: 1 1 1 1 0 1 0 0 This means a car is present, car is in position, spray gun fill level is OK, and metallic red paint finish is chosen. U n i t 2 Numbers, processors and operating systems 5 Registers are also used in most digital instruments to represent the numbers. Consider the following example in a digital display of a car. A car has a speedometer with a digital read out. Each digit can be represented by a 4-bit register. 1 2 9 1st Digit 2nd Digit 3rd Digit Can be represented as: 8 0 0 1 4 0 0 0 2 0 1 0 1 1 0 1 1st Digit 2nd Digit 3rd Digit Understand hexadecimal notation and to convert hexadecimal integers to and from binary and denary Humans are not very good at remembering long strings of numbers so, to make it easier for us, we can represent every group of 4 bits with a single digit. The smallest value you can have with 4 bits is 0000 = 0. The largest value is 1111= 15. In base 10 we have 10 symbols 0 to 9, if we use the 16 symbols for 0 to 15 we can use a system based on place values of 16 rather than 2 or 10. We call this hexadecimal (or hex for short). We do, however need to have symbols for the numbers 10, 11, 12, 13, 14 and 15. We use the letters A, B, C, D, E and F to represent these values. To convert Hexadecimal to Denary Converting hex to denary is the same process we have used before with column values, using the values 1 and 16. Let’s convert Hex 23 to denary: Place the first Hex digit under the column heading 16 and the second Hex digit under the column heading 1. Complete the calculations to find out the denary value. 16 1 2 3 2 X 16 = 32 3X1=3 32 + 3 = 35 in denary To convert Denary to Hexadecimal U n i t 2 Numbers, processors and operating systems 6 Converting denary to hex is the same process we have used before with column values, using the values 1 and 16 except this time we need to work out how many groups of 16 there are in the denary number. Let’s convert 182 to hex: 182/16 = 11 remainder 6 Represent this using the table and replace the denary with its corresponding Hex value. 16 1 11 6 B 6 B6 To convert a Binary number to Hex To convert from Binary to Hex you first need to represent the binary using two nibbles. For example, the binary number 00101101 can be represented in 2 nibbles as shown below. Then replace the values with the corresponding Hex digits. Split into 2 Nibbles =2D To convert a Hex to Binary To convert from Hex to Binary you need to split the Hex digits into two nibbles and then represent each digit in binary as shown below. U n i t 2 Numbers, processors and operating systems 7 Understand the significance of hexadecimal in computer systems The close relationship between binary and hexadecimal is why hexadecimal is used so extensively by programmers. The data on the computer is in binary, if the programmer needs to examine this data then pages of 1s and 0s are not much help, but the hexadecimal equivalents are much easier to work with. As with binary numbers, hexadecimal numbers are stored in registers and main memory. Hexadecimal is used in the HTML code for colours. Light blue on an HTML page has the hexadecimal value ADD8E6, and brown is A52A2A. Working with hexadecimal numbers is much easier than working with the binary equivalent 101011011101100011100110. Hexadecimal numbers are also used in MAC addresses. Media Access Control (MAC) technology provides unique identification and access control for computers on an Internet Protocol (IP) network. Media Access Control assigns a unique number to each IP network adapter called the MAC address. A MAC address is 48 bits long. The MAC address is commonly written as a sequence of 12 hexadecimal digits as follows: 48-3F-0A-91-00-BC Hexadecimal numbers are used in assembly languages. Assembly languages use a set of mnemonics to represent the possible machine operations which include instructions in Hexadecimal. Show understanding of the basic Von Neumann model for a computer system and the stored program concept In 1945, John van Neumann published a document that would provide the way forward for the development of the modern digital computer. The paper described a computer architecture in which the data and the program are both stored in the computer’s memory in the same place. This is the fundamental design concept behind all modern computer systems. All instructions and data will be stored in the same place as binary numbers. Previously data and programs were stored in separate memories. Von Neumann realised that data and programs are indistinguishable and can, therefore, use the same memory. This led to the introduction of compilers which accepted text as input and produced binary code as output. The Von Neumann architecture uses a single processor which follows a linear sequence of fetch-decode-execute In order to do this, the processor has to use some special registers. U n i t 2 Numbers, processors and operating systems 8 Registers Register Stands for PC Program Counter CIR Current Instruction Register MAR Memory Address Register MDR Memory Data Register Accumulator Holds Results Index Used by programs to adjust the address part of an instruction before the address is used Special Register Holds the address in PC to be reloaded after the completion of jump instruction Status Holds flags that indicate process status PC - Program Counter (Alternative names; Sequence Control Register ”SCR”, Instruction Address Register “IAR”, Next Instruction Register “NIR”; the name we shall use forward is PC): It contains the address of the next machine code instruction to be executed. It controls the sequence in which machine code instructions are executed. It is in the control unit. MAR (Memory Address Register): It is used to store the address of the memory location currently in use. This address contains either the address of current instruction being loaded (in the fetch phase) or the address of data to be used (In the execute phase) or the address of data to be stored in memory (In execute Cycle). It is in the processor. CIR (Current Instruction Register): It holds the instruction that is to be executed. Any machine code instruction includes a part which contains an address this part called the address part of an instruction, and another part which includes the Function. It is in the control unit. MDR (Memory Data Register) or MBR (Memory Buffer Register): It acts like a buffer and holds data or instructions being transferred to and from the memory, ready to be used by the processor or stored to the memory. The MDR is the only route between the other registers and the main memory of the computer. It is in the processor. Accumulator: Is a special storage register in the arithmetic unit where data is processed. This involves arithmetic and logical operations. U n i t 2 Numbers, processors and operating systems 9 It holds processing results before being transferred to memory data register and then to memory. Status Register: Holds flags that indicate processor status at any time. The index register: Is a special purpose register used by programs to adjust the address part of an instruction before the address is used. It provide an efficient way of accessing a range of memory locations, such as in an array. Use of Special Registers/Memory Addressing Techniques The minimum number of registers needed to execute machine code instructions not high-level language instructions. The diagram does not show the control bus and the signals needed for instructions to be correctly executed. U n i t 2 Numbers, processors and operating systems 10 Describe the stages of the fetch-execute cycle Fetch cycle; Load the address that is in the program counter (PC) into the memory address register (MAR). Load the instruction that is in the memory address given by the MAR into the memory data register (MDR). Increment the PC. Load the instruction that is now in the MDR into the Current Instruction Register (CIR). Decode the instruction that is in the CIR. Execute the instruction. If the instruction is a jump instruction then o Save the address in PC to special register to be reloaded after the completion of jump instruction. Load the address part of the instruction in CIR into the PC Reset by going to first step in fetch cycle. Copy the address part of the instruction at CIR to MAR Load the memory content of the address in the MAR to MDR Upon the instruction, Add/Subtract/Copy the content of MDR to the accumulator. Reset by going to first step in fetch cycle. U n i t 2 Numbers, processors and operating systems 11 Describe the purpose of an operating system The operating system manages all other programs and applications (and hardware). On many computers, when it is powered up, the first program that runs is stored on a ROM chip. This program checks system hardware to make sure everything functions normally. The next thing to check is the CPU, the internal memory and basic input-output system (bios) for errors. If all proves to be acceptable, the bios activates the memory drives. When the drive is activated, the operating system is found and is loaded. The operating system is system software. It is a group of programs that manages the computer’s resources. This includes the following functions: Memory Management o One of the main duties of an OS o When you open an application the OS loads the necessary parts into memory o The OS will load extra parts into memory as they are required o If features haven’t been used in a while the OS will remove them from memory to try to free up space Peripheral management o Manage the way software interacts with Hardware o A device driver acts as a go between for other software to ‘talk’ to the hardware o Most device drivers are loaded into memory by the OS during booting but some are connected with the peripheral is connected to the computer o When you have finished with the application, the OS will remove it from memory Multi-tasking o Allows several processes to be resident in RAM at the same time. These processes are in different states – running, runnable or waiting. o While a process is running, it has the attention of the CPU. Other processes must wait. Security o Operating Systems must protect processes from each other. o Ensuring processes don’t overwrite each other o They also must protect users from each other o Keeps track of who ‘owns’ each process and each file Providing a user interface o Command Line o Graphical User Interface (GUI) o Voice Input File Management o A file directory is an index of the contents of a virtual container for files and sub-directories maintained by the operating system’s file manager o In a GUI, a directory is displayed as a folder and the two terms are often used interchangeably. o Facilities include: List, Move, Copy, Print A buffer is an area of memory used to hold data temporarily to compensate for different rates of processing data by the processor and a (slower) peripheral and allow the processor to perform other tasks while waiting to receive or send data. Handshaking involves sending electronic signals during transfer of data to control the flow of data between the computer and a peripheral device (or over a network with another computer) to prevent a delay in processing data at the receiving end resulting in lost data U n i t 2 Numbers, processors and operating systems 12 Show understanding of the need for interrupts Peripheral devices such as keyboards and printers must be controlled and responded to by the operating system. Communication between the computer and peripherals must be controlled and errors detected. When a device is required by a program, a signal called an interrupt is generated. Interrupts allow for more efficient operation of a computer system. It interrupts the operating system and tells it to stop running the current program and switch the CPU’s attention to a different program that is looking after the peripheral. The interrupts have code numbers and these are different for each operating system. When the job with the peripheral is finished, the CPU is directed back to the original program, to the point where it was interrupted. The alternative method of communicating with peripherals is polling where the operating system is responsible for periodically interrogating each peripheral device in turn to discover its status. The disadvantage of this method is that the operating system has to devote significant processing time to polling all the peripheral devices, even when the devices are not active. U n i t 2 Numbers, processors and operating systems