- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Three Address Code?
The three-address code is a sequence of statements of the form A−=B op C, where A, B, C are either programmer-defined names, constants, or compiler-generated temporary names, the op represents an operator that can be constant or floatingpoint arithmetic operators or a Boolean valued data or a logical operator. The reason for the name “three address code” is that each statement generally includes three addresses, two for the operands, and one for the result.
In the three-address code, atmost three addresses are define any statement. Two addresses for operand & one for the result.
Hence, op is an operator.
An only a single operation is allowed at a time at the right side of the expression.
Example− Expression a = b + c + d can be converted into the following Three Address Code.
t1 = b + c
t2 = t1 + d
a = t2
where t1 and t2 are temporary variables generated by the compiler. Most of the time a statement includes less than three references, but it is still known as a threeaddress statement.
Types of Three-Address Code Statements
Following are the various types of three address statements −
Assignment− The three types of Assignment statements are
x = y op z, op is a binary operator with y, z as operands.
x = op y, op is a unary operator
x = y, values of y is assigned to x.
Unconditional Jumps− Unconditional Jump is of the form goto L, L being a label.
Control flow to three address statements labeled at L.
Conditional Jump − Condition Jump is of the form
if x relop y goto L
Here relop can be <, >, <=, >=. If the condition is true, then it can execute three address statements at Label L else statement following if statement will be executed.
Array Statements −
x = y[i], value of ithlocation of array y is assigned to x.
x[i] = y, the value of y is assigned to ithlocation of array x.
Address & Pointer Assignments − Languages like Pascal & C allow pointer assignments.
x = & y, the address of y is assigned to x.
x = * y, the content of location pointed to by y is assigned to x.
*x=y, Finally sets the r-value of the object pointed to by x to the r-value of y.
Procedure call/Return − A call to the procedure P(x1, x2 … . . xn) with the parameters x1, x2 … . . xn is written as
call p, n
Here param refers to the parameter, & call p, n will call procedure p with n arguments.
- What is Implementation of Three Address Code Statements?
- What is loopback address?
- C++ code to find three numbers whose sum is n
- What is Address Resolution Protocol (ARP)?
- What is Gray code?
- What is Polynomial Code?
- What is Reverse Address Resolution Protocol (RARP)?
- What is Address Sequencing in Computer Architecture?
- What is a Three Winding Transformer?
- What is Excess-3 Code?
- What is Code Division Multiplexing?
- What is Intermediate Code Generation?
- What is a MAC Address in Computer Networks?
- What is three-bit sliding window protocol?
- What is unmanaged code in C#?