Three Address Code
Submitted by: Submitted To:
Shashti D B Dr.Maheshwari L Patil
4GM20CS095 Assistant Professor
Dept. Of CS&E
GMIT, Davangere
Contents:
• Three Address Code
• Address and Instructions
• Quadruples
• Applications
• VTU Questions
Three Address Code
• Three address code is a type of intermediate code which is easy to generate and
can be easily converted to machine code.
Address and Instructions
Three-address code is built from two concepts:
• Address
• Instructions
An address can be one of the following:
• Name
• Constant
• Compiler-generated temporary
List of the common three-address instruction forms:
1. Assignment instructions
x = y op z and x = op y
Binary, arithmetic or Unary
logical operation operation
2. Copy Instructions : x=y
3. Unconditional Jump: goto L
4. Conditional Jump: if x goto L and if x relop y goto L
5. Procedure calls and returns: param x call p return y
6. Index copy Instructions: x = y[i] and x[i] =y
7.Address and pointer Assignments: x =&y , x=*y , *x=y
Convert the expression a * – (b + c) into three address code
Implementation of Three Address Code
There are 3 representations of three address code namely
1. Quadruple
2. Triples
3. Indirect Triples
Quadruples
It is a structure which consists 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.
The following are some exceptions to this rule:
1. Instructions with unary operators like x = minus y or x = y do not use arg2.
Note that for a copy statement like x = y, op is =, while for most
other operations, the assignment operator is implied.
2. Operators like param use neither arg2 nor result.
3. Conditional and unconditional jumps put the target label in result.
a = b*-c + b*-c
Applications
o Optimization
o Code generation
o Debugging
o Language Translation
VTU Questions
THANK YOU