Compilers

Which describes three-address code, a kind of intermediate representation?

  1. AA single instruction can contain any number of operations and parentheses
  2. BEach instruction has at most three addresses and one operation
  3. CAddresses must always be physical memory addresses
Show answer and explanation

Answer: B. Each instruction has at most three addresses and one operation

Three-address code breaks complex expressions into a sequence of simple instructions with one operation each. For example, x = (a + b) * c becomes t1 = a + b and x = t1 * c, and each instruction mentions at most three addresses: the result and two operands. Intermediate values get temporary names such as t1. This makes evaluation order explicit and eases optimization and translation to CPU instructions. Addresses are variables or temporaries, not physical addresses.

  • A. Each instruction has only one operation.
  • B. Correct. Instructions have at most three addresses and one operation.
  • C. Addresses are variables or temporaries, not physical addresses.
Practice this topic Back to topic

More Compilers questions

  1. What does liveness analysis, done in preparation for register allocation, determine?
  2. In a function, at most five values are live at the same time. In a simple case where the interference graph imposes no further constraints, how many registers are needed at minimum to hold every value without spilling?
  3. If a loop with 100 iterations is unrolled by replicating its body four times, how many counter checks and branches remain? (Assume 100 is divisible by 4.)
  4. What is the usual sequence for producing an executable from a C program?
  5. What is the optimization called that examines short sequences of generated machine code through a small window and replaces wasteful instruction combinations with better ones?