补全编程,利用 jcxz 指令,实现在内存 2000h 段中查找第一个值为 0 的字节,找到后将它的偏移地址放到 dx 中。
assume cs:code
code segment
start: mov ax, 2000h
mov ds, ax
mov bx, 0
s: _________
_________
_________
_________
jmp short s
ok: mov dx, bx
mov ax, 4c00h
int 21h
code ends
end start
答案
assume cs:code
code segment
start: mov ax, 200h ; 为了方便测试,我选择了自己设备上一段有数据的内存作为起始
mov ds, ax
mov bx, 0
s: mov ah, 0
mov byte ptr al, [bx]
mov cx, ax
jcxz ok
add bx, 1
jmp short s
ok: mov dx, bx
mov ax, 4c00h
int 21h
code ends
end start
上面的答案行数超过了,更新下
assume cs:code
code segment
start: mov ax, 200h ; 为了方便测试,我选择了自己设备上一段有数据的内存作为起始
mov ds, ax
mov bx, 0
s: mov ch, 0 ; 因为这里只有 4 行且位置限定了,实际这里应该将这一条指令移动到循环的外面
mov byte ptr cl, [bx]
jcxz ok
inc bx
jmp short s
ok: mov dx, bx
mov ax, 4c00h
int 21h
code ends
end start