SlideShare a Scribd company logo
1 of 20
Download to read offline
Central Processing Unit (CPU)
• CPU is the heart and brain
• It interprets and executes machine level instructions
• Controls data transfer from/to Main Memory (MM) and CPU
• Detects any errors
• In the following lectures, we will learn:
• Instruction representation
• Data transfer mechanism between MM and CPU
• The internal functional units of two different CPU architectures
• How these units are interconnected
• How a processor executes instructions
Instruction Representation
• CPU operation is determined by the instruction it executes
• Collection of these instructions that a CPU can execute forms its Instruction
Set
• An instruction is represented as sequence of bits, for example:
• Instruction is divided into fields
• Opcode indicates the operation to be performed, eg., 92 above indicates a
copy operation – we need two operands – one source and other destination
• Opcode represents
• nature of operands (data or address), operand 1 is address and operand 2 is data
• mode (register or memory), operand 1 is memory, and operand 2 is immediate data
1001 0010 0000 0011 1011 1011 1000 0001
9 2 0 3 B B 8 1
Opcode Operand1 Operand2
Basic Instruction Types
Not all instructions require two operands
• 3-address instructions
Operation Source1, Source2, Destination
e.g. Add A, B, C ; C = A + B
• 2-address instructions
Operation Source, Destination
e.g. Move B, C ; C = B
Add A, C ; C = C + A
Here Source2 is implicitly the destination
• 1-address instructions
e.g. Load A
Store C
• 0-address instructions
e.g. Stop
Simple Instruction Set
Assume we have a processor whose Instruction Set consists of four machine
language instructions
• Move from a memory location to a data register in CPU
• Move from a data register in CPU to a memory location
• Add the contents of a memory location to a data register
• Stop
Suppose our program for Z = X + Y looks like:
Move X, D0
Add Y, D0
Move D0, Z
Stop
This program is coded into machine instruction and suppose is loaded into memory
starting at location $0000 0000
$0000 0000
move
add
move
stop
• How does the CPU know which instruction to execute?
• There is a dedicated register in CPU called Program Counter (PC)
that points to the memory location where next instruction is stored
Therefore, at start PC = $0000 0000
• Instruction is in Main Memory – it is to be transferred
(fetched) to CPU to be executed
• CPU has an Instruction Register (IR) that holds the instruction
• What kind of instruction is to be executed?
• CPU has its own Instruction Interpreter (Decoder)
• Followed by Instruction execution
• Next instruction follows. PC is incremented by length of
instruction just completed
Mechanism of Transferring Data from MM to CPU
CPU has an external bus that connects it to the Memory and I/O devices.
The data lines are connected to the processor via the Memory Data Register
(MDR)
The address lines are connected to the processor via the Memory Address
Register (MAR)
• Memory address from where the instruction/data is to be accessed is copied into
MAR
• Contents of MAR are loaded onto address bus
• Corresponding memory location accessed
• Contents of this location put onto data bus
• Data on data bus loaded into MDR
MAR
MDR
CPU MM
Address bus
Data bus
Control bus
R/W
CISC and RISC
Reduced Instruction Set Computers (RISC)
• Performs simple instructions that require small number of basic steps to execute
(smaller S)
• Requires large number of instructions to perform a given task – large code size
(larger N)
• more RAM is needed to store the assembly level instructions
• Advantage: Low cycles per second – each instruction is executed faster in one clock
cycle (smaller R)
• Example: Advanced RISC Machines (ARM) processor
Complex Instruction Set Computers (CISC)
• Complex instructions that involve large number of steps (larger S)
• Fewer instructions needed (smaller N) – small code size
• Commands represent more closely to high-level languages
• Less RAM required to store the program
• Disadvantage: High cycles per second
• Example: Motorola 68000 processor, Intel x86
General Purpose Register (GPR)Architecture
Its functional units are:
Data Registers: D0, D1, D2,..., D7 for arithmetic operations – holds any kind of data
Address Registers: A0, A1, A2,..., A7 serve as pointers to memory addresses
Working Registers: several such registers – serve as scratch pads for CPU
Program Counter (PC) holding the address in memory of the next instruction to be
executed. After an instruction is fetched from memory, the PC is automatically
incremented to hold the address of, or point to, the next instruction to be executed.
Instruction Register (IR) holds the most recently read instruction from memory while it is
being decoded by the Instruction Interpreter.
Memory Address Register (MAR) holds the address of the next location to be accessed in
memory.
Memory Buffer Register (MBR or MDR) holds the data just read from memory, or the
data which is about to be written to memory. Buffer is referring to temporarily holding
data.
Status Register (SR) to record status information
GPR CPU
MBR
MAR
PC
Increment
Interpreter
IR
Register
File
0
1
2
3
ALU
CPU Memory
Data bus
Address bus
Memory
Control
16 bit
8 bit
Program Execution
Fetch Cycle:
• Processor fetches one instruction at a time from successive memory locations until
a branch/jump occurs.
• Instructions are located in the memory location pointed to by the PC
• Instruction is loaded into the IR
• Increment the contents of the PC by the size of an instruction
Decode Cycle:
• Instruction is decoded/interpreted, opcode will provide the type of operation to be
performed, the nature and mode of the operands
• Decoder and control logic unit is responsible to select the registers involved and
direct the data transfer.
Execute Cycle:
• Carry out the actions specified by the instruction in the IR
Execution for add D1,D2 in a GPR processor
MAR  PC
MDR  M[MAR]
IR  MDR
D2  D1 + D2
PC  PC + 2
Fetch
Decode
Execute
GPR CPU
Type equation here.
MBR
MAR
PC
Increment
Interpreter
IR
Register
File
0
1
2
3
ALU
CPU Memory
Data bus
Address bus
Memory
Control
16 bit
8 bit
Execution for add X,D0 in a GPR processor
MAR  PC
MDR  M[MAR]
IR  MDR
MAR  IR (X)
PC  PC + 2
Fetch
Decode
Execute
MDR  M[MAR]
D0  MDR + D0
Address X extracted from IR
Contents of Address X
transferred to MDR
Contents of Address X
added to D0
GPR CPU
Type equation here.
MBR
MAR
PC
Increment
Interpreter
IR
Register
File
0
1
2
3
ALU
CPU Memory
Data bus
Address bus
Memory
Control
16 bit
8 bit
Instruction Execution Time
Clock Cycles (P) – regular time intervals
defined by the CPU clock
Clock Rate, R = 1/P cycles per second (Hz)
500 MHz => P = 2ns
1.25 GHz => P = 0.8ns
For each instruction:
Fetch: Total 12 clock cycles
MAR  PC 1
MDR  M[MAR] 10
IR  MBR 1
Decode: 2 clock cycles
Execute: depends on instruction
Micro Step Number of Clock Cycles
Register Transfer 1
Decoding 2
Add 2
Multiply 5
Memory Access 10
Accumulator (Acc)Architecture
• Its functional units are same as GPR architecture, except there is only ONE
register – accumulator (Acc) – instead of the Register File
Ex: Z = X + Y
Move contents of location X to Acc
Add contents of location Y to Acc
Move from Acc to location Z
Stop
• All operations and data movements are on this single register
• Most of the instructions in the instruction set require only one Operand
• Destination and Source are implicitly Acc
• Leads to shorter instructions but program may be slower to execute since
there are more moves to memory for intermediate results (to free Acc)
• May lead to inefficiency
Accumulator Architecture CPU
MBR
MAR
PC
Increment
Interpreter
IR
Acc
ALU
CPU Memory
Data bus
Address bus
Memory
Control
16 bit
10 bit
Execution for Add Y in an Acc Architecture
MAR  PC
MDR  M[MAR]
IR  MDR
MAR  IR (X)
PC  PC + 2
Fetch
Decode
Execute
MDR  M[MAR]
Acc  MDR + Acc
Address X extracted from IR
Contents of Address X
transferred to MDR
Contents of Address X
added to Accumulator
GPR vs Acc
Let the following instructions be allowed:
For GPR machine (with 4 data reg)
• Move 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑗
Move 𝑅𝑖, M[X] ; 𝑅𝑖 ← M[X]
Move M[X], 𝑅𝑖 ; M[X] ← 𝑅𝑖
• Add 𝑅𝑖, M[X] ; 𝑅𝑖 ← 𝑅𝑖 + M[X]
Add 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑖 + 𝑅𝑗
• Sub 𝑅𝑖, M[X] ; 𝑅𝑖 ← 𝑅𝑖 − M[X]
Sub 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑖 − 𝑅𝑗
• Mult 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑖 ∗ 𝑅𝑗
• Stop
For Accumulator machine
• Add x ; 𝐴𝑐𝑐 ← 𝐴𝑐𝑐 + M[X]
• Sub x ; 𝐴𝑐𝑐 ← 𝐴𝑐𝑐 − M[X]
• Mult x ; 𝐴𝑐𝑐 ← 𝐴𝑐𝑐 ∗ M[X]
• LD x ; 𝐴𝑐𝑐 ← M[X]
• ST x ; M[X] ← 𝐴𝑐𝑐
• Stop
Note that M[X] = x
GPR vs Acc
Assembly Program for a <- (x + y) * (x – y)
For GPR machine (with 4 data reg)
Move 𝐷0, 𝑋
Add 𝐷0, 𝑌
Move 𝐷1, 𝑋
Sub 𝐷1, 𝑌
Mult 𝐷0, 𝐷1
Move 𝐴, 𝐷0
Stop
For Accumulator machine
LD X
ADD Y
ST C
LD X
SUB Y
MULT C
ST A
STOP

More Related Content

Similar to CPU Instruction Execution

ICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptxICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptxSirRafiLectures
 
PattPatelCh04.ppt
PattPatelCh04.pptPattPatelCh04.ppt
PattPatelCh04.pptDipakShow2
 
Unit 1 computer architecture (1)
Unit 1   computer architecture (1)Unit 1   computer architecture (1)
Unit 1 computer architecture (1)DevaKumari Vijay
 
The Basic Organization of Computers
The Basic Organization of ComputersThe Basic Organization of Computers
The Basic Organization of ComputersTallat Satti
 
F453 computer science fde cycle
F453 computer science fde cycleF453 computer science fde cycle
F453 computer science fde cycleMark Gibbs
 
introduction to embedded systems part 1
introduction to embedded systems part 1introduction to embedded systems part 1
introduction to embedded systems part 1Hatem Abd El-Salam
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorDarling Jemima
 
Processor Management
Processor ManagementProcessor Management
Processor ManagementSumit kumar
 
Computer Organization & Architecture (COA) Unit 2
Computer Organization & Architecture (COA) Unit 2Computer Organization & Architecture (COA) Unit 2
Computer Organization & Architecture (COA) Unit 2parthivrathodlits
 
Arm cortex-m4 programmer model
Arm cortex-m4 programmer modelArm cortex-m4 programmer model
Arm cortex-m4 programmer modelMohammed Gomaa
 
Lecture1 - Computer Architecture
Lecture1 - Computer ArchitectureLecture1 - Computer Architecture
Lecture1 - Computer ArchitectureVolodymyr Ushenko
 
Computer System Architecture - Computer System Architecture
Computer System Architecture - Computer System ArchitectureComputer System Architecture - Computer System Architecture
Computer System Architecture - Computer System Architecturessusera1e32a1
 

Similar to CPU Instruction Execution (20)

ICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptxICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptx
 
Central processing unit i
Central processing unit iCentral processing unit i
Central processing unit i
 
PattPatelCh04.ppt
PattPatelCh04.pptPattPatelCh04.ppt
PattPatelCh04.ppt
 
Chap 3 CA.pptx
Chap 3 CA.pptxChap 3 CA.pptx
Chap 3 CA.pptx
 
Cpu & its execution of instruction
Cpu & its execution of instructionCpu & its execution of instruction
Cpu & its execution of instruction
 
Unit 1 computer architecture (1)
Unit 1   computer architecture (1)Unit 1   computer architecture (1)
Unit 1 computer architecture (1)
 
The Basic Organization of Computers
The Basic Organization of ComputersThe Basic Organization of Computers
The Basic Organization of Computers
 
Control unit
Control unitControl unit
Control unit
 
F453 computer science fde cycle
F453 computer science fde cycleF453 computer science fde cycle
F453 computer science fde cycle
 
introduction to embedded systems part 1
introduction to embedded systems part 1introduction to embedded systems part 1
introduction to embedded systems part 1
 
Dsp ajal
Dsp  ajalDsp  ajal
Dsp ajal
 
16 control unit
16 control unit16 control unit
16 control unit
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM Processor
 
Processor Management
Processor ManagementProcessor Management
Processor Management
 
CPU Architecture
CPU ArchitectureCPU Architecture
CPU Architecture
 
Instruction codes
Instruction codesInstruction codes
Instruction codes
 
Computer Organization & Architecture (COA) Unit 2
Computer Organization & Architecture (COA) Unit 2Computer Organization & Architecture (COA) Unit 2
Computer Organization & Architecture (COA) Unit 2
 
Arm cortex-m4 programmer model
Arm cortex-m4 programmer modelArm cortex-m4 programmer model
Arm cortex-m4 programmer model
 
Lecture1 - Computer Architecture
Lecture1 - Computer ArchitectureLecture1 - Computer Architecture
Lecture1 - Computer Architecture
 
Computer System Architecture - Computer System Architecture
Computer System Architecture - Computer System ArchitectureComputer System Architecture - Computer System Architecture
Computer System Architecture - Computer System Architecture
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 

CPU Instruction Execution

  • 1. Central Processing Unit (CPU) • CPU is the heart and brain • It interprets and executes machine level instructions • Controls data transfer from/to Main Memory (MM) and CPU • Detects any errors • In the following lectures, we will learn: • Instruction representation • Data transfer mechanism between MM and CPU • The internal functional units of two different CPU architectures • How these units are interconnected • How a processor executes instructions
  • 2. Instruction Representation • CPU operation is determined by the instruction it executes • Collection of these instructions that a CPU can execute forms its Instruction Set • An instruction is represented as sequence of bits, for example: • Instruction is divided into fields • Opcode indicates the operation to be performed, eg., 92 above indicates a copy operation – we need two operands – one source and other destination • Opcode represents • nature of operands (data or address), operand 1 is address and operand 2 is data • mode (register or memory), operand 1 is memory, and operand 2 is immediate data 1001 0010 0000 0011 1011 1011 1000 0001 9 2 0 3 B B 8 1 Opcode Operand1 Operand2
  • 3. Basic Instruction Types Not all instructions require two operands • 3-address instructions Operation Source1, Source2, Destination e.g. Add A, B, C ; C = A + B • 2-address instructions Operation Source, Destination e.g. Move B, C ; C = B Add A, C ; C = C + A Here Source2 is implicitly the destination • 1-address instructions e.g. Load A Store C • 0-address instructions e.g. Stop
  • 4. Simple Instruction Set Assume we have a processor whose Instruction Set consists of four machine language instructions • Move from a memory location to a data register in CPU • Move from a data register in CPU to a memory location • Add the contents of a memory location to a data register • Stop Suppose our program for Z = X + Y looks like: Move X, D0 Add Y, D0 Move D0, Z Stop This program is coded into machine instruction and suppose is loaded into memory starting at location $0000 0000 $0000 0000 move add move stop
  • 5. • How does the CPU know which instruction to execute? • There is a dedicated register in CPU called Program Counter (PC) that points to the memory location where next instruction is stored Therefore, at start PC = $0000 0000 • Instruction is in Main Memory – it is to be transferred (fetched) to CPU to be executed • CPU has an Instruction Register (IR) that holds the instruction • What kind of instruction is to be executed? • CPU has its own Instruction Interpreter (Decoder) • Followed by Instruction execution • Next instruction follows. PC is incremented by length of instruction just completed
  • 6. Mechanism of Transferring Data from MM to CPU CPU has an external bus that connects it to the Memory and I/O devices. The data lines are connected to the processor via the Memory Data Register (MDR) The address lines are connected to the processor via the Memory Address Register (MAR) • Memory address from where the instruction/data is to be accessed is copied into MAR • Contents of MAR are loaded onto address bus • Corresponding memory location accessed • Contents of this location put onto data bus • Data on data bus loaded into MDR MAR MDR CPU MM Address bus Data bus Control bus R/W
  • 7. CISC and RISC Reduced Instruction Set Computers (RISC) • Performs simple instructions that require small number of basic steps to execute (smaller S) • Requires large number of instructions to perform a given task – large code size (larger N) • more RAM is needed to store the assembly level instructions • Advantage: Low cycles per second – each instruction is executed faster in one clock cycle (smaller R) • Example: Advanced RISC Machines (ARM) processor Complex Instruction Set Computers (CISC) • Complex instructions that involve large number of steps (larger S) • Fewer instructions needed (smaller N) – small code size • Commands represent more closely to high-level languages • Less RAM required to store the program • Disadvantage: High cycles per second • Example: Motorola 68000 processor, Intel x86
  • 8. General Purpose Register (GPR)Architecture Its functional units are: Data Registers: D0, D1, D2,..., D7 for arithmetic operations – holds any kind of data Address Registers: A0, A1, A2,..., A7 serve as pointers to memory addresses Working Registers: several such registers – serve as scratch pads for CPU Program Counter (PC) holding the address in memory of the next instruction to be executed. After an instruction is fetched from memory, the PC is automatically incremented to hold the address of, or point to, the next instruction to be executed. Instruction Register (IR) holds the most recently read instruction from memory while it is being decoded by the Instruction Interpreter. Memory Address Register (MAR) holds the address of the next location to be accessed in memory. Memory Buffer Register (MBR or MDR) holds the data just read from memory, or the data which is about to be written to memory. Buffer is referring to temporarily holding data. Status Register (SR) to record status information
  • 10. Program Execution Fetch Cycle: • Processor fetches one instruction at a time from successive memory locations until a branch/jump occurs. • Instructions are located in the memory location pointed to by the PC • Instruction is loaded into the IR • Increment the contents of the PC by the size of an instruction Decode Cycle: • Instruction is decoded/interpreted, opcode will provide the type of operation to be performed, the nature and mode of the operands • Decoder and control logic unit is responsible to select the registers involved and direct the data transfer. Execute Cycle: • Carry out the actions specified by the instruction in the IR
  • 11. Execution for add D1,D2 in a GPR processor MAR  PC MDR  M[MAR] IR  MDR D2  D1 + D2 PC  PC + 2 Fetch Decode Execute
  • 12. GPR CPU Type equation here. MBR MAR PC Increment Interpreter IR Register File 0 1 2 3 ALU CPU Memory Data bus Address bus Memory Control 16 bit 8 bit
  • 13. Execution for add X,D0 in a GPR processor MAR  PC MDR  M[MAR] IR  MDR MAR  IR (X) PC  PC + 2 Fetch Decode Execute MDR  M[MAR] D0  MDR + D0 Address X extracted from IR Contents of Address X transferred to MDR Contents of Address X added to D0
  • 14. GPR CPU Type equation here. MBR MAR PC Increment Interpreter IR Register File 0 1 2 3 ALU CPU Memory Data bus Address bus Memory Control 16 bit 8 bit
  • 15. Instruction Execution Time Clock Cycles (P) – regular time intervals defined by the CPU clock Clock Rate, R = 1/P cycles per second (Hz) 500 MHz => P = 2ns 1.25 GHz => P = 0.8ns For each instruction: Fetch: Total 12 clock cycles MAR  PC 1 MDR  M[MAR] 10 IR  MBR 1 Decode: 2 clock cycles Execute: depends on instruction Micro Step Number of Clock Cycles Register Transfer 1 Decoding 2 Add 2 Multiply 5 Memory Access 10
  • 16. Accumulator (Acc)Architecture • Its functional units are same as GPR architecture, except there is only ONE register – accumulator (Acc) – instead of the Register File Ex: Z = X + Y Move contents of location X to Acc Add contents of location Y to Acc Move from Acc to location Z Stop • All operations and data movements are on this single register • Most of the instructions in the instruction set require only one Operand • Destination and Source are implicitly Acc • Leads to shorter instructions but program may be slower to execute since there are more moves to memory for intermediate results (to free Acc) • May lead to inefficiency
  • 17. Accumulator Architecture CPU MBR MAR PC Increment Interpreter IR Acc ALU CPU Memory Data bus Address bus Memory Control 16 bit 10 bit
  • 18. Execution for Add Y in an Acc Architecture MAR  PC MDR  M[MAR] IR  MDR MAR  IR (X) PC  PC + 2 Fetch Decode Execute MDR  M[MAR] Acc  MDR + Acc Address X extracted from IR Contents of Address X transferred to MDR Contents of Address X added to Accumulator
  • 19. GPR vs Acc Let the following instructions be allowed: For GPR machine (with 4 data reg) • Move 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑗 Move 𝑅𝑖, M[X] ; 𝑅𝑖 ← M[X] Move M[X], 𝑅𝑖 ; M[X] ← 𝑅𝑖 • Add 𝑅𝑖, M[X] ; 𝑅𝑖 ← 𝑅𝑖 + M[X] Add 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑖 + 𝑅𝑗 • Sub 𝑅𝑖, M[X] ; 𝑅𝑖 ← 𝑅𝑖 − M[X] Sub 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑖 − 𝑅𝑗 • Mult 𝑅𝑖, 𝑅𝑗 ; 𝑅𝑖 ← 𝑅𝑖 ∗ 𝑅𝑗 • Stop For Accumulator machine • Add x ; 𝐴𝑐𝑐 ← 𝐴𝑐𝑐 + M[X] • Sub x ; 𝐴𝑐𝑐 ← 𝐴𝑐𝑐 − M[X] • Mult x ; 𝐴𝑐𝑐 ← 𝐴𝑐𝑐 ∗ M[X] • LD x ; 𝐴𝑐𝑐 ← M[X] • ST x ; M[X] ← 𝐴𝑐𝑐 • Stop Note that M[X] = x
  • 20. GPR vs Acc Assembly Program for a <- (x + y) * (x – y) For GPR machine (with 4 data reg) Move 𝐷0, 𝑋 Add 𝐷0, 𝑌 Move 𝐷1, 𝑋 Sub 𝐷1, 𝑌 Mult 𝐷0, 𝐷1 Move 𝐴, 𝐷0 Stop For Accumulator machine LD X ADD Y ST C LD X SUB Y MULT C ST A STOP