Consider the following program fragment in assembly language: mov ax, 0h mov…
2017
Consider the following program fragment in assembly language:
mov ax, 0h
mov cx, 0A h
do loop:
dec ax
loop doloop
What is the value of 𝑎𝑥 and 𝑐𝑥 registers after the completion of the doloop ?
- A.
𝑎𝑥=𝐹𝐹𝐹5ℎ and 𝑐𝑥=0ℎ
- B.
𝑎𝑥=𝐹𝐹𝐹6ℎ and 𝑐𝑥=0ℎ
- C.
𝑎𝑥=𝐹𝐹𝐹7ℎ and 𝑐𝑥=0𝐴ℎ
- D.
𝑎𝑥=𝐹𝐹𝐹5ℎ and 𝑐𝑥=0𝐴ℎ
Attempted by 38 students.
Show answer & explanation
Correct answer: B
Answer: AX = FFF6h, CX = 0h.
Reasoning:
Initial registers: AX = 0000h, CX = 000Ah (10 decimal).
Each iteration executes DEC AX once, decreasing AX by 1.
The LOOP instruction decrements CX each iteration and repeats while CX ≠ 0, so the body runs 10 times.
AX after 10 decrements: 0000h − 000Ah = FFF6h.
CX after LOOP completes: 0000h.