Three-address code is an intermediate representation in compilers where each instruction follows the format x := y op z, using at most three operands (two sources and one result). It simplifies code optimization and translation to machine code by breaking complex expressions into atomic operations.
Quadruples for a = -b * (c + d) / e
Quadruples represent three-address code with four fields: operator, source1, source2, and result.
| Operator | Source1 | Source2 | Result |
|---|---|---|---|
+ |
c |
d |
t1 |
- |
b |
None |
t2 |
* |
t2 |
t1 |
t3 |
/ |
t3 |
e |
t4 |
= |
t4 |
None |
a |
Breakdown:
- Addition: Compute
c + d→ stored int1. - Negation: Compute
-b→ stored int2. - Multiplication: Multiply
t2 * t1→ stored int3. - Division: Divide
t3 / e→ stored int4. - Assignment: Assign
t4toa.
Quadruples explicitly track intermediate results (t1–t4), enabling optimizations like dead-code elimination and register allocation.