SlideShare a Scribd company logo
1 of 13
Welcome to
MY PRESENTATION
1
1Three Address Code
Intermediate Code Generation
.
Three Address Code
2
Submitted To
Shah Md. Tanvir Siddiquee
Assistant Professor
Department of CSE
Daffodil International University
Submitted by:
Sourov Kumar Mondal
ID:173-15-1688
Section:PC-A
Department of CSE
Daffodil International University
2
Discussion Topics
• Intermediate Code Generation
• Three address code in Compiler
• Implementation of Three Address
Code
• following expression
• Conclusion
Three Address Code
3
Intermediate Code Generation
In the analysis-synthesis model of a compiler, the front end of a compiler translates a
source program into an independent intermediate code, then the back end of the
compiler uses this intermediate code to generate the target code (which can be
understood by the machine
Three Address Code 4
Three address code in Compiler
Three address code is a type of intermediate code which is easy to generate and
can be easily converted to machine code.It makes use of at most three addresses
and one operator to represent an expression and the value computed at each
instruction is stored in temporary variable generated by compiler. The compiler
decides the order of operation given by three address code.
Converting the expression x * (y - z) into three address code:
t1 = y - z
t2 = x * t1
Three Address Code 5
Implementation of Three Address Code
There are 3 representations of three address code:
1. Quadruple
2. Triples
3. Indirect Triples
Three Address Code 6
Three address code for the following expression:
((a+b)-((a+b)*(a-b)))+((a+b)*(a-b))
t1 = a + b
t2 = a - b
t3 = t1 * t2
t4 = t1 - t3
t5 = t1 * t2
t6 = t4 + t5
Three Address Code 7
For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b))
It is structure with consist of 4 fields namely op, arg1, arg2 and result. op denotes the operator and arg1 and
arg2 denotes the two operands and result is used to store the result of the expression.
Three Address Code 8
Three Address Code:
t1 = a + b
t2 = a - b
t3 = t1 * t2
t4 = t1 - t3
t5 = t1 * t2
t6 = t4 + t5
Quadruples
# op arg1 arg2 result
0 + a b t1
1 - a b t2
2 * t1 t2 t3
3 - t1 t3 t4
4 * t1 t2 t5
5 + t4 t5 t6
For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b))
This representation doesn’t make use of extra temporary variable to represent a single operation instead
when a reference to another triple’s value is needed, a pointer to that triple is used. So, it consist of only
three fields namely op, arg1 and arg2.
Three Address Code 9
Quadruples Triples
# op arg1 arg2 result
0 + a b t1
1 - a b t2
2 * t1 t2 t3
3 - t1 t3 t4
4 * t1 t2 t5
5 + t4 t5 t6
# op arg1 arg2
0 + a b
1 - a b
2 * (0) (1)
3 - (0) (2)
4 * (0) (1)
5 + (3) (4)
For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b))
This representation makes use of pointer to the listing of all references to computations which is made
separately and stored. Its similar in utility as compared to quadruple representation but requires less
space than it. Temporaries are implicit and easier to rearrange code.
Three Address Code 10
Triples Indirect Triples
# op arg1 arg2
0 + a b
1 - a b
2 * (0) (1)
3 - (0) (2)
4 * (0) (1)
5 + (3) (4)
• .
# op arg1 arg2
0 + a b
1 - a b
2 * (0) (1)
3 - (0) (2)
4 * (0) (1)
5 + (3) (4)
# Statement
0 21
1 22
2 23
3 24
4 25
5 26
Directed Acyclic Graph (DAG)
For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b))
Three Address Code 11
Conclusion
Since three-address code is used as an intermediate language within
compilers, the operands will most likely not be concrete memory
addresses or processor registers, but rather symbolic addresses that
will be translated into actual addresses during register allocation.
Three Address Code 12
Three Address Code 13

More Related Content

What's hot

Array in c language
Array in c languageArray in c language
Array in c language
home
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 

What's hot (20)

Code optimization
Code optimizationCode optimization
Code optimization
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
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
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
4. block coding
4. block coding 4. block coding
4. block coding
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Quick tutorial on IEEE 754 FLOATING POINT representation
Quick tutorial on IEEE 754 FLOATING POINT representationQuick tutorial on IEEE 754 FLOATING POINT representation
Quick tutorial on IEEE 754 FLOATING POINT representation
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentation
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 
Instruction format
Instruction formatInstruction format
Instruction format
 
Lex programming
Lex programmingLex programming
Lex programming
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
What Is LEX and YACC?
What Is LEX and YACC?What Is LEX and YACC?
What Is LEX and YACC?
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Assembler
AssemblerAssembler
Assembler
 

Similar to Presentation(intermediate code generation)

Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
bolovv
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
Shashwat Shriparv
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
venkatapranaykumarGa
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
bolovv
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
bolovv
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
venkatapranaykumarGa
 

Similar to Presentation(intermediate code generation) (20)

Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 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
 
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 generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
Instruction Set Architecture
Instruction  Set ArchitectureInstruction  Set Architecture
Instruction Set Architecture
 
Ch8a
Ch8aCh8a
Ch8a
 
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...
 
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptx
 
Intermediate code generator.pptx
Intermediate code generator.pptxIntermediate code generator.pptx
Intermediate code generator.pptx
 
UNIT-3.pptx
UNIT-3.pptxUNIT-3.pptx
UNIT-3.pptx
 
Lcdf4 chap 03_p2
Lcdf4 chap 03_p2Lcdf4 chap 03_p2
Lcdf4 chap 03_p2
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
 
C programming part2
C programming part2C programming part2
C programming part2
 

Recently uploaded

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
meharikiros2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 

Presentation(intermediate code generation)

  • 2. Intermediate Code Generation . Three Address Code 2 Submitted To Shah Md. Tanvir Siddiquee Assistant Professor Department of CSE Daffodil International University Submitted by: Sourov Kumar Mondal ID:173-15-1688 Section:PC-A Department of CSE Daffodil International University 2
  • 3. Discussion Topics • Intermediate Code Generation • Three address code in Compiler • Implementation of Three Address Code • following expression • Conclusion Three Address Code 3
  • 4. Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end of a compiler translates a source program into an independent intermediate code, then the back end of the compiler uses this intermediate code to generate the target code (which can be understood by the machine Three Address Code 4
  • 5. Three address code in Compiler Three address code is a type of intermediate code which is easy to generate and can be easily converted to machine code.It makes use of at most three addresses and one operator to represent an expression and the value computed at each instruction is stored in temporary variable generated by compiler. The compiler decides the order of operation given by three address code. Converting the expression x * (y - z) into three address code: t1 = y - z t2 = x * t1 Three Address Code 5
  • 6. Implementation of Three Address Code There are 3 representations of three address code: 1. Quadruple 2. Triples 3. Indirect Triples Three Address Code 6
  • 7. Three address code for the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b)) t1 = a + b t2 = a - b t3 = t1 * t2 t4 = t1 - t3 t5 = t1 * t2 t6 = t4 + t5 Three Address Code 7
  • 8. For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b)) It is structure with consist of 4 fields namely op, arg1, arg2 and result. op denotes the operator and arg1 and arg2 denotes the two operands and result is used to store the result of the expression. Three Address Code 8 Three Address Code: t1 = a + b t2 = a - b t3 = t1 * t2 t4 = t1 - t3 t5 = t1 * t2 t6 = t4 + t5 Quadruples # op arg1 arg2 result 0 + a b t1 1 - a b t2 2 * t1 t2 t3 3 - t1 t3 t4 4 * t1 t2 t5 5 + t4 t5 t6
  • 9. For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b)) This representation doesn’t make use of extra temporary variable to represent a single operation instead when a reference to another triple’s value is needed, a pointer to that triple is used. So, it consist of only three fields namely op, arg1 and arg2. Three Address Code 9 Quadruples Triples # op arg1 arg2 result 0 + a b t1 1 - a b t2 2 * t1 t2 t3 3 - t1 t3 t4 4 * t1 t2 t5 5 + t4 t5 t6 # op arg1 arg2 0 + a b 1 - a b 2 * (0) (1) 3 - (0) (2) 4 * (0) (1) 5 + (3) (4)
  • 10. For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b)) This representation makes use of pointer to the listing of all references to computations which is made separately and stored. Its similar in utility as compared to quadruple representation but requires less space than it. Temporaries are implicit and easier to rearrange code. Three Address Code 10 Triples Indirect Triples # op arg1 arg2 0 + a b 1 - a b 2 * (0) (1) 3 - (0) (2) 4 * (0) (1) 5 + (3) (4) • . # op arg1 arg2 0 + a b 1 - a b 2 * (0) (1) 3 - (0) (2) 4 * (0) (1) 5 + (3) (4) # Statement 0 21 1 22 2 23 3 24 4 25 5 26
  • 11. Directed Acyclic Graph (DAG) For the following expression: ((a+b)-((a+b)*(a-b)))+((a+b)*(a-b)) Three Address Code 11
  • 12. Conclusion Since three-address code is used as an intermediate language within compilers, the operands will most likely not be concrete memory addresses or processor registers, but rather symbolic addresses that will be translated into actual addresses during register allocation. Three Address Code 12