edited by
1 flag 9,741 views
29 votes
29 votes

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. $\text{RRC A}, \#1$
  2. $\text{NOP} ;$ no operation
  3. $\text{LRC A,} \#1; $  left rotate $A$ through carry flag by one bit
  4. $\text{ADD A,} \#1$
  • 🚩 Edit necessary | 👮 Arjun
edited by
1 flag

3 Answers

52 votes
52 votes

Option $(A) \text{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$.

PS: In question, “ADD B, #1” should be replaced with “INC B” to prevent modification of carry flag. 

edited by
10 votes
10 votes
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 ...
6 votes
6 votes

$Let A=7(00000111)$
$|B=0|C=8|carry=0,zero=0|zero\neq1 |C=7|00000011\ \ 1|B=1$

$|carry=0,zero=0|zero\neq1 |C=6|10000001\ \ 1|B=2$

$|carry=0,zero=0|zero\neq1 |C=5|11000000\ \ 1|B=3$

$|carry=0,zero=0|zero\neq1 |C=4|11100000\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=3|01110000\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=2|00111000\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=1|00011100\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=0|00001110\ \ 0|$

$|carry=0,zero=1|zero=1:Jump\ to\ 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?

$If\ X:RRC \ A,\#1$

$|00000111\ \ 0|$


$Ans:A$

Answer:

Related questions

35 votes
35 votes
3 answers
1
Kathleen asked Sep 17, 2014
14,990 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 com...