Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 i206: Lecture 4: The CPU, Instruction Sets, and How Computers Work Marti Hearst Spring 2012.

Similar presentations


Presentation on theme: "1 i206: Lecture 4: The CPU, Instruction Sets, and How Computers Work Marti Hearst Spring 2012."— Presentation transcript:

1 1 i206: Lecture 4: The CPU, Instruction Sets, and How Computers Work Marti Hearst Spring 2012

2 2 Summary from Last Time Quick Binary Exercise Boolean Logic –deMorgan’s Law Relating Boolean Logic to Circuits –Logic gates Special gates: –Flip Flops –Adders –Decoders

3 3 Revisit DeMorgan’s Laws A B = A B The inverse or complement of any Boolean expression can be found by successively applying the following theorems: (x + y)' = x'y' (xy)' = x' + y’

4 4 How fast is a logic gate? “Computers used to work in milliseconds (1,000ths), then moved up to microseconds (millionths), and now are approaching nanoseconds (billionths) for logic operations - and picoseconds (trillionths!) for the switches and gates in chips.” A nanosecond (ns) is one billionth of a second, 10^-9 seconds. http://science.nasa.gov/science-news/science-at-nasa/2000/ast28apr_1m/

5 5 Example; Linking Boolean to Circuits Lighting up a digital clock

6 6 7 Segment LEDs: How to set the digits Images from http://www.ee.ed.ac.uk/~gaa/DigilabNotes/Digilab/Components/node7.html Need a lot of gates to implement this truth table.

7 7 7 segment Digital Display How to turn on only 1 of the 4 digits at a time? Images from http://www.ee.ed.ac.uk/~gaa/DigilabNotes/Digilab/Components/node7.html a b c d e f g p i1 i2 i3 i4

8 8 n-bit Decoder: Takes as input n inputs; turns on 1 (and only 1) of outputs Righthand image from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/Circuits/index.html AB W X Y Z a b c d e f g p w x y z

9 9 n-bit Decoder: Takes as input n inputs; turns on 1 (and only 1) of outputs Righthand image from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/Circuits/index.html AB W X Y Z What else could you use this for? How about selecting between 4 kinds of instructions? (add, subtract, multiply, divide)

10 10 How a Flip Flop Works: Try out this tool: http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/Circuits/index.html

11 11 The CPU Central Processing Unit

12 12 The CPU Registers –Are basically rows of latches –Store values –Can be used to hold values of variables as well as memory addresses. Special registers –PC (program counter) Points to the location in memory that has the current instruction. –Instruction Register Holds the current instruction. –Accumulator Hold the current value of the ALU

13 13 The CPU ALU (Arithmetic Logic Unit) –Made of a long series of adder units –Addition, Subtraction (Mult, Div) –Lots of gates, so often the slowest circuit in the CPU Image from http://eleceng.ucd.ie/~rreilly/elecengnotes/LECTURE18/sld017.htm

14 14 Circuits for Binary Addition Full Adder Images from http://www.play-hookey.com/digital/adder.html

15 15 Circuits for Binary Addition Full Adder, 4 bit output + carry Can link up an arbitrary number of input bits Can modify this easily to do subtraction Can also modify to do multiplication –How? –Usually division is done with a special floating point chip Images from http://www.play-hookey.com/digital/adder.html

16 16 Arithmetic Logic Unit (ALU) Add, Subtract, and Logic Operations http://www.seas.upenn.edu/~ee201/lab/LabALU/ALU.html

17 17 A key computer science concept: Code and data can be represented in the same way.

18 18 The Stored-Program Concept Programs (code) are represented in the same way that data is. This way, both code and data can be stored in the same place as well. This is a key concept for understanding how the CPU works.

19 19 Computer Memory We represent data as 0 ’ s and 1 ’ s (bits) –8 bits in a byte –2 to 4 bytes in a word –Words represented schematically as rows in memory –Each word has High order bit (most significant bit) Low order bit (least significant bit) We also represent locations as 0 ’ s and 1 ’ s –These locations are called addresses

20 20 RAM (Random Access Memory) One set of wires activates the appropriate location Another set of wires –reads the data value from that location or –writes the data value to that location RAM is arranged as a grid –Each column is a word (or some number of bytes) –First activate the correct column –Then either Read the word ’ s values into the row output, or Write the row ’ s values into the word Read: get the value (don ’ t change it) Write: set the value (change it)

21 21 How DRAM Works This example memory holds 8 bytes. Say we want to change the contents of memory address number 0101 (which is the fifth one from the right) Image adapted from http://www.howstuffworks.com/ram.htm First, activate the column that corresponds to this address Converting 0101 to 00010000 requires circuitry (not shown)

22 22 How DRAM Works Saw we want to set this memory address to contain the value 01001011 When two activated lines cross, the cell at the intersection gets turned on. Image adapted from http://www.howstuffworks.com/ram.htm 0 1 0 0 1 0 1 1

23 23 How DRAM Works Now we ’ ve set the value. Reading moves the data the other direction, onto the row (a special control wire, not shown, tells the circuit whether to read or write). Image adapted from http://www.howstuffworks.com/ram.htm

24 24 Machine Language Only a very few unique instructions (commands) are needed for all CPU functionality. Called: –Machine instructions –Machine language –Machine code Represented in binary Assembly language: the human-readable version –Each statement of assembly language corresponds to one machine instruction. Need an assembler program to convert assembly language to machine code.

25 25 Machine Language Why so few instructions? (Nearly) everything is built up from: –Add/subtract/compare values (for jumps) –Load (into registers from memory) –Store (from registers into memory) –Get next instruction (or jump to another instruction)

26 26 Relation to High Level Languages Java, Python, C are all high level programming languages. They are translated to assembly language by a compiler and/or an interpreter.

27 27 Instructions and Their Representation Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ The op-code area holds operations. How many unique op-codes can this setup support?

28 28 Instructions and Their Representation Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/

29 29 Instructions and Their Representation Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ The Operand area holds memory addresses and data values. 111111 = 1 + 2 + 4 + 8 + 16 + 32 = 63 What is the largest memory address?

30 30 The CPU Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ Bus: bundles of wires connecting things. Instruction Register: holds instructions. Program Counter: points to the current memory location of the executing program. RAM: stores the code (instructions) and the data.

31 31 The CPU Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ MUX: multiplexer – chose 1 out of N (ALU or RAM in this case) ALU: adds, subtracts, compares two numbers (it has 2 words of storage, on the left and the right) Accumulator: stores ALU ’ s output Decoder: uses the 3-bit op- code and the number bit to control the MUX and the ALU and the memory buses.

32 32 Machine code to add two numbers that are stored in memory (locations 13 and 14) and then store the result into memory (location 15). The Program Counter starts at memory location 0. Image adapted from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/

33 33 Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ The Program Counter starts at memory location 0. (Notice: the instructions and the data are both stored in the RAM.) This instruction moves along the bus into the instruction register. The decoder checks the number bit to see how to handle the op- code.

34 34 Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ If the op-code number bit = 0, we want the operand to be used as a memory address. So the decoder switches the MUX to connect the operand to the RAM. If the bit were 1, the MUX would connect the operand to the ALU. The green wires do the addressing of the RAM. The blue wires do the reading to and writing from the RAM.

35 35 Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ The Decoder tells the ALU this is a LOAD instruction. The memory location 13 is activated, and its value placed on the blue bus. This goes through the multiplexer into the ALU. It also trickles down into the Accumulator (Load is implemented as an ADD value to 0). The last step (always, except for a jump) is for the Program Counter to get incremented. Now it points to memory location 1.

36 36 Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ Instruction: ADD 14 Similar to Load 13, except the ALU is given the ADD operation. The contents of the Accumulator are fed into the left hand operand, and the contents of memory location 14 becomes the right hand operand. Results of the AND end up in the Accumulator. The Program Counter increments.

37 37 Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/ Instruction: STORE 15 Memory address 15 is activated via the green bus. The contents of the Accumulator are written to RAM in location 15 using the blue bus. The Program Counter increments. The next instruction is HALT.

38 38 CPU Performance CPU cycles are not the whole story The number of INSTRUCTIONS per second play a big role. –Each operation on the computer requires some instructions e.g., about 6 instructions required for the loop part of a simple for-loop. –Each instruction takes some number of cycles to execute. –So … a CPU with an instruction set and circuit design that requires fewer cycles to get operations done might have better performance than a CPU with a faster clock but more complicated circuitry.

39 39 Measuring CPU Performance MIPS: –millions of instructions per second –“ meaningless indicator of performance ” (a joke) –Some instructions require more time than others –No standard way to measure MIPS FLOPS: –floating-point operations per second –Measures the speed of the floating point unit A special circuit that does math on real numbers So, doesn ’ t measure performance on non-numeric applications Benchmark: –A test used to compare performance of hardware and/or software. –Different benchmarks measure different aspects of performance SPEC: –Standard Performance Evaluation Corporation –A set of standardized tasks (benchmarks) that CPUs are run on in order to assess their performance. Adapted form http://webopedia.internet.com/

40 40 CPU Performance CPU clocks are related to another commonly used term… Real Time –Means regular clock time as opposed to CPU clock time –Other factors also prevent a program from running in real time CPU scheduling, discussed in today ’ s lecture In common usage today, –Real time means right now, as I ’ m talking, as opposed to –Offline, when I have to think on my own, or when we ’ re not in the middle of a timed event with others listening.

41 41 Summary Boolean logic is used to make logic gates, which build up into circuits. Binary is used to represent both code and data in memory, in instruction registers, and in the arithmetic logic unit. Binary instructions move through the circuits, controlling the computer’s operation and also doing the operations themselves. –Adding, subtracting, moving locations. This is pretty much what it takes to do computation! –After you write the program, compile it, and load it into the CPU and memory.


Download ppt "1 i206: Lecture 4: The CPU, Instruction Sets, and How Computers Work Marti Hearst Spring 2012."

Similar presentations


Ads by Google