Compare zero-, one-, two-, and three-address machines by writing programs to compute
X = (A+B X C)/D - E X F)
For each of the four machines. The instructions available for use as follows:
0 Address 1 Address 2 Address 3 Address
PUSH M LOAD M MOVE (X<-- Y) MOVE (X <--Y)
POP STORE M ADD (X<--X +Y) ADD (X<-- Y +Z)
ADD ADD M SUB (X<-- X -Y) SUB (X<-- Y -Z)
SUB SUB M MUL (X<-- X x Y) MUL (X<-- Y x Z)
MUL MUL M DIV (X<-- X /Y) DIV (X<-- Y /Z)
DIV DIV M
Legend: <-- arrow
small x multiply
3 Address mode
MUL T,B,C //T=B*C
ADD T,T,A //T=A+B*C
DIV T,T,D //T=(A+B*C)/D
MUL T1,E,F // T1=E*F
SUB X,T,T1 //X=T-T1=(A+B*C)/D-E*F
Here we have taken two temporary registers T,T1 and storing the result in these two temp registers and finally, we have stored the content of registers into X which is the result.
In 3 address machines, each instruction takes 4 memory access, one access to fetch opcode from memory, 2 for getting the 2 inputs operands and a final to write the result back in memory
Hence, machine generates a total no of 20 ...
The following posting helps compare address machines.