edited by
17,266 views
40 votes
40 votes

The memory locations $1000,1001$ and $1020$ have data values $18,1$ and $16$ respectively before the following program is executed.

$$\begin{array}{ll} \text{MOVI} & \text{$R_s, 1$} && \text{; Move immediate} \\  \text{LOAD} & \text{$R_d, 1000(R_s)$} && \text{; Load from memory}\\   \text{ADDI} & \text{$ R_d, 1000$} && \text{; Add immediate}\\  \text{STOREI} & \text{$0(R_d), 20$} && \text{; Store immediate}   \end{array}$$ Which of the statements below is TRUE after the program is executed ?

  1. Memory location $1000$ has value $20$
  2. Memory location $1020$ has value $20$
  3. Memory location $1021$ has value $20$
  4. Memory location $1001$ has value $20$
edited by

3 Answers

Best answer
59 votes
59 votes

Before the execution of the program, the memory contents are-

Now, let's execute the program instructions one by one-

  1. $\textbf{Instruction-01: MOVI $R_{s}, 1$}$
    • This instruction uses immediate addressing mode.
    • The instruction is interpreted as $R_{s} \leftarrow 1.$
    • Thus, value $= 1$ is moved to the register $R_{s}$.
  2. $\textbf{Instruction-02: LOAD $R_{d}, 1000\left(R_{s}\right)$}$
    • This instruction uses indexed addressing mode.

    • The instruction is interpreted as $R_{d} \leftarrow [1000 + [R_{s}]].$

    • Value of the operand $= [1000 + [R_{s}]] = [1000 + 1] = [1001] = 1.$

    • Thus, value $= 1$ is moved to the register $R_{d}$.

  3. $\textbf{Instruction-03: ADDI $R_{d}, 1000$}$
    • This instruction uses immediate addressing mode.

    • The instruction is interpreted as $R_{d} \leftarrow [R_{d}] + 1000.$

    • Value of the operand $= [R_{d}] + 1000 = 1 + 1000 = 1001.$

    • Thus, value $= 1001$ is moved to the register $R_{d}$.

  4. $\textbf{Instruction-04: STOREI 0($R_{d}), 20$}$
    • This instruction uses indexed addressing mode.

    • The instruction is interpreted as $0 + [R_{d}] \leftarrow 20.$

    • Value of the destination address $= 0 + [R_{d}] = 0 + 1001 = 1001.$

    • Thus, value $= 20$ is moved to the memory location $1001.$

Hence, after the program execution is completed, memory location $1001$ has a value $20.$

Option D is correct.

edited by
51 votes
51 votes
$D$ is the answer. Memory location $1001$ has value $20$.
$R_s \leftarrow 1$ (Immediate Addressing)
$R_d \leftarrow 1$ (Indexed Addressing, value at memory location $1+1000 = 1001$ is loaded to $R_d$ which is $1$)
$R_d \leftarrow 1001$ ($R_d$ becomes $1+1000$)
store in  address $1001 \leftarrow 20$
edited by
9 votes
9 votes

Initially let Rs and Rd have any values.

After ins 1:

Rs holds 1

 

For ins 2:

⇒Rd ←1000(Rs)

⇒Rd ←[Rs+1000]     (It says whatever is in Rs is added with 1000 and result is used as the memory address which has to be                                          fetched and put it in Rd)

⇒Rd ←[1+1000]       (Rs was having 1 in it after 1st instruction)

⇒Rd ←[1001] 

⇒Rd ←1                    (Given that address 1001 actually holds value 1)

So, finally after ins 2, 

Rs holds 1

Rd holds 1

 

For Ins 3:

⇒Rd←Rd+1000         (direct addition of 1000 to whatever is being held in Rd)

⇒Rd←1+1000           (Rd had 1 in it after ins 2)

⇒Rd←1001

So, finally after ins 3, 

Rs holds 1

Rd holds 1001

 

For Ins 4:

⇒0(Rd) ←20

⇒[0+Rd]←20        (It says, add 0 to whatever is stored in Rd, assume the result as another new address where 20 needs to be                                 stored)

⇒[0+1001]←20    (Rd had 1001 after last instruction)

⇒[1001]←20         (Put value 20 into the address 1001)

 

Finally, address 1001 contains value 20.

Values initially held in memory locations 1001 and 1020 are given just to confuse the reader, only one of the whole given date is used to solve the question.

So, the answer is D.

Answer:

Related questions

56 votes
56 votes
3 answers
1