Skip to content
Official PYQ · 2007

GATE CS 2007 Q54 — Machine Instructions and Addressing Modes

Explain with AI

In a simplified computer the instructions are:

OP Rj,RiPerform Rj OP Ri and store the result in register RjOP m,RiPerform val OP Ri and store the result in register Rival denotes the content of the memory location mMOV m,RiMoves the content of memory location m to register RiMOV Ri,mMoves the content of register Ri to memory location m\begin{array}{|l|l|} \hline \text{OP }R _j , R _i & \text{Perform }R _j \text{ OP } R _i \text{ and store the result in register }R _j \\ \hline \text{OP }m,R _i & \text{Perform } val\text{ OP }R _i \text{ and store the result in register }R _i \\ & val \text{ denotes the content of the memory location }m \\ \hline \text{MOV }m,R _i & \text{Moves the content of memory location }m \text{ to register }R _i \\ \hline \text{MOV }R _i,m & \text{Moves the content of register }R _i\text{ to memory location }m\\ \hline \end{array}

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

  • t1 = a+bt_1\: = \: a+b
  • t2 = c+dt_2\: = \: c+d
  • t3 = e−t2t_3\: = \: e-t_2
  • t4 = t1–t3t_4\: = \: t_1 – t_3

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?

Choose one option
View worked solution

Answer: B

To find the minimum number of MOV instructions, we can carefully schedule the evaluation of the expressions using the two available registers, R0R_0 and R1R_1.

Let's evaluate t2t_2 and t3t_3 first, followed by t1t_1, and finally t4t_4:

  1. MOV c, R0    (R0←cR_0 \leftarrow c)
    (1st MOV)
  2. ADD d, R0    (R0←c+d=t2R_0 \leftarrow c + d = t_2)
  3. SUB e, R0    (R0←e−R0=e−t2=t3R_0 \leftarrow e - R_0 = e - t_2 = t_3)
    Note: The instruction OP m, R_i performs val OP Ri→Rival \text{ OP } R_i \to R_i, so SUB e, R0 correctly computes e−t2e - t_2.
  4. MOV a, R1    (R1←aR_1 \leftarrow a)
    (2nd MOV)
  5. ADD b, R1    (R1←a+b=t1R_1 \leftarrow a + b = t_1)
  6. SUB R1, R0    (R1←R1−R0=t1−t3=t4R_1 \leftarrow R_1 - R_0 = t_1 - t_3 = t_4)
  7. MOV R1, t4    (t4←R1t_4 \leftarrow R_1)
    (3rd MOV)

This sequence successfully computes the basic block using only 3 MOV instructions (two loads and one store).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Machine Instructions and Addressing Modes questions