2.4k views

Consider the following assembly language program for a hypothetical processor A, B, and C are 8 bit registers. The meanings of various instructions are shown as comments.

 MOV B, #0 ; $B \leftarrow 0$ MOV C, #8 ; $C \leftarrow 8$ Z: CMP C, #0 ; compare C with 0 JZ X ; jump to X if zero flag is set SUB C, #1 ; $C \gets C-1$ RRC A, #1 ; right rotate A through carry by one bit. Thus: ; If the initial values of A and the carry flag are $a_7..a_0$ and ; $c_0$ respectively, their values after the execution of this ; instruction will be $c_0a_7..a_1$ and $a_0$ respectively. JC Y ; jump to Y if carry flag is set JMP Z ; jump to Z Y: ADD B, #1 ; $B \gets B+1$ JMP Z ; jump to Z X:

Which of the following instructions when inserted at location X will ensure that the value of the register A after program execution is as same as its initial value?

1. RRC A, #1
2. NOP  ; no operation
3. LRC A, #1;   left rotate A through carry flag by one bit
retagged | 2.4k views

Option $(A)$ RRC a, #1.  As the 8 bit register is rotated via carry 8 times.

$a_7a_6a_5a_4a_3a_2a_1a_0$
$c_0a_7a_6a_5a_4a_3a_2a_1$, now $a_0$ is the new carry. So, after next rotation,
$a_0c_0a_7a_6a_5a_4a_3a_2$

So, after 8 rotations,

$a_6a_5a_4a_3a_2a_1a_0c_0$ and carry is $a_7$.

Now, one more rotation will restore the original value of $A_0$.
edited
+1
sir.. here condition JC Y is when checked? as we do not know the value in register A. Do we have to ignore the instruction through out?
0
same doubt! @ arjun sir
+1
@Arjun Sir i have one doubt, I think CMP will reset the zero and carry flags when !=0( C>0)

So every time RRC is performed it should insert 0 at MSB every time right???

So how can the contents be made same by using RRC A only one time that too at the end.
0
It doesn't matter here as we need to Jump on Z again in both the cases whether it is a 0 or 1 in the carry. It is used just to complete the task of given assembly language program. The main concern is RRC on A and to get A again after the complete execution.
0
Sir can you please explain with the example?
If A has n bits with 1 carry bit ... then number of right rotations through carry after which we will get the same A is (n+1) .. Here this code is doing right rotation for n times .. So at the last step of program we do one more rotation ...

1
2