Presentation is loading. Please wait.

Presentation is loading. Please wait.

Elements of the Computer (How a processor works)

Similar presentations


Presentation on theme: "Elements of the Computer (How a processor works)"— Presentation transcript:

1 Elements of the Computer (How a processor works)
C.S. French Chapter 19 The purpose of this lecture is to give you a little understanding about how computers actually work. At this point you should know how computers store information as either (i) numbers in binary or (ii) letters in binary using the ASCII or ANSI coding system. Now we need to see how computers can take that data, follow a set of instructions and create new information from the data. If you would like to know the key points from this lecture they are the following: The computer’s memory is used to store two things: instructions and data. The instructions are bunched together in sequences known as programs. The processor is the part of the computer that executes these program by obeying the instructions one by one. The processor obeys each instruction in a 2 stage method: first it FETCHES an instruction from memory, then it EXECUTES the instruction. Most times when it is executing an instruction it needs to fetch some data from memory to work on. As it works through a program if fetches, executes, fetches, executes and so on. This is known as the fetch/execute cycle. Now read the lecture and see how a simple Central Processing Unit does this. Although it seems a little complicated, it is the principles that I’d like you to understand (you don’t have to remember detailed terms). It is quite short.

2 The Computer itself. Processor 1 2 3 4 5 6 7 8 9 10 11 12 Data Bus
Memory Control Unit ALU 1 2 3 4 5 6 7 8 9 10 11 12 CIR Accumulator SCR Input Output Unit Peripheral Devices MAR MDR Although this diagram looks quite different, it is actually similar to one you’ve seen before: The memory, Processor and Input/Output unit all connected to each other via the data bus. The difference here is that (I) the memory is divided up into individual numbered compartments and (ii) some details of the insides of the processor are show. You should take down a sketch of this for your notes and refer to that sketch as you read the following pages. Note how the data bus is connected into the memory. It’s not really physically built like this, but it works in such a way that it is like having a switch that can swivel around and connect to any of the memory compartments (locations). At the moment it is connected to location 4, but it can easily be changed to connect to another location. These memory locations are really very small, consisting of 8 or maybe 16 cells that can store ones or zeros (bits). This diagram only shows 12 but really there can be millions of them. Data Bus

3 Terms Memory main memory (RAM), electronic, fast, volatile, expensive, holds data currently in use. made up of many general purpose storage locations. may hold data or instructions. locations referred to by their ‘addresses’. Data Bus a set of wires for transmitting data. Processor controls the computer and carries out processing. Register a special purpose storage location in the processor. Control Unit controls the loading and execution of instructions. MDR (Memory Data Register) holds data temporarily as it enters and leaves the processor. Memory refers to the working storage where we temporarily keep data and programs we are working on as opposed to the auxilliary sorage on hard discs, floppies, zips, CDROMs. Each location can be referred to by a number, called it’s address. You’ll notice that the processor has rectangles with 3 letter codes on them. These represent areas for storing bits (ones and zeros) for particuclar purposes and are called registers. Each of them has a different name and purpose – we’ll look at these now. The Contrul Unit is really the most central part of a computer. It knows how to follow all the instructions in a computer program (eg MS Word). The instructions in these programs are stored in the memory when the program is operating. The control unit organises to read in the instructions on at a time from memory and then figure out what has to be done to obey each instruction. In order to oney these instructions, it must be able to control everything else in the processor. It may have to delegate by sending further instructions to the other parts of the processor. Memory Data Register: data moves from memory to the processor via the switch, down onto the databus ond into the processor. The MDR holds the data (ones and zeros) as they come in and also as they go out if they are being transferred the other way.

4 More Terms ALU (Arithmetic and Logic Unit)
carries out arithmetic and logic operations. (add, subtract, AND, NOT etc) Accumulator holds the result of the last operation carried out by the ALU. CIR (Current Instruction Register) holds the instruction that is currently being interpreted and executed by the Control Unit. MAR (Memory Address Register) holds the address of the memory location which is currently connected to the data bus. (controls access to memory) SCR (Sequence Control Register) holds the address of the memory location of the instruction that is to be executed after the current one is finished. this is ‘incremented’ by 1 each time it is copied to the MAR. The Arithmetic and Logic Unit (ALU) does all sorts of calculations. The control unit organises data for it and then tells it to carry out a particular calculation. When it has carried out a particular calculation, the result of the calculation is stored in the register called the Accumulator (It’s a bit like your small screen on your calculator) This result can then be used for further calculations (just like on your calculator also) The sequence of instructions that makes up a computer program is stored in memory. However, at any particular point in time, the processor can only be carrying out one of the instructions in that program. The Current Instruction Register (CIR) stores a copy of the instruction that the processor is trying to obey just at that time. The processor needs to keep track of where it is in that program, otherwise it won’t know which instruction to carry out next after the one it is working on. The Sequence Control Register (SCR) holds a number indicating where in memory to get the next instruction to be executed after the current on is finished. How does it go and get the next instruction. It copies this number in the SCR over to the Memory Address Register (MAR). So the MAR now should hold the number of the location in memory where the processor is supposed to get the next instruction to be obeyed. Now the MAR is directly connected to that swivelling switch and it is it’s job to control what it is connected to in memory, so it turns the switch to point at the correct memory location. The computer can now copy the contents of that memory location down onto the data bus and into the processor.

5 Peripheral Devices Input
keyboard, mouse, bar-code readers, camera, microphone etc Output screen, printer, plotter, mechanical device etc. Communications modem, ISDN adaptor, network card etc. Backing Storage slow, non-volatile, usually mechanical, cheap. floppy disk, hard disk, CDROM, magnetic tape, zip disk You were asked to categorise these peripheral devices yourself before. Did you get them right?

6 How the computer works. Machine instructions and data are stored in memory in binary format. A machine instruction consists of 2 parts: Operation code: holds the binary code for the operation that is to be carried out by the processor. Operand address: this is the address in memory where the processor may find the data that is to be operated on. Machine instructions are ‘fetched’ from memory and then ‘executed’ by the processor. The types of instructions that a computer’s processor (control unit) can obey are called: “machine instructions” (and a sequence of these is called a program). When running a program (eg. MS Word) the sequence of instructions is loaded into memory and stored in a series of contiguous (beside each other) memory locations as ones and zeros. Data (numbers and text) that the program needs to work on (eg. The letters of the alphabet in a report that you might be writing), are stored somewhere else in the memory. The processor has a fixed vocabulary of types of instructions that it can understand (eg an instruction to add 2 numbers, or to copy a number from somewhere in memory into the processor). Each type of instruction that it can understand has a short binary code to represent it ( eg: 0011 might represent ADD) – this is called the operation code. However, each instruction needs some data to work (operate) on. The first part of any instruction holds the code needed to specify what type of an instruction it is (operation code), but the second part holds the address in memory of the location that holds the data that the instruction has to work on (operand address). So an instruction that looked like would mean: ADD (0011) the contents of memory location 2 (000010) to whatever is already in the Accumulator. Now it is the Control Unit that will actually obey this instruction. In order to do this the instruction has to be loaded into the Current Instruction Register, so it is copied from wherever it is in memory via the databus, into the Memory Data Register and then up into the Current Instruction Register. This is called “fetching” the instruction. The instruction can then be obeyed by the control unit. This is called “Executing” the instruction. From this slide and the next, 1st years would be expected to be able to describe the principle of the fetch/execute cycle as opposed to the details of how this cycle is implemented.

7 The Fetch/Execute cycle.
The address of the next instruction to be executed is copied from the SCR to the MAR. The SCR is incremented by 1. The information is copied from memory to the MDR. The contents of the MDR is copied to the CIR. The operation code part of the instruction in the MDR is copied to the control unit. The control unit recognises the instruction and executes it (the execution will vary depending on the instruction). In order to carry out a whole program of instructions, the processor needs to fetch each one and execute it, one after the other after the other. So it is constantly fetching one, executing it, fetching the next one then executing it and so on. This is called the “fetch/execute cycle”. The diagram above shows the same procedure being followed over and over like going around a wheel. The processor has one neat little trick that keeps it doing this over and over again. Remember that we said that the Sequence Control Register(SCR) holds the address of the next instruction that has to be fetched. If we need to get this from memory, then we will have to swivel the memory switch to the correct location. If we copy the number in the SCR over to the MAR, this will automatically happen (as the MAR controls the swivel switch). Now when this copy is done, the SCR is automatically increased (incremented) by 1. This neat little trick means that the next time around, when the SCR is copied over to the MAR, the number will be one more than the last time and so it will automatically get the next instruction after the last one. Now after the SCR is copied over (and increased) the swivel switch moves, the memory location containing the instruction is copied via the databus into the processor through the MDR and up into the Current Instruction Register (Fetched). The first part of the instruction (the operation code) is examined by the Control Unit. It works out what type of instructions it is, then sends whatever instructions it needs to to other parts of the processor in order that the instruction be obeyed (Executed). Once the instruction has been obeyed, it then goes back around the cycle again and fetches the next instruction and then obeys it, and so on, and so on.

8 The LOAD instruction. (Not required for 1st years)
Purpose: to load data from memory to the accumulator. The operation address part of the CIR is copied to the MAR. The location in memory is copied to the MDR. The MDR is copied to the accumulator. No more of this lecture is required for first year students. Go back to the very first slide and read the key points of the lecture.

9 The STORE instruction (Not required for 1st years)
Purpose: to copy the contents of the accumulator to a location in memory. The operation address part of the CIR is copied to the MAR. The accumulator is copied to the MDR. The MDR is copied to the location in memory .

10 The ADD instruction (Not required for 1st years)
Purpose: to add the contents of a memory location to the contents of the accumulator. The operand address in the CIR is copied to the MAR. The contents of memory is copied to the MDR. The MDR contents are copied to the ALU which adds it to the accumulator, placing the result in the accumulator.

11 The JUMP instruction. (Not required for 1st years)
Purpose: to transfer control in a program to an instruction other than the next one. The contents of the operand address are copied to the SCR. Variations: JUMP NEGATIVE JUMP ZERO JUMP POSITIVE The contents of the operand address are only copied to the SCR if the accumulator is in the correct condition.

12 Machine language exercises (Not required for 1st years)
Given the binary codes for these machine instructions write the programs described below. LOAD 0001 STORE 0010 ADD 0011 JUMP 0100 JUMP JUMP JUMP Program to add together the contents of memory locations 10 and 11 and store the result in location 12. Program to count down from 9 to zero.


Download ppt "Elements of the Computer (How a processor works)"

Similar presentations


Ads by Google