SlideShare a Scribd company logo
1 of 10
By
M.Lalitha(BP150522)
II M.Sc Computer Science
Target machine
1. Op-codes
2. Address modes
Instruction Costs
Example
Instruction Selection
Utilizing Addressing Modes
 Implementing code generation requires thorough
understanding of the target machine architecture and its
instruction set
 Our (hypothetical) machine:
◦ Byte-addressable (word = 4 bytes)
◦ Has n general purpose registers R0, R1, …, Rn-1
◦ Two-address instructions of the form
op source, destination
◦ Op :: op-code
◦ Source, destination – data fields
 Op-codes (op), for example
 MOV (move content of source to destination)
 ADD (add content of source to destination)
 SUB (subtract content of source from destination)
 Addressing mode: Different ways in which location of an
operand can be specified in the instruction.
Mode Form Address Added Cost
Absolute M M 1
Register R R 0
Indexed c(R) c+contents(R) 1
Indirect register *R contents(R) 0
Indirect indexed *c(R) contents(c+contents(R)) 1
Literal #c N/A 1
 Machine is a simple processor with fixed instruction costs
 In most of the machines and in most of the instructions the
time taken to fetch an instruction from memory exceeds the
time spent executing the instruction. So reducing the length of
the instruction has an extra benefit.
Instruction Operation Cost
MOV R0,R1 Store content(R0) into register R1 1
MOV R0,M Store content(R0) into memory location M 2
MOV M,R0 Store content(M) into register R0 2
MOV 4(R0),M Store contents(4+contents(R0)) into M 3
MOV *4(R0),M Store contents(contents(4+contents(R0))) into M 3
MOV #1,R0 Store 1 into R0 2
ADD 4(R0),*12(R1) Add contents(4+contents(R0))
to value at location contents(12+contents(R1)) 3
• Instruction selection is important to obtain efficient
code
• Suppose we translate three-address code
x:= y + z
to: MOV y,R0
ADD z,R0
MOV R0,x
a:=a+1 MOV a,R0
ADD #1,R0
MOV R0,a
ADD #1,a INC a
Cost = 6
Cost = 3 Cost = 2
Better Best
 Suppose we translate a:=b+c into
MOV b, R0
ADD c, R0 Cost=6
MOV R0,a
 Assuming addresses of a, b, and c are stored in R0,
R1, and R2
MOV *R1, *R0
ADD *R2, *R0 cost=2
 Assuming R1 and R2 contain values of b and c
ADD R2,R1
MOV R1,a cost=3
Bp150522

More Related Content

What's hot

Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructionsRobert Almazan
 
Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branchingJyotiprakashMishra18
 
Instruction set of 8085 microprocessor
Instruction set of 8085 microprocessorInstruction set of 8085 microprocessor
Instruction set of 8085 microprocessorRahul Sahu
 
MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085Sumadeep Juvvalapalem
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with typesRavinder Rautela
 
Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Muhammad Umar Farooq
 
Instruction set of 8085 Microprocessor By Er. Swapnil Kaware
Instruction set of 8085 Microprocessor By Er. Swapnil KawareInstruction set of 8085 Microprocessor By Er. Swapnil Kaware
Instruction set of 8085 Microprocessor By Er. Swapnil KawareProf. Swapnil V. Kaware
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 
15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3RLJIT
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086Mahalakshmiv11
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5RLJIT
 
Instruction set 8085
Instruction set 8085Instruction set 8085
Instruction set 8085varun sukheja
 
8085 arithmetic instructions
8085 arithmetic instructions8085 arithmetic instructions
8085 arithmetic instructionsprashant1271
 
15CS44 MP & MC Module 2
15CS44 MP & MC Module  215CS44 MP & MC Module  2
15CS44 MP & MC Module 2RLJIT
 
8085 instruction set and Programming
8085 instruction set and Programming 8085 instruction set and Programming
8085 instruction set and Programming pooja saini
 

What's hot (20)

Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branching
 
Instruction set of 8085 microprocessor
Instruction set of 8085 microprocessorInstruction set of 8085 microprocessor
Instruction set of 8085 microprocessor
 
MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
 
Assembly Language -I
Assembly Language -IAssembly Language -I
Assembly Language -I
 
Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Assembly language (addition and subtraction)
Assembly language (addition and subtraction)
 
Instruction set of 8085 Microprocessor By Er. Swapnil Kaware
Instruction set of 8085 Microprocessor By Er. Swapnil KawareInstruction set of 8085 Microprocessor By Er. Swapnil Kaware
Instruction set of 8085 Microprocessor By Er. Swapnil Kaware
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5
 
Instruction set 8085
Instruction set 8085Instruction set 8085
Instruction set 8085
 
8085 arithmetic instructions
8085 arithmetic instructions8085 arithmetic instructions
8085 arithmetic instructions
 
15CS44 MP & MC Module 2
15CS44 MP & MC Module  215CS44 MP & MC Module  2
15CS44 MP & MC Module 2
 
8085 instruction set and Programming
8085 instruction set and Programming 8085 instruction set and Programming
8085 instruction set and Programming
 
arithmetic ins in 8051
arithmetic ins in 8051arithmetic ins in 8051
arithmetic ins in 8051
 

Viewers also liked

Pancasila sebagai Ideologi dan Dasar Negara
Pancasila sebagai Ideologi dan Dasar NegaraPancasila sebagai Ideologi dan Dasar Negara
Pancasila sebagai Ideologi dan Dasar NegaraPahmi Agustian
 
Politik Strategi Nasional
Politik Strategi NasionalPolitik Strategi Nasional
Politik Strategi Nasionalpjj_kemenkes
 
Death & dying theories
Death & dying theoriesDeath & dying theories
Death & dying theoriesSana Sultan
 
DIPLOMATIC CITIZENRY of, by and for NORTH CAROLINA
DIPLOMATIC CITIZENRY of, by and for NORTH CAROLINADIPLOMATIC CITIZENRY of, by and for NORTH CAROLINA
DIPLOMATIC CITIZENRY of, by and for NORTH CAROLINAUnderdog Business Strategies
 
apj abdul kalam presentation
apj abdul kalam presentationapj abdul kalam presentation
apj abdul kalam presentationkatkarprashant
 
Salesforce Spring 17 Release Overview
Salesforce Spring 17 Release OverviewSalesforce Spring 17 Release Overview
Salesforce Spring 17 Release OverviewRoy Gilad
 
Prolonged labour -gihs
Prolonged labour -gihsProlonged labour -gihs
Prolonged labour -gihsgangahealth
 

Viewers also liked (9)

Innocreativiy
InnocreativiyInnocreativiy
Innocreativiy
 
Pancasila sebagai Ideologi dan Dasar Negara
Pancasila sebagai Ideologi dan Dasar NegaraPancasila sebagai Ideologi dan Dasar Negara
Pancasila sebagai Ideologi dan Dasar Negara
 
Politik Strategi Nasional
Politik Strategi NasionalPolitik Strategi Nasional
Politik Strategi Nasional
 
¿Cómo organizar un evento?
¿Cómo organizar un evento?¿Cómo organizar un evento?
¿Cómo organizar un evento?
 
Death & dying theories
Death & dying theoriesDeath & dying theories
Death & dying theories
 
DIPLOMATIC CITIZENRY of, by and for NORTH CAROLINA
DIPLOMATIC CITIZENRY of, by and for NORTH CAROLINADIPLOMATIC CITIZENRY of, by and for NORTH CAROLINA
DIPLOMATIC CITIZENRY of, by and for NORTH CAROLINA
 
apj abdul kalam presentation
apj abdul kalam presentationapj abdul kalam presentation
apj abdul kalam presentation
 
Salesforce Spring 17 Release Overview
Salesforce Spring 17 Release OverviewSalesforce Spring 17 Release Overview
Salesforce Spring 17 Release Overview
 
Prolonged labour -gihs
Prolonged labour -gihsProlonged labour -gihs
Prolonged labour -gihs
 

Similar to Bp150522

Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptxModule 2 PPT of ES.pptx
Module 2 PPT of ES.pptxshruthi810379
 
(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)Alveena Saleem
 
Instruction set.pptx
Instruction set.pptxInstruction set.pptx
Instruction set.pptxssuser000e54
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptManju Badiger
 
Compreport
CompreportCompreport
Compreportxdarlord
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction SetDr. Pankaj Zope
 
Lec3 instructions branch carl hamcher
Lec3 instructions branch carl hamcher Lec3 instructions branch carl hamcher
Lec3 instructions branch carl hamcher Venkata Krishnakanth P
 
MICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptxMICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptxAmoghR3
 
Computer organization and architecture
Computer organization and architectureComputer organization and architecture
Computer organization and architectureSubesh Kumar Yadav
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Romain Francois
 
Instruction set (prasenjit dey)
Instruction set (prasenjit dey)Instruction set (prasenjit dey)
Instruction set (prasenjit dey)Prasenjit Dey
 

Similar to Bp150522 (20)

Ch9a
Ch9aCh9a
Ch9a
 
addressing-mode-of-8051.pdf
addressing-mode-of-8051.pdfaddressing-mode-of-8051.pdf
addressing-mode-of-8051.pdf
 
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptxModule 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
 
(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)
 
Instruction set.pptx
Instruction set.pptxInstruction set.pptx
Instruction set.pptx
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
Unit vi
Unit viUnit vi
Unit vi
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.ppt
 
Compreport
CompreportCompreport
Compreport
 
UNIT 2 ERTS.ppt
UNIT 2 ERTS.pptUNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 
Part 1.pptx
Part 1.pptxPart 1.pptx
Part 1.pptx
 
Lec3 instructions branch carl hamcher
Lec3 instructions branch carl hamcher Lec3 instructions branch carl hamcher
Lec3 instructions branch carl hamcher
 
MICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptxMICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptx
 
Computer organization and architecture
Computer organization and architectureComputer organization and architecture
Computer organization and architecture
 
UNIT-3.pptx
UNIT-3.pptxUNIT-3.pptx
UNIT-3.pptx
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
Instruction set (prasenjit dey)
Instruction set (prasenjit dey)Instruction set (prasenjit dey)
Instruction set (prasenjit dey)
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
“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
 
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
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
“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...
 
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
 

Bp150522

  • 2. Target machine 1. Op-codes 2. Address modes Instruction Costs Example Instruction Selection Utilizing Addressing Modes
  • 3.  Implementing code generation requires thorough understanding of the target machine architecture and its instruction set  Our (hypothetical) machine: ◦ Byte-addressable (word = 4 bytes) ◦ Has n general purpose registers R0, R1, …, Rn-1 ◦ Two-address instructions of the form op source, destination ◦ Op :: op-code ◦ Source, destination – data fields
  • 4.  Op-codes (op), for example  MOV (move content of source to destination)  ADD (add content of source to destination)  SUB (subtract content of source from destination)
  • 5.  Addressing mode: Different ways in which location of an operand can be specified in the instruction. Mode Form Address Added Cost Absolute M M 1 Register R R 0 Indexed c(R) c+contents(R) 1 Indirect register *R contents(R) 0 Indirect indexed *c(R) contents(c+contents(R)) 1 Literal #c N/A 1
  • 6.  Machine is a simple processor with fixed instruction costs  In most of the machines and in most of the instructions the time taken to fetch an instruction from memory exceeds the time spent executing the instruction. So reducing the length of the instruction has an extra benefit.
  • 7. Instruction Operation Cost MOV R0,R1 Store content(R0) into register R1 1 MOV R0,M Store content(R0) into memory location M 2 MOV M,R0 Store content(M) into register R0 2 MOV 4(R0),M Store contents(4+contents(R0)) into M 3 MOV *4(R0),M Store contents(contents(4+contents(R0))) into M 3 MOV #1,R0 Store 1 into R0 2 ADD 4(R0),*12(R1) Add contents(4+contents(R0)) to value at location contents(12+contents(R1)) 3
  • 8. • Instruction selection is important to obtain efficient code • Suppose we translate three-address code x:= y + z to: MOV y,R0 ADD z,R0 MOV R0,x a:=a+1 MOV a,R0 ADD #1,R0 MOV R0,a ADD #1,a INC a Cost = 6 Cost = 3 Cost = 2 Better Best
  • 9.  Suppose we translate a:=b+c into MOV b, R0 ADD c, R0 Cost=6 MOV R0,a  Assuming addresses of a, b, and c are stored in R0, R1, and R2 MOV *R1, *R0 ADD *R2, *R0 cost=2  Assuming R1 and R2 contain values of b and c ADD R2,R1 MOV R1,a cost=3