GATE | GATE-CS-2003 | Question 48

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 ← 0
 MOV C, # 8 ;    C ← 8
Z :  CMP C, # 0 ;    compare C with 0
 JZX ;    jump to X if zero flag is set
 SUB C, # 1 ;    C ← 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 a7…a0 and
;    c0 respectively, their values after the execution of this
;    instruction will be c0a7…a1 and a0 respectively.
 JC Y ;    jump to Y if carry flag is set
 JMP Z ;    jump to Z
Y :  ADD B, # 1 ;    B ← B + 1
 JMP Z ;    jump to Z
X :

(A) the number of 0 bits in A0
(B) the number of 1 bits in A0
(C) A0
(D) 8


Answer: (B)

Explanation: Answer: (B)

Explanation:

Explanation: Here value of B incremented by 1 only if carry flag is 1 and carry is filled always using right rotation. So B will store the no. of 1s in A0. RRC instruction is(  Each binary bit of the accumulator is rotated right by one position. Bit D0 is placed in the position of D7 as well as in the Carry flag. CY is modified according to bit D0. Any other bit is not affected). So A=A0, and after execution RRC A,#1, carry flag is set,it goes to Y,which is B=B+1,Which becomes B=0+1=1   So (B) is correct option

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.