Exams › GATE › Technical
In a simplified computer, the instructions are: - `OP Rj, Ri` — performs `Rj OP Ri` and stores the result in register `Ri`. - `OP m, Ri` — performs `val OP Ri` and stores the result in register `Ri`, where `val` denotes the content of memory location `m`. - `MOV m, Ri` — 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: ```text t1 = a + b t2 = c + d t3 = e - t2 t4 = t1 - t3 ``` Assume that all operands are initially in memory and 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?
- 2
- 3
- 5
- 6
Correct answer: 3
Solution
Because only two registers are available, some intermediate values must be kept in memory or recomputed. An efficient schedule can compute `t1`, then `t2`, then `t3`, and finally `t4` with only three `MOV` instructions. The minimum is 3.
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →