540 likes | 725 Views
22342 - Computer Organization & Assembly Language. Chapter 4:. The Processor: Datapath & Control. Stored Program Architecture. Instruction Cycle Fetch an instruction from memory Decode the instruction Get the operands Execute the instruction Where is the next instruction?
E N D
22342 - Computer Organization & Assembly Language Chapter 4: The Processor:Datapath & Control IT Students
Stored Program Architecture • Instruction Cycle • Fetch an instruction from memory • Decode the instruction • Get the operands • Execute the instruction • Where is the next instruction? Program Counter (PC) Instruction Pointer (IP) • Where is the operand? Memory Instructions (Program) Opcode Operands Operands (Data) Binary Operand PC IT Students
ALU CPU • Datapath • Control Unit CU Register File IT Students
General-Purpose Register Organization R1 R2 R3 R4 R5 R6 R7 MUX MUX ASEL BSEL 3 x 8Decoder A B OPR ALU DSEL IT Students
R1 R2 R3 R4 R5 R6 R7 MUX MUX ASEL BSEL 3 x 8Decoder A B OPR ALU DSEL General-Purpose Register Organization Examples: IT Students
General-Purpose Register Organization Memory Instructions (Program) Trivial view of Opcode & Operands 00101 010 011 001 00 Operands (Data) 0000 0000 0000 0000 Examples: IT Students
Memory Interface • Address / Data Buses • Read / Write Control • Bidirectional /UnidirectionalData Bus Memory Memory 22 Byte│Byte│Byte│Byte 26 Byte│Byte│Byte│Byte Addr Read Data Write Data Data IT Students
Building a Datapath Write a program & compile it. Where do you want to put it? Where is the first instruction? What comes out of memory? Where to perform operation? Where are the operands? Who well tell us which reg? Where to store result? Can we save this reg to mem? • Datapath Elements Opcode │ Operands Register File 32 32 32 PC SelA Data A Addr Data B SelB Data Sel C LD Instruction Memory Data C ALU IT Students
Building a Datapath • Datapath Elements At what address? Register File PC SelA Data A Addr Data Memory Data B SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU IT Students
Building a Datapath How can we read it back? Register File PC SelA Data A Addr Data Memory Data B SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU IT Students
Building a Datapath Finished executing instruction. Where is the next instruction? Why +4? 4 Register File PC SelA Data A Addr Data Memory MUX Data B SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU Adder IT Students
Building a Datapath How can we add “immediate”? What if it is 8-bit negative? 4 Opcode │ Operand │ immediate Register File PC SelA Data A Addr Data Memory MUX Data B SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU Adder Sign Extend IT Students
Building a Datapath What about “JMP RelDisp”? It can be positive or negative! 4 Opcode │ Relative Displacement Register File PC SelA Data A Addr Data Memory MUX Data B MUX SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU Adder Sign Extend IT Students
Building a Datapath 4 Shift Left 2 Register File PC SelA Data A Addr Data Memory MUX Data B MUX SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU Adder Adder Sign Extend IT Students
Building a Datapath MUX Why the shift? 4 Shift Left 2 Register File PC SelA Data A Addr Data Memory MUX Data B MUX SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU Adder Adder Sign Extend IT Students
Building a Datapath MUX 4 Shift Left 2 Why not use ALU instead of another adder? Register File PC SelA Data A Addr Data Memory MUX Data B MUX SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU Adder Adder Sign Extend IT Students
Adding Control Signals to the Datapath 0 MUX 1 4 Shift Left 2 Register File PC SelA Data A Addr Data Memory 1 MUX 0 Data B 0 MUX 1 SelB Addr Data Data Sel C LD Instruction Memory Opcodeetc Data Data C ALU Adder Adder Control Unit Sign Extend Cy, Z, etc IT Students
Adding Control Signals to the Datapath 0 MUX 1 4 Shift Left 2 Register File PC SelA Data A Addr Data Memory 1 MUX 0 Data B 0 MUX 1 SelB Addr Data Data Sel C LD Instruction Memory Data Data C ALU Adder Adder Control Unit Sign Extend IT Students
A Simple Implementation Scheme • ALU Control 32 32 4 ALU Cntrl Cy Z 32 Cy = 1 Carry from last adder Z = 1 The result = 0 slt R1, R2, R3 ALU IT Students
A Simple Implementation Scheme • Instruction Format • Arithmetic/Logic Instruction Opcode Operand(s), Address, Code 6 5 5 5 5 6 Rd = RsFunctRt 0 000000 00011 Rs Rt 00111 Rd 00101 Shift 00000 100000 Funct Register File SelA Data A Data B SelB Sel C LD Data C Example: IT Students
A Simple Implementation Scheme • Instruction Format • Load Immediate Instruction Opcode Operand(s), Address, Code 6 5 5 16 13 001101 00000 0 Rt 00001 0000 0000 0000 1100 Immediate Rt = Value 16 bits (can be positive or negative) Example: R1 = 12 IT Students
A Simple Implementation Scheme • Instruction Format • Load Memory Instruction Opcode Operand(s), Address, Code 6 5 5 16 100011 35 00100 Rs Rt 00110 1111 1111 1111 1111 Address Rt = M [Rs + Addr] 32 bits 16 bits (can be positive or negative) Example: R6 = M [R4– 1 ] IT Students
A Simple Implementation Scheme • Instruction Format • Store Memory Instruction Opcode Operand(s), Address, Code 6 5 5 16 101011 43 00111 Rs Rt 01001 1111 1111 1111 1110 Address M [Rs + Addr] = Rt Example: M [R7– 2 ] = R9 IT Students
A Simple Implementation Scheme • Instruction Format • JE Operation Instruction Opcode Operand(s), Address, Code 6 5 5 16 000100 4 00001 Rs Rt 00100 1111 1111 1111 1111 Offset If Rs = Rt then PC = PC + 4*Addr PC is already incremented Example: IT Students
Final Datapath Design 0 MUX 1 4 Shift Left 2 Register File Rs PC SelA Data A Rt Addr Data Memory 1 MUX 0 Data B 0 MUX 1 SelB Addr Data Data Rt MUX Rd Sel C LD Instruction Memory Data Data C ALU Adder Adder Offset, Addr, Immediate Sign Extend IT Students
Program Setup • Write a Program • Assemble it • Store it in Memory Example: Memory 001101 000000 000100 00000 00001 00001 00001 00001 00001 0000 0000 0000 1010 1111 1111 1111 1111 00001 00000 100000 0 4 8 3 4 0 1 0 0 0 A 0 0 2 1 0 8 2 0 1 0 2 1 F F F F IT Students
Datapath Operation CLK PC I-Mem • Fetch Instruction • Decode Instruction • Get Operands • Execute it 0 ƮM Adder MUX PC Adder 0 1 ƮAdder RegASel 2 (Add) 10 0 10 10 4 RegCSel Reg CLD ALU MUX ALU Ctrl Mem MUX Data A ƮReg Sign Ext 3401000A (LDI R1, 10) ALU ƮALU Data C Rs Rt Immediate ƮReg 13 0 1 10 IT Students
Datapath Operation CLK PC I-Mem • How Fast Can the Clock Be? 0 ƮM Adder MUX Ʈclk PC Adder 0 1 RegASel 4 2 (Add) 10 0 10 10 RegCSel Reg CLD ALU MUX ALU Ctrl Mem MUX Data A ƮReg Sign Ext 3401000A (LDI R1, 10) ALU ƮALU Data C ƮReg IT Students
Datapath Operation CLK PC I-Mem • Fetch Instruction • Decode Instruction • Get Operands • Execute it 0 4 Adder MUX PC Adder 4 1 1 RegASel 0 8 2 (Add) 10 10 20 20 RegCSel 1 Reg CLD ALU MUX ALU Ctrl 2 Mem MUX Data A 0 Data B 00210820(Add R1,R1,R1) ALU 10 Data C 10 Rs Rt Rd Shift Funct IT Students 0 1 1 1 0 32
Datapath Operation CLK PC I-Mem • Fetch Instruction • Decode Instruction • Get Operands • Execute it 4 8 PC Adder 8 1 1 PC Adder 2 Adder MUX 12 8 6 (Sub) 20 20 0 RegASel 1 RegCSel 1 Reg CLD ALU MUX ALU Ctrl 2 Data A 10 Data B 10 1021FFFF (JE R1,R1,-1) ALU 20 Rs Rt Offset IT Students 4 1 1 – 1
Datapath Operation CLK PC I-Mem • How Fast Can the Clock Be? 4 8 ƮM PC Adder 8 1 1 PC Adder 2 Adder MUX 12 8 6 (Sub) 20 20 0 RegASel 1 RegCSel 1 Reg CLD ALU MUX ALU Ctrl 2 Data A 10 ƮReg Data B 10 1021FFFF (JE R1,R1,-1) ALU 20 ƮALU IT Students
Datapath Operation CLK PC I-Mem • How Fast Can the Clock Be? 4 8 ƮM PC Adder 8 Ʈclk ƮAdder 1 1 PC Adder 2 ƮAdder Adder MUX 12 8 6 (Sub) 20 20 0 RegASel 1 RegCSel 1 Reg CLD ALU MUX ALU Ctrl 2 Data A 10 ƮReg Data B 10 1021FFFF (JE R1,R1,-1) ALU 20 ƮALU IT Students
Single-Cycle Implementation CLK PC I-Mem • Fetch Instruction • Decode Instruction • Get Operands • Execute it i RegASel 3 RegCSel 4 Reg CLD 2 (Add) 7 d d+7 v v ALU MUX ALU Ctrl Mem MUX Data A Sign Ext ALU D-Mem 8C640007(LD R4,[R3+7]) Data C Rs Rt Address 35 3 4 7 IT Students
Single-Cycle Implementation CLK PC I-Mem • Clock Speed? i ƮM RegASel Ʈclk 3 RegCSel 4 Reg CLD 2 (Add) 7 d d+7 v v ALU MUX ALU Ctrl Mem MUX Data A ƮReg Sign Ext ALU ƮALU D-Mem ƮM 8C640007(LD R4,[R3+7]) Data C ƮReg IT Students
Single-Cycle Implementation Example: ƮM= 200 picoseconds ƮALU = 100 picoseconds ƮAdder = 100 picoseconds ƮReg= 50 picoseconds Fastest Clock? Load Immediate/ALU: Ʈclk>ƮM+2ƮReg+ ƮALU Load Memory: Ʈclk>2ƮM+2ƮReg+ ƮALU Store Memory: Ʈclk>2ƮM+ƮReg+ ƮALU Conditional Jump: Ʈclk>Max ƮM+ƮReg+ƮALU 2ƮAdder Ʈclk=ps GHz IT Students
Multicycle Implementation • Instructions take different number of clock cycles • Functional units can be shared within the execution of a single instruction Register File SelA Data A X IR Data B SelB PC Memory Result Addr Sel C LD Y MDR Data C ALU Data Data IT Students
Multicycle Implementation • Some registers are not visible to the programmer IR X Register File PC Result SelA Data A Y 4 Data B SelB Memory MDR Addr Sel C LD Data C Sign Extend ALU Shift Left 2 Data Data Exercise: Can you do all the previous instruction here? IT Students
Multicycle Implementation • Some registers are not visible to the programmer 0 1 2 3 0 1 IR X 0 1 0 1 0 1 0 1 Memory Register File Result PC SelA Data A Y 4 Data B SelB MDR Addr Sel C LD Data Data C Sign Extend ALU Shift Left 2 Data IT Students
Multicycle Datapath Operation 1 CLK PC • Fetch Instruction 0 MemRd Ʈclk IRLD IR Mem Out 4 ƮM X MUX Y MUX 0 ALU Ctrl 2 (Add) ALU ƮALU PCMUX PCLD 3401000A IT Students
Multicycle Datapath Operation 2 CLK PC • Fetch Instruction • Decode Instruction • Get Operands 0 4 MemRd IRLD 0 IR 3401000A (LDI R1, 10) Mem Out 10 0 Ʈclk RegASel XLD X Data A ƮReg Sign Ext Rs Rt Immediate 13 0 1 10 IT Students
Multicycle Datapath Operation 3 CLK PC • Fetch Instruction • Decode Instruction • Get Operands • Execute it 4 IR 3401000A (LDI R1, 10) XLD X 0 X MUX 10 Y MUX 2 ALU Ctrl 2 (Add) Ʈclk ResultLD Result ALU ƮALU Rs Rt Immediate 13 0 1 10 IT Students
Multicycle Datapath Operation 4 CLK PC • Fetch Instruction • Decode Instruction • Get Operands • Execute it 4 IR 3401000A (LDI R1, 10) ResultLD Result 10 RegCSel 1 C MUX Reg CLD Ʈclk ƮReg Ʈclk Rs Rt Immediate 13 0 1 10 IT Students
Multicycle Implementation Example: ƮM= 200 picoseconds ƮALU = 100 picoseconds ƮAdder = 100 picoseconds ƮReg= 50 picoseconds Fastest Clock? Load Immediate/ALU: 4 Clocks Load Memory: 5 Clocks Store Memory: 4 Clocks Conditional Jump: 3 Clocks Ʈclk=ps GHz IT Students
Control Implementation Datapath Control Signals: ALU Operation, MUX Selection,Memory Rd/Wr, etc Control Unit CU Data Processing Unit DPU or Datapath • • • • • • Datapath Status Signals: IR Fields, ALU Flags IT Students
Control Implementation • Hardwired • Standard Logic Components • Fast • Not Flexible, i.e. Difficult to Change Control Operation • Microprogrammed • Memory-Based • Speed Function of Memory (slower than hardwired) • Flexible Design IT Students
Control Implementation • Hardwired • FiniteStateMachine Control Unit CombinationalControlLogic Datapath Control Outputs • • • • • • • • • State Register Datapath Control inputs • • • IT Students
Microprogrammed Control Implementation • Each Linein the Micro-ProgramExecutesMicro-Operations(in 1 Clock) • Fetch,Decode,ExecuteCycle Control Unit Microprogram Counter Microprogram Memory (Microstore) ALU Operation, MUX Selection,Memory Rd/Wr, etc IT Students
Microprogram Control Unit Datapath Control Signals: IT Students
Microprogram Control Unit Opcode IR MAP Funct Adder MUX ConditionSelect ZCyetc μPC 1 μProgram Memory C19 C0 IT Students
Microprogram Control Unit • Fetch Instruction IR M[PC] PC PC + 4 μPC M0 S1 S0 C19C18C17C16C15C14C13C12C11C10C9 C8 C7 C6 C5C4 C3 C2 C1 C0 IT Students