CpSc 423, Language Processor Techniques

Three-Address Code

Instructions are written as quadruples (op, arg1, arg2, arg3). See p. 172 of the texbook for more information.

Add Immediate

Add constant to the contents of src, storing the result in memory location dst.

addi constant src1 dst

Equal To

Compare the contents of src1 and src2. If they are equal, store 1 in memory location dst, else store 0.

eq src1 src2 dst

Not Equal To

Compare the contents of src1 and src2. If they are equal, store 0 in memory location dst, else store 1.

ne src1 src2 dst

Less Than

Compare the contents of src1 and src2. If src1is less than src2, store 1 in memory location dst, else store 0;

lt src1 src2 dst

Greater than

Compare the contents of src1 and src2. If src1is greater than src2, store 1 in memory location dst, else store 0.

gt src1 src2 dst

Logical And

If the contents of src1 and src2 are both non-zero, store 1 in memory location dst, else store 0;

and src1 src2 dst

Logical Or

If the contents of either src1 or src2 are non-zero, store 1 in memory location dst, else store 0;

or src1 src2 dst

Logical Not

If src contains 0, store 1 in dst, else store 0.

not 0 src dst

Addition

Add the contents of src1 and src2, storing the result in dst.

add src1 src2 dst

Subtraction

Subtract the contents of src2 from the contents of src1, storing the result in dst.

sub src1 src2 dst

Multiplication

Multiple the contents of src1 and src2, storing the result in dst.

mul src1 src2 dst

Division

Divide the contents of src1 by the contents of src2, storing the result in dst.

div src1 src2 dst

Modulus

Divide the contents of src1 by the contents of src2, storing the remainder in dst.

mod src1 src2 dst

Unconditional Jump

Jump immediately to instruction number dst.

j 0 0 dst

Branch if Equal

Jump to instruction number dst if the contents of src1 and src2 are equal.

beq src1 src2 dst

Branch if Not Equal

Jump to instruction number dst if the contents of src1 and src2 are not equal.

bne src1 src2 dst

Write

Write the contents of src to standard output.

wrt 0 src 0

Halt

Stop running the program.

hlt 0 0 0