Скачать презентацию Chapter 9 How does a computer do it Скачать презентацию Chapter 9 How does a computer do it

489c23f091e1920393e13e3cbaba70aa.ppt

  • Количество слайдов: 52

Chapter 9: How does a computer do it? Introduction to Computers CS 1100 Dr. Chapter 9: How does a computer do it? Introduction to Computers CS 1100 Dr. Zhizhang Shen Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

What about it? • Once the data is brought in, how does the computer What about it? • Once the data is brought in, how does the computer process them? • We will check out the basic structure of a computer and • A basic process a computer goes through to process the data 1 -2 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -2

What can it do and can’t do? (CS 3780) • What computers can do What can it do and can’t do? (CS 3780) • What computers can do – Deterministically perform or execute instructions to process information – The computer must have instructions to follow • What computers can't do – – – – Have no imagination or creativity Have no intuition Have no sense of irony, subtlety, proportion, decorum, or humor Are not vindictive or cruel Are not purposeful Have no free will It only does whatever it is told 1 -3 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -3

A general mode of any computer(CS 2200, CS 4250) • Computers have five basic A general mode of any computer(CS 2200, CS 4250) • Computers have five basic parts or subsystems – Memory, control unit, arithmetic/logic unit (ALU), input unit, output unit 1 -4 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -4

How does the computer do it? • A program consists of a sequence of How does the computer do it? • A program consists of a sequence of instructions. • For each instruction so kept in the memory, the computer bring it into the processor and get it executed. • It starts with the first instruction. • The computer keeps on doing it until there is nothing left. 1 -5 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -5

The Fetch/Execute Cycle • For any instruction, it goes through the following steps: 1. The Fetch/Execute Cycle • For any instruction, it goes through the following steps: 1. Instruction fetch (IF): what to do? 2. Instruction decode (ID): what is it? 3. Data fetch (DF) / Operand Fetch (OF): how? 4. Instruction execution (EX): do it! 5. Result return (RR) / Store (ST): put it back. 1 -6 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -6

1 -7 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -7 1 -7 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -7

Memory • Memory stores the program running and the data on which the program Memory • Memory stores the program running and the data on which the program operates (von Neumann architecture) • Properties of memory: – Discrete locations. Each location consists of a fixed amount of space. Recall the computer word stuff – Addresses. Every memory location (byte) has an address (whole numbers starting with zero). Rounds 206 – Values. Memory locations record or store values. – Finite capacity. Limited size—programmers must remember that the data may not "fit" in the memory location. N bits keep 2^N things. 1 -8 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -8

Byte-size memory location • A commonly used diagram of computer memory represents the discrete Byte-size memory location • A commonly used diagram of computer memory represents the discrete locations as boxes with fixed capacity. (Super 8 motel) • Address of location is displayed above the box. • Value or contents of location is shown in the box. 1 -9 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -9

1 -10 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -10 1 -10 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -10

Memory (cont'd) • 1 -byte memory locations can store one ASCII character, or a Memory (cont'd) • 1 -byte memory locations can store one ASCII character, or a number less than 256 (0 - 255) • Programmers use a sequence of memory locations together, ignoring the fact that they all have different addresses – Blocks of four bytes are used as a unit so frequently that they are called memory "words“ – It is different in the 64 bit machine. 1 -11 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -11

Random access memory (RAM) • Random access memory (RAM) • "Random access" means the computer can refer to (access) the memory locations in any order, and it takes the same time no matter where it is kept. • Often measured in megabytes (MB) – millions of bytes or gigabytes (GB) – billions of bytes • Large memory is preferable because there is more space for programs and data (less I/O) 1 -12 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -12

Control unit • Hardware implementation of the Fetch/Execute Cycle • Its circuitry fetches an Control unit • Hardware implementation of the Fetch/Execute Cycle • Its circuitry fetches an instruction from memory, decodes the instruction, and fetches the operands used in it – A typical instruction might have the form ADD 4000, 2080 op dest, src 1, src 2 – This instruction asks that the numbers stored in locations 2000 and 2080 be added together in CPU, and the result stored in location 4000 [4000] = [2000] + [2080] – Data/Operand Fetch step must get these two values and after they are added, Result Return/Store step will store the answer in location 4000 1 -13 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -13

1 -14 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -14 1 -14 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -14

Arithmetic/Logic Unit (ALU) • Performs the math and logic operations such as AND, NOT. Arithmetic/Logic Unit (ALU) • Performs the math and logic operations such as AND, NOT. • Generally does the work during the Instruction Execute step of the Cycle • A circuit in the ALU can add two number, and other stuff such as multiplication and comparison, etc. • Instructions that just transfer data usually don't use the ALU • Data/Operand Fetch step of the Cycle gets the values that the ALU needs to work on (operands) • When the ALU completes the operation, Return Result/Store step moves the answer from the ALU to the destination memory address specified in the instruction 1 -15 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -15

Input Unit and Output Unit (I/O) • The wires and circuits through which information Input Unit and Output Unit (I/O) • The wires and circuits through which information moves into and out of a computer • It is perhaps the most complex part since there are so many of them. • The peripherals: Connect to the computer input/output ports. They are not considered part of the computer, but specialized gadgets that encode or decode information between the computer and the physical world. • KB, mouse, scanner, camera, mic, printer, storage, cable modem, … 1 -16 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -16

The Peripherals • Keyboard encodes keystrokes we type into binary form for the computer The Peripherals • Keyboard encodes keystrokes we type into binary form for the computer • Monitor decodes information from the computer's memory and displays it on a lighted, colored screen • Disks drives are used for both input and output— storage devices where the computer puts away information when it is not needed, and can retrieve from when it is needed again 1 -17 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -17

A Device driver for every peripheral • A Device driver for every peripheral • "Dumb" devices provide basic physical translation to or from binary signals. • Additional information from the computer is needed to make it operate intelligently. • e. g. , computer receives information that user typed shift and w at the same time. It converts to a capital W. The software that converts is called the device driver. 1 -18 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -18

The Program Counter: Where am I? • How does the computer determine which step The Program Counter: Where am I? • How does the computer determine which step to execute next? • Address of the next instruction is stored in the control part of the computer. It is called the program counter (PC). • Because instructions use 4 bytes of memory, the next instruction must be at PC + 4, 4 bytes further along in the sequence (in general). • Computer adds four to the PC, so when the F/E Cycle gets back to Instruction Fetch step, the PC is "pointing at" the next instruction. 1 -19 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -19

Branch and Jump Instructions • The program typically goes in a sequence: get up, Branch and Jump Instructions • The program typically goes in a sequence: get up, have class, have lunch, have class, have dinner, go to bed. • It can also go to somewhere else. This changes the PC, so instead of going to PC +4 automatically, the computer “jumps” or “branches” to the specified location. 1 -20 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -20

Loop instructions • Beside sequential and branch, the computer also needs a loop structure Loop instructions • Beside sequential and branch, the computer also needs a loop structure that will keep on doing something until a condition turns true. • Various loop structures – Keep on drinking until drunk – While not drunk keep on drinking – Drink exactly 4 bottles 1 -21 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -21

Instruction interpretation • Process of executing a program – There at least two languages: Instruction interpretation • Process of executing a program – There at least two languages: one for us, one for the machine. – Computer is interpreting our commands, but in its own language • Before the F/E Cycle begins, some of the memory locations and the PC are visible in the control unit 1 -22 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -22

1 -23 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -23 1 -23 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -23

Step 1 • Execution begins by moving instruction at the address given by the Step 1 • Execution begins by moving instruction at the address given by the PC from memory to control unit 1 -24 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -24

Step 2 • Every instruction is cut into two pieces: what to do and Step 2 • Every instruction is cut into two pieces: what to do and where to get the data. • The what to do part of instruction are placed into the decoder circuit of the CU • Then, it goes there to get the data • Once instruction is fetched, the PC can be readied for fetching the next instruction 1 -25 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -25

Step 3 • In Instruction Decode step, ALU is set up for the operation Step 3 • In Instruction Decode step, ALU is set up for the operation as required • Decoder will find the memory address of the instruction's data (source operands) – Most instructions operate on two data values stored in memory (like ADD), so most instructions have addresses for two source operands – These addresses are passed to the circuit that fetches them from memory during the next step, Data Fetch • Decoder finds destination address for the Result Return step, and places it in RR circuit • Decoder determines what operation the ALU will perform, and sets it up appropriately 1 -26 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -26

1 -27 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -27 1 -27 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -27

Step 4 • Instruction Execution: The actual computation is performed. • In this case, Step 4 • Instruction Execution: The actual computation is performed. • In this case, get out the data kept in (428) and (824) and put it back in (800) • For ADD instruction, the addition circuit adds the two source operands together to produce their sum 1 -28 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -28

1 -29 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -29 1 -29 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -29

Step 5 • Result Return: result of execution is returned to the memory location Step 5 • Result Return: result of execution is returned to the memory location specified by the destination address. • In this case, the result 54 is put in (800). • Once the result is returned, the cycle begins again. 1 -30 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -30

1 -31 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -31 1 -31 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -31

Lots of simple operations • Addition is only one of them • Computers can Lots of simple operations • Addition is only one of them • Computers can only perform about 100 different instructions – About 20 different kinds of operations (different instructions are needed for adding bytes, words, decimal numbers, etc. ) • Everything computers do must be reduced to some combination of these primitive, hardwired instructions 1 -32 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -32

What are the others? • Besides ADD, MULT (multiply) and DIV (divide), other instructions What are the others? • Besides ADD, MULT (multiply) and DIV (divide), other instructions include: – Shift the bits of a word to the left or right, filling the emptied places with zeros and throwing away bits that fall off the end – Compute logical AND (test if pairs of bits are both true), and logical OR (test if at least one of two bits is true) – Test if a bit is zero or non-zero, and jump to new set of instructions based on outcome – Move information around in memory – Sense signals from input/output devices 1 -33 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -33

Cycling the F/E Cycle • Computers get their impressive capabilities by executing many billions Cycling the F/E Cycle • Computers get their impressive capabilities by executing many billions of these simple instructions per second • The Computer clock: Determines rate of F/E Cycle – Measured in gigahertz (GHz), or billions of cycles per second 1 -34 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -34

1 -35 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -35 1 -35 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -35

Clock speed? • Modern computers try to start an instruction on each clock tick Clock speed? • Modern computers try to start an instruction on each clock tick • Pass off finishing instruction to other circuitry (pipelining) – Five instructions can be in process at the same time – Pipeline: different phase is done at different time – Average time goes up. Instead of 10, it now goes down to 10/7 • Does a 1 GHz clock really execute a billion instructions per second? – Not a precise measurement. Computer may not be able to start an instruction on each tick, but may sometimes be able to start more than one instruction at a time 1 -36 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -36

1 -37 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -37 1 -37 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -37

Assembly languages (AL) – Machine language (ML) is the native language, consisting of only Assembly languages (AL) – Machine language (ML) is the native language, consisting of only 0 and 1. ML is hard to read and understand for us, but the only language a machine understands. – AL is an alternative form of ML, using letters and normal numbers so people can understand it (mnemonic codes) – When scanning AL code, and seeing a word such as ADD, it looks them up in a table to convert it to binary. It also converts numbers to binary, then assembles the binary pieces into an instruction – It is now ready for the hardware to take over Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 -38 9 -38

1 -39 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -39 1 -39 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -39

High-level programming languages – Even AL is tough to crack for us, such as High-level programming languages – Even AL is tough to crack for us, such as ADD 800 484 848 – Most modern software is written in a high-level notation, which is then compiled (translated) into assembly language, which is then assembled into binary code 1 -40 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -40

Something special… – Have special statement forms to help programmers give complicated instructions • Something special… – Have special statement forms to help programmers give complicated instructions • Example: Three-part if statement If (I am not drunk) Get me another one; Else lie on the floor 1 -41 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -41

1 -42 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -42 1 -42 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -42

1 -43 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -43 1 -43 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -43

Operating systems (CS 4310) • Basic operations that are necessary for the effective use Operating systems (CS 4310) • Basic operations that are necessary for the effective use of computer, but are not built into the hardware • Three most widely used Operating Systems: – Microsoft Windows – Apple's Mac OS X – Unix / Linux • OS performs booting, memory management, device management, Internet connection, file management and provide a user interface. 1 -44 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -44

Programming • Programmers build on previously developed software to make their jobs easier (Software Programming • Programmers build on previously developed software to make their jobs easier (Software reuse) • Example: GUI Software – Frame around window, slider bars, buttons, pointers, etc. are packaged for programmers and given with OS 1 -45 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -45

Integrated Circuits • Technically, we can build a machine with light switches, but it Integrated Circuits • Technically, we can build a machine with light switches, but it is too big. • Miniaturization: – Clock speeds are so high because processor chips are so tiny (electrical signals can travel about 1 foot in a nanosecond) – Billions of transisters, tiny switches, are placed on 1 sq. inch chips. 1 -46 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -46

Combining the Ideas § Start with information processing task § Task is performed by Combining the Ideas § Start with information processing task § Task is performed by application, implemented as part of a large program in a high-level language like C or Java § Program performs specific operations; standard operations like print or save are done by OS § Program's commands are compiled into assembly language instructions 1 -47 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -47

Moore’s law • In the past sixty years, the costperformance ratio of sequential computing Moore’s law • In the past sixty years, the costperformance ratio of sequential computing has improved about 100 billion times overall. • This is done, during the last 20 years, mainly due to Moore’s observation that “The number of transistors that have been put onto a chip has been doubled every eighteen month”. 1 -48 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -48

An example • Intel 8086, a processor chip made by Intel in 1978, contained An example • Intel 8086, a processor chip made by Intel in 1978, contained 29, 000 transistors, and ran at 5 MHz. • Intel Core 2 Duo, introduced in 2006, contained 291 million transistors and ran at the speed of 2. 93 GHz. • Thus, during those 28 years, the number of transistors has gone up by 10, 034 times and, as a result, the speed goes up by 586 times. • In this specific case, the number of transistors is doubled once every 24 months, or two years. 1 -49 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -49

It all comes to an end…. • Moore’s law will stay for another decade It all comes to an end…. • Moore’s law will stay for another decade or two. • We won’t put this many transistors into one processor. • Instead, we will use them to come up with multiple processors. • We are at a critical juncture of computer technology development. 1 -50 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -50

Combining the Ideas § Assembly instructions are translated into binary code § Binary instructions Combining the Ideas § Assembly instructions are translated into binary code § Binary instructions are stored on hard disk (secondary memory) § Application instructions move into RAM (primary memory) § Fetch/Execute Cycle executes the instructions § All the computer's instructions are performed by the ALU circuits, using the transistor model previously described, under the control of the Control Unit 1 -51 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -51

Homework • Multiple choices: odd numbered • Short answers: even numbered • Complete Exercise Homework • Multiple choices: odd numbered • Short answers: even numbered • Complete Exercise 3, 4, 5, 9, and 12. 1 -52 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 -52