📌  相关文章
📜  国际空间研究组织 | ISRO CS 2020 |问题 47(1)

📅  最后修改于: 2023-12-03 15:37:16.225000             🧑  作者: Mango

ISRO CS 2020 - Question 47

The International Space Research Organization (ISRO) conducts a yearly recruitment test for Computer Science graduates called the ISRO CS Test. In 2020, the test had 80 objective-type questions covering topics such as algorithms, data structures, computer networks, programming languages, operating systems, and database systems.

Question 47

Consider a simple CPU with 4 general purpose registers named R0, R1, R2, and R3. The CPU supports the following programming instructions:

  1. MOV R1,R2 (copy the contents of R2 to R1)
  2. MOV R1,#10 (store the value 10 in R1)
  3. ADD R1,R2 (add the contents of R2 to R1 and store the result in R1)
  4. SUB R1,R2 (subtract the contents of R2 from R1 and store the result in R1)
  5. MUL R1,R2 (multiply the contents of R2 with R1 and store the result in R1)
  6. DIV R1,R2 (divide the contents of R1 by R2 and store the quotient in R1)

Suppose the CPU is initialized with R0 = 0, R1 = 5, R2 = -3, and R3 = 4. What is the final value of R1 after executing the following program?

MOV R3,R2
ADD R3,R3
SUB R1,R3
MUL R2,R1
Answer

To solve the problem, we need to simulate the execution of the program step-by-step, keeping track of the values of the registers. Here is how the program executes:

  1. MOV R3,R2: R3 is set to -3 (the current value of R2).
  2. ADD R3,R3: R3 is added to itself, resulting in -6.
  3. SUB R1,R3: R3 (which is -6) is subtracted from R1 (which is 5), resulting in 11. Hence, R1 now contains the value 11.
  4. MUL R2,R1: R1 (which is 11) is multiplied with R2 (which is -3), resulting in -33. Hence, the final value of R1 is -33.

Therefore, the final value of R1 after executing the program is -33.

## Answer

The final value of R1 after executing the program is **-33**.