Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP 4—Power Tools for the Mind 1 What’s in the box? Computer architecture, part 1: What we’ll cover for this lecture topic: –What is a CPU? –How is a.

Similar presentations


Presentation on theme: "COMP 4—Power Tools for the Mind 1 What’s in the box? Computer architecture, part 1: What we’ll cover for this lecture topic: –What is a CPU? –How is a."— Presentation transcript:

1

2 COMP 4—Power Tools for the Mind 1 What’s in the box? Computer architecture, part 1: What we’ll cover for this lecture topic: –What is a CPU? –How is a program executed by the CPU? –Boolean logic –Binary circuits that can add!

3 COMP 4—Power Tools for the Mind 2 What’s in the box? Central Processing Unit (CPU): –Carries out the program’s instructions! Operates on data it finds in the computer’s memory. –Also called Microprocessor Includes all binary circuits that carry out arithmetic & logic operations---reduced to a single IC. – CPU has four key parts that we will examine: Control Unit Arithmetic & Logic Unit Registers Clock And, of course, wires that connect everything together.

4 COMP 4—Power Tools for the Mind 3 What’s in the box? —CONTROL UNIT (CU): circuitry for coordinating machine’s activities. Controls sequence of operations. —ARITHMETIC & LOGIC UNIT (ALU): circuitry to perform data manipulation (arithmetic & logic). —Registers : Temporary storage areas. Holds information applicable to the current operation. —Clock : Triggers start and stop of all CPU operations. (heartbeat) CPU CU ALU Two main functional units: clock Registers

5 COMP 4—Power Tools for the Mind 4 What’s in the box? CPUs support a set of very simple instructions that typically fall into the following categories: Data movement (load, store, copy…) Arithmetic/logical (add, subtract, compare..) Program control (branch, halt…) –Very primitive commands (operations) executed by the CPU [ logical structure] –These commands are implemented as electronic binary circuits [ physical structure] which can transform the 0s and 1s. BASIC INSTRUCTION SET

6 COMP 4—Power Tools for the Mind 5 What’s in the box? Sample of a partial Basic instruction set Instr: Meaning: STOStore data in a particular memory location ADDAdd two numbers together SUBSubtract one number from another MULMultiply two numbers DIVDivide two numbers INCIncrement a number by adding 1 CMPCompare two numbers to see if they are equal JMPJump to a specific position in the instruction code Instructions are given to the processor in the form of a program … so it knows what circuits to use, in what order; and from where the data should be read or to where it should be stored.

7 COMP 4—Power Tools for the Mind 6 What’s in the box? More specifically: A program consists of a sequence of instructions. EACH instruction specifies both: –The operation to perform –The address of the data it will transform in that operation (if necessary). Instructions are stored and processed in machine language--also called microcode. Like everything else (e.g. like ASCII characters, pixels of an image, …) machine language consists solely of bit patterns.

8 COMP 4—Power Tools for the Mind 7 What’s in the box? Machine language or Machine Code a/k/a microcode –ML bit patterns are based directly on CPU’s instruction set (on its binary circuits). So who created them? –CPU chip: designed to recognize certain bit patterns as representing certain ML instructions, which correspond directly to certain available binary circuits. –Each ML instruction contains a fixed-length instruction code that: Identifies the operation to perform : op code Tells the CPU how to determine the operands For example: assume a 4-bit op-code + two 6-bit operands = one 16 bit instruction

9 COMP 4—Power Tools for the Mind 8 What’s in the box? E.G.: An ADD instruction in a 16-bit machine language: 0101 110011 111100 Op-code: Operands: (RAM or Register addresses) 0101 110011 111100 Before it can process a M.L. instruction, the CPU must fetch it from main memory. The CPU must keep track of its position in the instruction code. It uses a bookmark of sorts. The offset at which the next instruction starts is stored in a special register, called the Program Counter or Instruction Pointer. Important digression… –who knows if bits in memory are data or program … ? –increments to memory address of next instruction...

10 Putting it all together Processor: simple minded! repeats same steps over & over... 1. FETCH Fetches instruction (from memory) at address given by instruction pointer; copies it into CU storage register. 2. COPY & DECODE Copies op code into instruction register, operands into address registers. Interprets instruction. ALU is invoked to perform decoded operation for any ALU ops (enters Execution Cycle) 3. ADVANCE INSTRUCTION POINTER (counter) Pointer incremented; contains memory address of next instruction that will be fetched. Instruction Cycle: in the Control Unit MACHINE CYCLE : “ Instruction-Execution cycle” Processing of a single machine-level instruction (one Op Code) in a basic machine. 9

11 , A single Instruction cycle (Add) CONTROL UNIT Pointer Storage register Address reg 000001 PROCESSOR Instr. reg. Imprecise data representation, and a vast simplification-- but general concepts are correct. 2b Enter execute cycle ALU 3 000011 Advance pointerMEMORY 0101 1100 1111 1100 85 data shown in base 10 65 data shown in base 10 #000001 #000011 #110011 …. 10 #000010 0111 1110 #000100 #111100 …. 0101 110011 111100 Copy & Decode 2a 0101 110011 111100 Fetch 1

12 , Another single Inst Cycle (Divide) CONTROL UNIT Pointer Storage register Address reg 000011 PROCESSOR Instr. reg. Imprecise data representation, and a vast simplification-- but general concepts are correct. 2b Enter execute cycle ALU 3 000101 Advance pointer 11 0111 111001 111110 Copy & Decode 2a MEMORY 0101 1100 1111 1100 85 data shown in base 10 65 data shown in base 10 #000001 #000011 #110011 …. #000010 0111 1110 #000100 #111100 …. 0111 111001 111110 Fetch 1

13 –Execution cycles vary, depending on the op code. Eg: load register R03 with contents of memory cell 47: Just for culture: The CU causes the load to occur. CU activates ALU circuitry, which performs the actual Op Code. EG: MUL, ADD, DIV, … Execution Cycle: by the CU/ALU E.G: an arithmetic operation: ADD 1. LOAD Data copied from memory to ALU register. 2. ADD Data values are added in ALU adder circuitry. 3. COPY Result stored in ALU accumulator. 4. STORE Result copied from ALU to memory. 12

14 COMP 4—Power Tools for the Mind 13 What’s in the box?MEMORY PROCESSOR Execution cycle C.U. Enter execute cycle AL U Adder Register Accumulator 1 Data loaded to registers 85 65 Data values added 2 85 + 65 = 150 Result copied to Accumulator 3 150 Result stored in memory 150 4 0101 1100 1111 1100 85 data shown in base 10 65 data shown in base 10 #000001 #000011 #110011 …. #000010 0111 1110 #000100 #111100 …. #111110 ….

15 COMP 4—Power Tools for the Mind 14 What’s in the box? Boolean logic Boolean algebra: solve complex math problems by reducing them to questions answered by Y/N. –Logic gate: Mathematical operation that handles only data that is represented in one of only two states: TRUE/FALSE –Physical gate : electronic device that transforms binary input(s) to produce a single binary output, according to its transformation rule. –Many computer binary circuits employ complex Boolean logic to perform various tasks. Such circuits can test the truth of propositions by making comparisons, as well as carry out complex calculations. Gates: AND, OR, NOT

16 COMP 4—Power Tools for the Mind 15 What’s in the box? Truth tables NOT truth table 1 Input1 Output 0 1 –Engineers design binary computer circuits using gates based on truth tables. –Gates : building blocks of all digital devices! –Such circuits can carry out +, –, *, /, comparisons, and many complex operations. AND truth table 2 Inputs 1 Output 00 01 10 11 OR truth table 1 Output 00 01 10 11 2 Inputs 0 0 0 1 1010 0 1 1 1 Homework? Clean? STRICT Parents Homework? Clean? COOL Parents Stubborn child

17 COMP 4—Power Tools for the Mind 16 What’s in the box? Digital Logic Remember, the fundamental part of the digital computer is the switch. A switch simply lets current either flow completely or not at all (binary) : –Relay: mechanical switch –Vacuum tubes: electronic switch –Transistors: electronic switch –ICs: use many transistors on a circuit board Speed of computer determined by how fast a switch “switches”!

18 COMP 4—Power Tools for the Mind 17 What’s in the box? Transistor How does a transistor work? Transistor (Switch) Current trying to flow through Input Voltage If input voltage is low (binary 0) the switch opens and the current cannot pass through. If input voltage is high (binary 1), the switch closes and the current passes through freely.

19 COMP 4—Power Tools for the Mind 18 What’s in the box? Logic Gates Transistors are only switches. They simply determine whether or not current can pass through a wire. Transistors are used to create logic gates. These gates perform logic operations on the input voltages and give the result in form of an output voltage. Let’s construct a few simple gates to see how this works…

20 COMP 4—Power Tools for the Mind 19 What’s in the box? NOT gate Input Voltage Steady current (high) Ground (low) Output Voltage When input is low, then switch is open, and high current flows to output. When input is high, then switch is closed, and the current is grounded (instead of passing into output), therefore the output voltage is low. logical operator: NOT Low input becomes high output. High input become low output. INOUT 01 10

21 COMP 4—Power Tools for the Mind 20 What’s in the box? NAND gate (NOT AND) Input Voltage 2 Steady current (high) Ground (low) Output Voltage Input Voltage 1 If both inputs are High, then current passes through, and output is Low. If either input is Low, switch closes, and output is High. IN1IN2OUT 001 011 101 110

22 COMP 4—Power Tools for the Mind 21 What’s in the box? NOR gate (NOT OR) Input Voltage 2 Steady current (high) Ground (low) Output Voltage Input Voltage 1 Ground (low) If both inputs are Low, then neither switch is closed, and output is High. If either input is High, a switch opens, and output is Low. IN1IN2OUT 001 010 100 110

23 COMP 4—Power Tools for the Mind 22 What’s in the box? Digital Logic We have only created NOT, NAND, and NOR. We wanted ANDs and ORs as well… Just feed output of NAND and NOR into NOT gate. Actually, all boolean logic expressions can be constructed just from NAND or from NOR – complete! Demo: 4-bit half adder

24 How can binary circuits ADD? 10 1 0 + You will not have to reconstruct diagrams! But you should know how to evaluate Boolean ops. Output Bit Carry Bit ORAND NOT 1 0 0 1 1 16

25 How can binary circuits ADD? 01 1 1 + Output Bit Carry Bit ORAND NOT 1 1 1 0 0 17

26 COMP 4—Power Tools for the Mind 25 What’s in the box? What about other operations? Subtraction –Addition using two’s complement representation Multiplication –Repeated addition (with bit shifting) Division –Repeated subtraction (with bit shifting) Basically, a computer just adds.

27 COMP 4—Power Tools for the Mind 26 What’s in the box? Important digression! –What kind of code do programmers use? Translator (Compiler) High-level language (source code) Machine language (object code) e.g.: Turing Source Code Machine Code or Object code Translation or Compilation –What is the only kind of code a CPU understands? –So, what has to occur before the CPU can execute a source-code program?

28 20 An Analogy Carbon-based unit JOHNNY, age 4 (obeys orders to transform raw material into tasty sandwiches.) Basic Instruction Set: Simple commands he can do: Go, Bring, Unwrap, … Child brain, hands, skills he uses. Grandpa’s commands: “Please make 2 p&j sandw’s on rye!” Mom: Grandpa language to Child Talk Child-talk instructions to Johnny that he understands: GO to pantry. BRING bread & PB to kitchen. UNWRAP bread. PULL OUT 4 slices ….

29 Basic Instruction Set : Primitive commands (log’l) it can do Computer circuits (phy’l) it uses Source code Answer := Num1 + Num2 Translator prog: Source to object Object code (Low-level ML) so CPU can understand it: LOAD M012 R07 LOAD M013 R08 ADD R07 R08 R02 STORE R09 M033 Silicon-based unit CPU (obeys orders to transform raw data into meaningful info.) as binary codes STO; ADD; SUB; MUL; DIV; INC; CMP; JMP… Johnny Grandpa’s command Mom translates Child talk what Johnny can do 21 0010 00001100 0111 0010 00001101 1000 0101 0111 1000 0010 0011 0010 00100001


Download ppt "COMP 4—Power Tools for the Mind 1 What’s in the box? Computer architecture, part 1: What we’ll cover for this lecture topic: –What is a CPU? –How is a."

Similar presentations


Ads by Google