How many times will the following loop be executed ? LXI B, 0007 H LOP : DCX B…

2014

How many times will the following loop be executed ?

     LXI B, 0007 H

LOP :   DCX B

            MOV A, B

            ORA C

            JNZ LOP

  1. A.

    05

  2. B.

    07

  3. C.

    09

  4. D.

    00

Attempted by 47 students.

Show answer & explanation

Correct answer: B

Answer: 7 times.

Explanation:

  • BC is initialized to 0007h, so B = 00h and C = 07h.

  • DCX B decrements the 16-bit BC pair by 1 on each iteration.

  • MOV A, B places the high byte (B) into A, and ORA C performs A OR C. The zero flag is set only when A OR C = 0, which means both B and C must be 00.

  • Starting from 0007h, it takes 7 decrements (0007 -> 0006 -> ... -> 0000) for BC to become 0000h. On the seventh iteration the ORA yields zero and the JNZ is not taken.

Explore the full course: Mppsc Assistant Professor