Tianchi YU's Blog

What is Three Address Code (3AC) ?

Today I would like to make a short note about Three Address Code.

Q: What is it?

A: It is a type of intermediate code.

Q: What is its advantages?

A: It is highly comprehensible, facilitates the generation of intermediate representations, and readily converts to machine code.

Q: What is its standard form?

A: At most three addresses(operants) and one operator, the order of operands depends on the specific compiler. The general representation is a = b op c

Q: Can you present a simple example?

A: For example, a = b * (c - d) could be represented as

_t1 = c - d; _t2 = b * _t1; a = _t2;

I hope these short answers help you to understand 3AC. To verify if you have understood it 100% percent, you could try to transfer the following expressions into 3AC(answers are in the next post).

for(i = 1; i <= 10; i++)
{
  a[i] = x * x;                               
} 
if (a < b + c)
    a = a - c;
c = b * c;

#compiler