The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+14 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: |

If the initial value of register A is A0 the value of register B after the program execution will be

- the number of 0 bits in $A_0$
- the number of 1 bits in $A_0$
- $A_0$
- 8

+1

Content of A0 is copied to A, we are rotating register to right with Carry, every 1 present in the register A carry will be set to 1, and everytime carry flag is set to 1, B will be incremented.

A contains the content of A0, it means when this program terminates, B will contain the number of 1's in the A (or) A0. there will be 8 iterations of the loop as value of C is initially 8 and with every iteration it is decremented by 1.

A contains the content of A0, it means when this program terminates, B will contain the number of 1's in the A (or) A0. there will be 8 iterations of the loop as value of C is initially 8 and with every iteration it is decremented by 1.

+16 votes

Best answer

–2

Dear

Now , after SUB C,#1 , value of C will be 7 ==> 0111

Now , will the RRC be 1011 ? so , B will be 0+1 = 1

After this C will be 7 ( CMP C,#0 will be zero flag false ) , now C <- C-1 , so C is 6 , 0110 ,

Now , RRC will be 0011 , so B will not be incremented.

Will this program flow happen in this way ?

0

@coolcoder are you rotating C? Question is rotating A and decrementing C.

@Amsar Because C is initialized to 8.

@Amsar Because C is initialized to 8.

0

@Arjun SIR

Can u pls explain what is happening in line

RRC A, #1 |

Carry Flad =0 Regiser A = 10010

After RRC 010010

When does carry flag set?

- All categories
- General Aptitude 1.3k
- Engineering Mathematics 5.1k
- Digital Logic 2k
- Programming & DS 3.7k
- Algorithms 3.1k
- Theory of Computation 3.9k
- Compiler Design 1.5k
- Databases 2.9k
- CO & Architecture 2.5k
- Computer Networks 2.9k
- Non GATE 1k
- Others 1.3k
- Admissions 449
- Exam Queries 428
- Tier 1 Placement Questions 17
- Job Queries 55
- Projects 8

35,500 questions

42,768 answers

121,499 comments

42,151 users