“Assembly Language”, 3rd Edition by Wang Shuang
Chapter 9: Principles of Transfer Instructions
Checkpoint 9.3 (Page 185)
Complete the program to use the loop instruction to find the first byte with a value of 0 in the memory segment 2000H, and store its offset address in dx after finding it.
assume cs:codecode segment start: mov ax, 2000H mov ds, ax mov bx, 0 s: mov cl, [bx] mov ch, 0 ______________ inc bx loop s ok: dec bx ;dec function is the opposite of inc, (bx)=(bx)-1 mov dx, bx mov ax, 4c00H int 21Hcode endsend start
—————————-Reference Answer
Analysis: First, to find the first byte with a value of 0, it is necessary to search byte by byte, so cx must be assigned values for ch and cl separately.
Secondly, when the loop executes, cx will be decremented by 1 before checking if it is not equal to 0, so after assigning a value to cx, it is necessary to increment it by 1, so that when looping, the decrement will yield the actual value.
Based on the above analysis, the line of code to be completed is:
inc cx
or:
add cx, 1
The answer is not unique; as long as cx’s value is incremented by 1, it is acceptable.