The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+18 votes
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
  4. ADD A, #1
asked in CO and Architecture by Veteran (97.7k points)
retagged by | 2.4k views

2 Answers

+27 votes
Best answer
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$.
answered by Veteran (414k points)
edited by
+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?
+5 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 ...
answered by Loyal (7.4k points)
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,814 questions
54,521 answers
188,389 comments
75,425 users