SlideShare une entreprise Scribd logo
1  sur  10
Three Address Code
Pooja Dixit
Department of Computer Science
Sophia Girls’ College (Autonomous),
Ajmer
Three address code
• Three-address code is an intermediate code. It is used by the
optimizing compilers.
• In three-address code, the given expression is broken down into
several separate instructions. These instructions can easily
translate into assembly language.
• In three address code, at most three addresses are used to
represent any statement.
• Each Three address code instruction has at most three
operands. It is a combination of assignment and a binary
operator.
• Example : Given Expression:
a := b op c
Where-
▫ a, b, c are operands
▫ Op= operators
• Example: a = b + c
▫ Here a, b, c = Operands
▫ +, = are Operator
How to Generate Three address code
• Eg:- a = b + c + d
this given expression has two operator +, =
Note: to generate 3-add code for given expression we
have follow these rules-
• ‘+’ operator has higher precedence over ‘=’ operator.
• ‘+’ operator is left associative.
• So the Address Code will be-
▫ T1 = b + c
▫ T2 = T1 + d
▫ a = T2
b + c + d
1
2
3
a =
According to the rule we
first solve b + c, than solve
d and at last store result
into a
Implementation of Three Address Code
• Three address code can be implemented as a record with the
address fields.
• There are three types of representation used for three
address code.
Representation
Quadruple
Triple
Indirect Triple
Implementation of Three Address Code –
1. Quadruple –
in quadruples representation each instruction is
divided into 4 fields.
Where-
▫ The op field is used to represent the internal code
for operator.
▫ The ag1, ag2 fields represent the two operands used.
▫ The result field is used to store the result of an
expression.
Operator
arg1
arg2
results
Three Address Code
• Example
• Change this expression into three-address code:
▫ t1 := e f
▫ t2 := b * c
▫ t3 := t2 / t1
▫ t4 := b * a
▫ t5 := a + t3
▫ t6 := t5 + t4
• These statements are represented by quadruples as follows:
• Operator Source 1 Source 2 Destination
(0) e f T1
(1) * b c T2
(2) / T2 T1 T3
(3) * b a T4
(4) + a T3 T5
(5) + T5 T4 T6
Note: here we arrange the terms according to the
Operator priority
Implementation of Three Address Code –
• Advantage –
▫ Easy to rearrange code for global optimization.
▫ One can quickly access value of temporary variables
using symbol table.
• Disadvantage –
▫ Contain lot of temporaries.
▫ Temporary variable creation increases time and
space complexity.
Triples
• The triples have three fields to implement the three address code. The
field of triples contains the name of the operator, the first arg1 operand
and the second arg2 operand.
• In triple representation the use of temporary variables are avoided and
instead to instructions are made.
Fig: Triples field
Operator
arg1
arg2
Triples
Example: consider the example of quadruple
• Three address code are same as quadruple
• These statements are represented by triples as follows:
• If there is any statement suffle
Operator Arg 1 Arg 2
(0) e f
(1) * b c
(2) / (1) (0)
(3) * b a
(4) + a (2)
(5) + (4) (3)
Indirect Triples
• This representation is an enhancement over triples representation. It
use an additional instruction array to list the pointers to the desired
order.
• Thus it use pointers instead of position to store result which enable the
optimizers to freely reposition the sub expression to produce an
optimize code.
Operator Arg 1 Arg 2
(0) e f
(1) * b c
(2) / (1) (0)
(3) * b a
(4) + a (2)
(5) + (4) (3)
Statement
35 (0)
36 (1)
37 (2)
38 (3)
39 (4)
40 (5)

Contenu connexe

Tendances

Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksMohammad Vaseem Akaram
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler designSudip Singh
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsingsanchi29
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTanzeela_Hussain
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1Shashwat Shriparv
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code GeneratorDarshan sai Reddy
 
Time space trade off
Time space trade offTime space trade off
Time space trade offanisha talwar
 

Tendances (20)

Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsing
 
A* Search Algorithm
A* Search AlgorithmA* Search Algorithm
A* Search Algorithm
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Time space trade off
Time space trade offTime space trade off
Time space trade off
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 

Similaire à Three Address code

Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)Sourov Kumar Ron
 
Chapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfChapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfRAnwarpasha
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
Compiler chapter six .ppt course material
Compiler chapter six .ppt course materialCompiler chapter six .ppt course material
Compiler chapter six .ppt course materialgadisaAdamu
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationRamchandraRegmi
 
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...Saikrishna Tanguturu
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoreambikavenkatesh2
 
Introduction to design and analysis of algorithm
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithmDevaKumari Vijay
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 
Lab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressionsLab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressionsAksharVaish2
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingEric Chou
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generationrawan_z
 
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH  SRIVATHS PC_BASICS FOR C PROGRAMMER WITH  SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH SRIVATHS Pamankr1234am
 

Similaire à Three Address code (20)

Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)
 
Chapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfChapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdf
 
Intermediate code
Intermediate codeIntermediate code
Intermediate code
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Compiler chapter six .ppt course material
Compiler chapter six .ppt course materialCompiler chapter six .ppt course material
Compiler chapter six .ppt course material
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Assignment12
Assignment12Assignment12
Assignment12
 
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
 
Introduction to design and analysis of algorithm
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithm
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Lab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressionsLab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressions
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH  SRIVATHS PC_BASICS FOR C PROGRAMMER WITH  SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
 
C- language Lecture 5
C- language Lecture 5C- language Lecture 5
C- language Lecture 5
 

Plus de Pooja Dixit

Combinational circuit.pptx
Combinational circuit.pptxCombinational circuit.pptx
Combinational circuit.pptxPooja Dixit
 
number system.pptx
number system.pptxnumber system.pptx
number system.pptxPooja Dixit
 
Multiplexer.pptx
Multiplexer.pptxMultiplexer.pptx
Multiplexer.pptxPooja Dixit
 
Logic Gates.pptx
Logic Gates.pptxLogic Gates.pptx
Logic Gates.pptxPooja Dixit
 
Karnaugh Map Simplification Rules.pptx
Karnaugh Map Simplification Rules.pptxKarnaugh Map Simplification Rules.pptx
Karnaugh Map Simplification Rules.pptxPooja Dixit
 
Half Subtractor.pptx
Half Subtractor.pptxHalf Subtractor.pptx
Half Subtractor.pptxPooja Dixit
 
De-multiplexer.pptx
De-multiplexer.pptxDe-multiplexer.pptx
De-multiplexer.pptxPooja Dixit
 
DeMorgan’s Theory.pptx
DeMorgan’s Theory.pptxDeMorgan’s Theory.pptx
DeMorgan’s Theory.pptxPooja Dixit
 
Combinational circuit.pptx
Combinational circuit.pptxCombinational circuit.pptx
Combinational circuit.pptxPooja Dixit
 
Boolean Algebra.pptx
Boolean Algebra.pptxBoolean Algebra.pptx
Boolean Algebra.pptxPooja Dixit
 
Binary Multiplication & Division.pptx
Binary Multiplication & Division.pptxBinary Multiplication & Division.pptx
Binary Multiplication & Division.pptxPooja Dixit
 
Binary addition.pptx
Binary addition.pptxBinary addition.pptx
Binary addition.pptxPooja Dixit
 
Basics of Computer Organization.pptx
Basics of Computer Organization.pptxBasics of Computer Organization.pptx
Basics of Computer Organization.pptxPooja Dixit
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithmPooja Dixit
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projectionPooja Dixit
 

Plus de Pooja Dixit (20)

Combinational circuit.pptx
Combinational circuit.pptxCombinational circuit.pptx
Combinational circuit.pptx
 
number system.pptx
number system.pptxnumber system.pptx
number system.pptx
 
Multiplexer.pptx
Multiplexer.pptxMultiplexer.pptx
Multiplexer.pptx
 
Logic Gates.pptx
Logic Gates.pptxLogic Gates.pptx
Logic Gates.pptx
 
K-Map.pptx
K-Map.pptxK-Map.pptx
K-Map.pptx
 
Karnaugh Map Simplification Rules.pptx
Karnaugh Map Simplification Rules.pptxKarnaugh Map Simplification Rules.pptx
Karnaugh Map Simplification Rules.pptx
 
Half Subtractor.pptx
Half Subtractor.pptxHalf Subtractor.pptx
Half Subtractor.pptx
 
Gray Code.pptx
Gray Code.pptxGray Code.pptx
Gray Code.pptx
 
Flip Flop.pptx
Flip Flop.pptxFlip Flop.pptx
Flip Flop.pptx
 
Encoder.pptx
Encoder.pptxEncoder.pptx
Encoder.pptx
 
De-multiplexer.pptx
De-multiplexer.pptxDe-multiplexer.pptx
De-multiplexer.pptx
 
DeMorgan’s Theory.pptx
DeMorgan’s Theory.pptxDeMorgan’s Theory.pptx
DeMorgan’s Theory.pptx
 
Combinational circuit.pptx
Combinational circuit.pptxCombinational circuit.pptx
Combinational circuit.pptx
 
Boolean Algebra.pptx
Boolean Algebra.pptxBoolean Algebra.pptx
Boolean Algebra.pptx
 
Binary Multiplication & Division.pptx
Binary Multiplication & Division.pptxBinary Multiplication & Division.pptx
Binary Multiplication & Division.pptx
 
Binary addition.pptx
Binary addition.pptxBinary addition.pptx
Binary addition.pptx
 
Basics of Computer Organization.pptx
Basics of Computer Organization.pptxBasics of Computer Organization.pptx
Basics of Computer Organization.pptx
 
Decoders
DecodersDecoders
Decoders
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithm
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projection
 

Dernier

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Dernier (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
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 ...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Three Address code

  • 1. Three Address Code Pooja Dixit Department of Computer Science Sophia Girls’ College (Autonomous), Ajmer
  • 2. Three address code • Three-address code is an intermediate code. It is used by the optimizing compilers. • In three-address code, the given expression is broken down into several separate instructions. These instructions can easily translate into assembly language. • In three address code, at most three addresses are used to represent any statement. • Each Three address code instruction has at most three operands. It is a combination of assignment and a binary operator. • Example : Given Expression: a := b op c Where- ▫ a, b, c are operands ▫ Op= operators • Example: a = b + c ▫ Here a, b, c = Operands ▫ +, = are Operator
  • 3. How to Generate Three address code • Eg:- a = b + c + d this given expression has two operator +, = Note: to generate 3-add code for given expression we have follow these rules- • ‘+’ operator has higher precedence over ‘=’ operator. • ‘+’ operator is left associative. • So the Address Code will be- ▫ T1 = b + c ▫ T2 = T1 + d ▫ a = T2 b + c + d 1 2 3 a = According to the rule we first solve b + c, than solve d and at last store result into a
  • 4. Implementation of Three Address Code • Three address code can be implemented as a record with the address fields. • There are three types of representation used for three address code. Representation Quadruple Triple Indirect Triple
  • 5. Implementation of Three Address Code – 1. Quadruple – in quadruples representation each instruction is divided into 4 fields. Where- ▫ The op field is used to represent the internal code for operator. ▫ The ag1, ag2 fields represent the two operands used. ▫ The result field is used to store the result of an expression. Operator arg1 arg2 results
  • 6. Three Address Code • Example • Change this expression into three-address code: ▫ t1 := e f ▫ t2 := b * c ▫ t3 := t2 / t1 ▫ t4 := b * a ▫ t5 := a + t3 ▫ t6 := t5 + t4 • These statements are represented by quadruples as follows: • Operator Source 1 Source 2 Destination (0) e f T1 (1) * b c T2 (2) / T2 T1 T3 (3) * b a T4 (4) + a T3 T5 (5) + T5 T4 T6 Note: here we arrange the terms according to the Operator priority
  • 7. Implementation of Three Address Code – • Advantage – ▫ Easy to rearrange code for global optimization. ▫ One can quickly access value of temporary variables using symbol table. • Disadvantage – ▫ Contain lot of temporaries. ▫ Temporary variable creation increases time and space complexity.
  • 8. Triples • The triples have three fields to implement the three address code. The field of triples contains the name of the operator, the first arg1 operand and the second arg2 operand. • In triple representation the use of temporary variables are avoided and instead to instructions are made. Fig: Triples field Operator arg1 arg2
  • 9. Triples Example: consider the example of quadruple • Three address code are same as quadruple • These statements are represented by triples as follows: • If there is any statement suffle Operator Arg 1 Arg 2 (0) e f (1) * b c (2) / (1) (0) (3) * b a (4) + a (2) (5) + (4) (3)
  • 10. Indirect Triples • This representation is an enhancement over triples representation. It use an additional instruction array to list the pointers to the desired order. • Thus it use pointers instead of position to store result which enable the optimizers to freely reposition the sub expression to produce an optimize code. Operator Arg 1 Arg 2 (0) e f (1) * b c (2) / (1) (0) (3) * b a (4) + a (2) (5) + (4) (3) Statement 35 (0) 36 (1) 37 (2) 38 (3) 39 (4) 40 (5)