• edited by
21,810 views
71 71 votes

In a simplified computer the instructions are:

$$\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:

  • $t_1\: = \: a+b$
  • $t_2\: = \: c+d$
  • $t_3\: = \: e-t_2$
  • $t_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?

  1. $2$
  2. $3$
  3. $5$
  4. $6$

9 Answers

Best answer
124 124 votes
  • MOV $a, R_1$
  • ADD $b, R_1$
  • MOV $c, R_2$
  • ADD $d, R_2$
  • SUB $e, R_2$
  • SUB $R_1, R_2$
  • MOV $R_2, m$


 Total number of MOV instructions $= 3$

Correct Answer: $B$

• edited by
17 17 votes

3 MOV instructions.

12 12 votes

Let the two registers be $R_{1}$ and $R_{2}$

  1. Move a into $R_{1}$, then add b into it. Equivalently, we can move b into $R_{1}$ then add a into it. (1 Move)
  2. Move c into $R_{2}$, then add d into it. Equivalently, we can move d into $R_{2}$ then add c into it. (1 Move)
  3. Subtract e from $R_{2}$
  4. Subtract $R_{2}$ from $R_{1}$

Total 2 moves.

Now, the question says that the final value must be in the memory. So, Move the contents of $R_{2}$ into the memory. (1 Move)

 

So, 3 moves. Option B.

7 7 votes

Min 3 moves

2 2 votes

let us consider 2 registers r1 and r2

MOV c,R1

OP d,R1

OP e,R1

MOV a,R2

OP b,R2

OP R1,R2

MOV R1,m

 

so answer is 3 

NOTE:  though 2 can also come in the answer a+b have to be performed separately(basic block)

2 2 votes

$R_{j}\Leftarrow R_{j}\ OP\ R_{i}$

$R_{i}\Leftarrow val\ OP\ R_{i}$

$R_{i}\Leftarrow m$

$m\Leftarrow R_{i}$


 

$R_{1}\Leftarrow a(mov)$

$R_{1}\Leftarrow b+R_{1}$

$R_{2}\Leftarrow c(mov)$

$R_{2}\Leftarrow d+R_{2}$

$R_{2}\Leftarrow e-R_{2}$

$R_{1}\Leftarrow R_{1}-R_{2}$

$m\Leftarrow R_{1}(mov)$

Answer : B

Answer:
Position:
Show:

Related questions

47 47 votes
3 answers 3 answers
15.6k
15.6k views
go_editor asked Apr 23, 2016
15,562 views
Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.$$\begin{array}{|l|l|l|c|} \hline & \text {Instruction} & \...
49 49 votes
6 answers 6 answers
14.6k
14.6k views
go_editor asked Apr 23, 2016
14,618 views
Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.$$\small \begin{array}{|c|l|l||c|} \hline & \text {Instruct...
80 80 votes
7 answers 7 answers
34.3k
34.3k views
Kathleen asked Sep 21, 2014
34,338 views
Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.$$\begin{array}{|l|l|l|c|} \hline & \text {Instruction} & \...
62 62 votes
7 answers 7 answers
16.7k
16.7k views
go_editor asked Apr 23, 2016
16,742 views
Consider a machine with a byte addressable main memory of $2^{16}$ bytes. Assume that a direct mapped data cache consisting of $32$ lines of $64$ bytes each is used in th...