A Simple Expression Compiler
For 0-, 1-, 2-, and 3- Address Machines

Dusko Koncaliev
Principles of Computer Organization
Programming Project


A SAMPLE RUN:
/clients/users/dusko/www/cs63/progproject> exprcompiler.pl

This program takes an expression of the form X=.....,
converts it to reverse polish notation and then compiles it
to 0-, 1-, 2-, and 3-address machine instructions (as in
Andrew S. Tanenbaum's, Structured Computer Organization,
(Prentice Hall, 1990), chapter 5, problem 8.
Note: the program can work with both constant numbers and
variables, but is restricted to only 1-character variables.

Please enter the expression (in the form X=.......): (A+3*23)/(465-B*C)

Expression: X = ( A + 3 * 23 ) / ( 465 - B * C )

RPN : X A 3 23 * + 465 B C * - / =

0-address machine instructions:
The result of this compiling (in a slightly changed form for
Kennedy's use) can be found at
/clients/users/dusko/www/cs63/progproject/outfile.txt

PUSH A
PUSH 3
PUSH 23
MUL
ADD
PUSH 465
PUSH B
PUSH C
MUL
SUB
DIV
POP X


1-address machine instructions:
LOAD 3
MUL 23
STORE R1
LOAD A
ADD R1
STORE R2
LOAD B
MUL C
STORE R3
LOAD 465
SUB R3
STORE R4
LOAD R2
DIV R4
STORE X


2-address machine instructions:
MOV R1 3
MUL R1 23
MOV R2 A
ADD R2 R1
MOV R3 B
MUL R3 C
MOV R4 465
SUB R4 R3
MOV X R2
DIV X R4


3-address machine instructions:
MUL R1 3 23
ADD R2 A R1
MUL R3 B C
SUB R4 465 R3
DIV X R2 R4