Can anyone help me with this compiler question on MOV instruction?


#1

5.In a simplified computer the instructions are-

OP Rj, Ri -Performs Rj OP Ri and stores the result in register Rj

OP m,Ri -Performs (val OP Ri) and stores the result in register Ri. val
denotes the content of the memory location m

MOV m,R -Moves the content of memory location m to register Ri

MOV Ri,m -Moves the content of register Ri to memory location m

The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block:

t1 = a + b

t2 = c + d

t3 = e − t2

t4 = t1 – t3

Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?

a) 2
b) 3
c) 5
d) 6


#2

Although the question looks it may be somewhat difficult,it is relatively easy.

t1 = a + b,

mov a or b from memory and then perform OPm,ri to store result t1 in one register.

Similarly mov c or d from memory and then perform OPm,ri to store result t2 in one register.

t3 = e - t2,using OPM,rj

so we have t1 and t3 in 2 register,perform Ri op Rj and store result in one register and finally mov instruction moves it to the memory as written in question - The final value of the computation should be in memory.

So number of MOV instruction = 1 + 1 + 1 = 3.

So atleast read the questions which are lengthy and try to give some thought to it,may be they can turn out to be simple as this one if you are lucky. :slight_smile: