GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 49

Restoring an eight-bit register after through-carry rotations

Computer Organization & Architecture · Instructions & Addressing Modes · Full GATE CSE 2003 paper

GATE 2003, Q49 2 marks · MCQ
Report issue

Instructions & Addressing Modes

Question 49, GATE 2003: A, B and C are 8-bit registers in a hypothetical processor. The program is:
MOV B,#0       ; B=0
MOV C,#8       ; C=8
Z: CMP C,#0    ; compare C with zero
JZ X          ; jump if zero flag is set
SUB C,#1      ; C=C-1
RRC A,#1      ; rotate A right through carry once
JC Y          ; jump if carry is set
JMP Z
Y: ADD B,#1   ; B=B+1
JMP Z
X:
RRC transforms A=a7...a0 and carry=c into A=ca7...a1 and carry=a0. Use the instruction effects listed for this hypothetical machine.
Which instruction inserted at X ensures that A ends with its original value?
A. RRC A,#1
B. NOP (no operation)
C. LRC A,#1 (rotate A left through carry once)
D. ADD A,#1
Question 49, GATE 2003: A, B and C are 8-bit registers in a hypothetical processor. The program is:
MOV B,#0       ; B=0
MOV C,#8       ; C=8
Z: CMP C,#0    ; compare C with zero
JZ X          ; jump if zero flag is set
SUB C,#1      ; C=C-1
RRC A,#1      ; rotate A right through carry once
JC Y          ; jump if carry is set
JMP Z
Y: ADD B,#1   ; B=B+1
JMP Z
X:
RRC transforms A=a7...a0 and carry=c into A=ca7...a1 and carry=a0. Use the instruction effects listed for this hypothetical machine.
Which instruction inserted at X ensures that A ends with its original value?
A. RRC A,#1
B. NOP (no operation)
C. LRC A,#1 (rotate A left through carry once)
D. ADD A,#1
Question 49, GATE 2003: A, B and C are 8-bit registers in a hypothetical processor. The program is:
MOV B,#0       ; B=0
MOV C,#8       ; C=8
Z: CMP C,#0    ; compare C with zero
JZ X          ; jump if zero flag is set
SUB C,#1      ; C=C-1
RRC A,#1      ; rotate A right through carry once
JC Y          ; jump if carry is set
JMP Z
Y: ADD B,#1   ; B=B+1
JMP Z
X:
RRC transforms A=a7...a0 and carry=c into A=ca7...a1 and carry=a0. Use the instruction effects listed for this hypothetical machine.
Which instruction inserted at X ensures that A ends with its original value?
A. RRC A,#1
B. NOP (no operation)
C. LRC A,#1 (rotate A left through carry once)
D. ADD A,#1
Tap to enlarge
Your answer
Answer & solution

Answer: A under the stated instruction effects (no official key was published)

1. Include carry in the state: (c,a7,a6,...,a0) is a nine-position ring. One RRC moves this ring one position right.
2. The loop performs eight rotations, so its accumulated permutation is R8. Since R9 is the identity, another RRC restores all nine bits.
3. NOP leaves R8 unchanged; one left rotation gives R7, not identity; adding 1 is not a bit-position inverse. Hence A works under the given instruction effects. This explicitly relies on other listed instructions not modifying carry.

Solution: Treat carry and A together as a nine-bit circular register and use the instruction effects stated for this hypothetical processor. Eight right rotations leave one right rotation short of a full nine-bit cycle. Inserting RRC A,#1 at X therefore restores A, irrespective of the initial carry value, giving A. This reasoning uses carry preservation by instructions whose listed effects do not change carry; importing different flag side effects from a real ISA would require a new analysis.

Original paper, page 7