CSc 453: A Three-Address Intermediate Code Instruction Set for C--

The syntax of a three-address intermediate code is suggested below: You are not required to use this intermediate code instruction set for your projects, or to adhere to it as given below even if you decide to use some sort of three-address intermediate representation. However, the Notes on Translating Three-Address Code to MIPS Assembly Code [PostScript   |   PDF] is based on this instruction set, and if you choose to use something different you'll have to figure out the translation yourself. (This usually isn't difficult to do, but something to be aware of nonetheless.)

Here, n denotes a (decimal) integer constant, and label denotes a label.

Data Declarations

global id type
Declares id to be a global variable of type type, where type is int, char, array[n] of int, or array[n] of char.

Assignment Statements

x := y op z
The usual binary operations: op is one of +, -, *, /, and y and z are constants or variables.
x := -y
Unary minus. y is a constant or variable.
x := y
A copy operation. y is a constant or variable.

Jump Instructions

goto label
Unconditional jump
if x relop val goto label
val is an identifier or a decimal integer, relop is one of <=, <, >=, >, ==, !=.
label L
L is a label and must be unique in the program.

Indexed Assignments

x := y[i]
x[i] := y

Address and Pointer Assignments

x := & y
x := *y
*x := y

Procedural Instructions

enter f
f is (a pointer to the symbol table entry of) a function.
leave f
f is (a pointer to the symbol table entry of) a function.
param x
x is an actual parameter.
call p, n
p is a procedure, n the number of arguments.
return
return to the caller.
return x
return to the caller, with return value x.
retrieve x
Copy the return value into x.