Skip to content
Official PYQ · 2003

GATE CS 2003 Q49 — Machine Instructions and Addressing Modes

Explain with AI

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

 

MOV B, #0

;

B←0B \leftarrow 0

 

MOV C, #8

;

C←8C \leftarrow 8

Z:

CMP C, #0

;

compare C with 0

 

JZ X

;

jump to X if zero flag is set

 

SUB C, #1

;

C←C−1C \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 a7..a0a_7..a_0 and 

   

;

c0c_0 respectively, their values after the execution of this

   

;

instruction will be c0a7..a1c_0a_7..a_1 and a0a_0 respectively.

 

JC Y

;

jump to Y if carry flag is set

 

JMP Z

;

jump to Z

Y:

ADD B, #1

;

B←B+1B \gets B+1

 

JMP Z

;

jump to Z

X:

     

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

Choose one option
View worked solution

Answer: A

Let the initial value of register AA be a7a6a5a4a3a2a1a0a_7 a_6 a_5 a_4 a_3 a_2 a_1 a_0 and the initial state of the carry flag be CinC_{in}.

The loop runs exactly 88 times (as register CC decrements from 88 to 00). In each iteration, the RRC A, #1 instruction rotates the bits of AA right through the carry flag by 11 bit:

  • Initial state: A=a7a6a5a4a3a2a1a0A = a_7 a_6 a_5 a_4 a_3 a_2 a_1 a_0, Carry=Cin\text{Carry} = C_{in}
  • After 1st rotation: A=Cina7a6a5a4a3a2a1A = C_{in} a_7 a_6 a_5 a_4 a_3 a_2 a_1, Carry=a0\text{Carry} = a_0
  • After 2nd rotation: A=a0Cina7a6a5a4a3a2A = a_0 C_{in} a_7 a_6 a_5 a_4 a_3 a_2, Carry=a1\text{Carry} = a_1
  • …\dots
  • After 8th rotation (at label X): A=a6a5a4a3a2a1a0CinA = a_6 a_5 a_4 a_3 a_2 a_1 a_0 C_{in}, Carry=a7\text{Carry} = a_7

To restore register AA to its original value a7a6a5a4a3a2a1a0a_7 a_6 a_5 a_4 a_3 a_2 a_1 a_0, we need to shift the current carry flag (a7a_7) back into the MSB of AA, and shift all other bits right by one position.

Executing one more RRC A, #1 at location XX does exactly this:

New A=(Carry)a6a5a4a3a2a1a0=a7a6a5a4a3a2a1a0\text{New } A = (\text{Carry}) a_6 a_5 a_4 a_3 a_2 a_1 a_0 = a_7 a_6 a_5 a_4 a_3 a_2 a_1 a_0

Thus, inserting RRC A, #1 at location XX restores the initial value of register AA.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Machine Instructions and Addressing Modes questions