0% found this document useful (0 votes)
21 views

Three Address Code

The document summarizes the three address code, which is an intermediate code representation that is easy to generate and convert to machine code. It consists of addresses, which can be names, constants, or temporary variables, and instructions. Common instruction forms include assignment, copy, unconditional/conditional jumps, procedure calls/returns, and address/pointer assignments. An example expression is converted to three address code using quadruples, which contain an operator, two operands, and a result field. Applications include optimization, code generation, debugging, and language translation.

Uploaded by

Shashti D B
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Three Address Code

The document summarizes the three address code, which is an intermediate code representation that is easy to generate and convert to machine code. It consists of addresses, which can be names, constants, or temporary variables, and instructions. Common instruction forms include assignment, copy, unconditional/conditional jumps, procedure calls/returns, and address/pointer assignments. An example expression is converted to three address code using quadruples, which contain an operator, two operands, and a result field. Applications include optimization, code generation, debugging, and language translation.

Uploaded by

Shashti D B
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

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

You might also like