SlideShare uma empresa Scribd logo
1 de 24
CODE
GENERATION
UNIT-5
Learning Objectives
 To understand the issues in generating code
Keyword : code generation
Introduction
Definition:
In computing, code generation is the process by which a
compiler's code generator converts some intermediate representation
of source code into a form (e.g., machine code) that can be readily
executed by a machine. Sophisticated compilers typically perform
multiple passes over various intermediate forms.
Cont.….
 So far we discussed front-end completely
 Where we discussed lexical phase ,syntax phase, semantic phase
completely
 After doing that we did intermediate code generator where we
have converted code into three address code
 All the (Front-end, code optimizer, code generator ) are access the
symbol table
Cont.…
 Code produced by complier must be correct
 Source to target program transformation is semantic preserving
 Code produced by compiler should be of high quality
 Effective use of target machine resources
 The code which is generated is in optimal state
Issues in the design of Code
Generator
 Input to the code generator
 Target Program
 Memory Management
 Instruction selection
 Register allocation
Input to the code generator:
 Intermediate representation of the source program
 Linear – Postfix
 Tables – Quadruples,Triples,Indirect triples
 No-Linear – AST,DAG
 In addition we also need a symbol table information give it to the
code generator
Target Program:
 The Back-end code generator of a complier may different forms of
code, depending on the requirements.
 Absolute machine code – Executable
 Relocatable machine code – Object files
 Assembly language
 Byte code forms for interpreters like JVM
 Implementing code generation requires thorough understanding of
the target machine architecture and its instruction set
 Our machine:
 Byte – addressable(word = 4 bytes)
 Has n general purpose registers R0,R1,……,Rn-1
 Two – address instructions of the form
 OP SOURCE , DESTINATION
Target machine :
Op-Code&Address modes
 Op – code , for example
 MOV (move content of source to destination)
 ADD (add content of source to destination)
 SUB (subtract content of source from destination)
 It has 6 address modes, They are
Instruction selection : Cost
 Machine is a simple , non-super-scalar processor with fixed
instruction costs
 Realistic machine have deep pipelines, I –cache, D –cache etc.
 Define the cost of instruction
 1+cost(source node)+cost(destination node)
Instruction selection :
Addressing modes
 Suppose we translate “ a:b+c” into
MOV b,R0
ADD c,R0
MOV R0,a
 Assuming address of a , b and c are stored in R0,R1 and R2
MOV *R1,*R2
ADD *R2,*R0
 Assuming R1 and R2 contain values of b and c
ADD R2,R1
MOV R1,a
Need for Global code optimization:
 Suppose we translate three – address code ” x:=y+z” to:
MOV y,R0
ADD z,R0
MOV R0,x
This is for single instruction…..
Cont…..
 For double instructions:
EX: a:=b+c
d:=a+e
to:
MOV a,R0
ADD b,R0
MOV R0,a Redundant as R0 is used.
MOV a,R0
ADD e,R0
MOV R0,d
Register Allocation and Assignment:
 Efficient utilization of the limited set of register s is important to
generate good code
 Registers are assigned by
 Register allocation to select the set of variables that will reside in
registers at a point in the code
 Register assignment to pick the specific register that a variable will
reside in particular point of time
Choice of Evaluation Order:
a+b-(c+d)*e t1:=a+b MOV a,R0
t2:=c+d ADD b,R0
t3:=e*t2 MOV R0,t1
t4:=t1-t3 MOV c,R1
ADD d,R1
MOV e,R0
MUL R1,R0
MOV t1,R1
SUB R0,R1
MOV R1,t4
Reordered Instructions and code:
t2: = c+d MOV c,R0
t3: = e*t2 ADD d,R0
t1: = a+b MOV e,R1
t4: = t1-t3 MUL R0,R1
MOV a ,R0
ADD b,R0
SUB R1,R0
MOV R0,t4
Cont.….
 When instruction are independent , their evolution order can be
changed to utilize registers and save on instruction set
 This is also possible with code generator
ANY QUIERIES
DARSHAN SAI REDDY.U
15121A15B2

Mais conteúdo relacionado

Mais procurados

Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design) Tasif Tanzim
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler designRajkumar R
 
Storage organization and stack allocation of space
Storage organization and stack allocation of spaceStorage organization and stack allocation of space
Storage organization and stack allocation of spaceMuhammad Haroon
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dagsindhu mathi
 
Three Address code
Three Address code Three Address code
Three Address code Pooja Dixit
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignmentKarthi Keyan
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generatorsanchi29
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
Input output organization
Input output organizationInput output organization
Input output organizationabdulugc
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 
Basic blocks and flow graph in Compiler Construction
Basic blocks and flow graph in Compiler ConstructionBasic blocks and flow graph in Compiler Construction
Basic blocks and flow graph in Compiler ConstructionMuhammad Haroon
 

Mais procurados (20)

Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
Storage organization and stack allocation of space
Storage organization and stack allocation of spaceStorage organization and stack allocation of space
Storage organization and stack allocation of space
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dags
 
Three Address code
Three Address code Three Address code
Three Address code
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Run time storage
Run time storageRun time storage
Run time storage
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Micro program example
Micro program exampleMicro program example
Micro program example
 
Input output organization
Input output organizationInput output organization
Input output organization
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Basic blocks and flow graph in Compiler Construction
Basic blocks and flow graph in Compiler ConstructionBasic blocks and flow graph in Compiler Construction
Basic blocks and flow graph in Compiler Construction
 

Semelhante a Issues in the design of Code Generator

Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Tirumala Rao
 
Introduction to computer architecture .pptx
Introduction to computer architecture .pptxIntroduction to computer architecture .pptx
Introduction to computer architecture .pptxFatma Sayed Ibrahim
 
C from hello world to 010101
C from hello world to 010101C from hello world to 010101
C from hello world to 010101Bellaj Badr
 
intro to assembly language.pptx
intro to assembly language.pptxintro to assembly language.pptx
intro to assembly language.pptxEdFeranil
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler languageAshok Raj
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computerMartial Kouadio
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generationIffat Anjum
 
Source-to-Source Compiler
Source-to-Source CompilerSource-to-Source Compiler
Source-to-Source CompilerMintoo Jakhmola
 
Chapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfChapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfRAnwarpasha
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compilerAbha Damani
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Shehrevar Davierwala
 

Semelhante a Issues in the design of Code Generator (20)

Ch9a
Ch9aCh9a
Ch9a
 
Bp150522
Bp150522Bp150522
Bp150522
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Introduction to computer architecture .pptx
Introduction to computer architecture .pptxIntroduction to computer architecture .pptx
Introduction to computer architecture .pptx
 
C from hello world to 010101
C from hello world to 010101C from hello world to 010101
C from hello world to 010101
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
intro to assembly language.pptx
intro to assembly language.pptxintro to assembly language.pptx
intro to assembly language.pptx
 
Wk1to4
Wk1to4Wk1to4
Wk1to4
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computer
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
 
Source-to-Source Compiler
Source-to-Source CompilerSource-to-Source Compiler
Source-to-Source Compiler
 
Unit1 cd
Unit1 cdUnit1 cd
Unit1 cd
 
Chapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfChapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdf
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 

Último

Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 

Último (20)

Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 

Issues in the design of Code Generator

  • 2. Learning Objectives  To understand the issues in generating code Keyword : code generation
  • 3. Introduction Definition: In computing, code generation is the process by which a compiler's code generator converts some intermediate representation of source code into a form (e.g., machine code) that can be readily executed by a machine. Sophisticated compilers typically perform multiple passes over various intermediate forms.
  • 4.
  • 5. Cont.….  So far we discussed front-end completely  Where we discussed lexical phase ,syntax phase, semantic phase completely  After doing that we did intermediate code generator where we have converted code into three address code  All the (Front-end, code optimizer, code generator ) are access the symbol table
  • 6. Cont.…  Code produced by complier must be correct  Source to target program transformation is semantic preserving  Code produced by compiler should be of high quality  Effective use of target machine resources  The code which is generated is in optimal state
  • 7. Issues in the design of Code Generator  Input to the code generator  Target Program  Memory Management  Instruction selection  Register allocation
  • 8. Input to the code generator:  Intermediate representation of the source program  Linear – Postfix  Tables – Quadruples,Triples,Indirect triples  No-Linear – AST,DAG  In addition we also need a symbol table information give it to the code generator
  • 9. Target Program:  The Back-end code generator of a complier may different forms of code, depending on the requirements.  Absolute machine code – Executable  Relocatable machine code – Object files  Assembly language  Byte code forms for interpreters like JVM
  • 10.  Implementing code generation requires thorough understanding of the target machine architecture and its instruction set  Our machine:  Byte – addressable(word = 4 bytes)  Has n general purpose registers R0,R1,……,Rn-1  Two – address instructions of the form  OP SOURCE , DESTINATION
  • 11. Target machine : Op-Code&Address modes  Op – code , for example  MOV (move content of source to destination)  ADD (add content of source to destination)  SUB (subtract content of source from destination)  It has 6 address modes, They are
  • 12.
  • 13. Instruction selection : Cost  Machine is a simple , non-super-scalar processor with fixed instruction costs  Realistic machine have deep pipelines, I –cache, D –cache etc.  Define the cost of instruction  1+cost(source node)+cost(destination node)
  • 14.
  • 15.
  • 16. Instruction selection : Addressing modes  Suppose we translate “ a:b+c” into MOV b,R0 ADD c,R0 MOV R0,a  Assuming address of a , b and c are stored in R0,R1 and R2 MOV *R1,*R2 ADD *R2,*R0  Assuming R1 and R2 contain values of b and c ADD R2,R1 MOV R1,a
  • 17. Need for Global code optimization:  Suppose we translate three – address code ” x:=y+z” to: MOV y,R0 ADD z,R0 MOV R0,x This is for single instruction…..
  • 18. Cont…..  For double instructions: EX: a:=b+c d:=a+e to: MOV a,R0 ADD b,R0 MOV R0,a Redundant as R0 is used. MOV a,R0 ADD e,R0 MOV R0,d
  • 19. Register Allocation and Assignment:  Efficient utilization of the limited set of register s is important to generate good code  Registers are assigned by  Register allocation to select the set of variables that will reside in registers at a point in the code  Register assignment to pick the specific register that a variable will reside in particular point of time
  • 20.
  • 21. Choice of Evaluation Order: a+b-(c+d)*e t1:=a+b MOV a,R0 t2:=c+d ADD b,R0 t3:=e*t2 MOV R0,t1 t4:=t1-t3 MOV c,R1 ADD d,R1 MOV e,R0 MUL R1,R0 MOV t1,R1 SUB R0,R1 MOV R1,t4
  • 22. Reordered Instructions and code: t2: = c+d MOV c,R0 t3: = e*t2 ADD d,R0 t1: = a+b MOV e,R1 t4: = t1-t3 MUL R0,R1 MOV a ,R0 ADD b,R0 SUB R1,R0 MOV R0,t4
  • 23. Cont.….  When instruction are independent , their evolution order can be changed to utilize registers and save on instruction set  This is also possible with code generator
  • 24. ANY QUIERIES DARSHAN SAI REDDY.U 15121A15B2