读到《汇编语言》第9章,一个有关jcxz指令的算法觉得很妙,问题如下:
利用jcxz指令,实现在内存2000H段中查找第一个值为0的字节,找到后将它的偏移地址存储在dx中。
代码:
assume cs:codesg
codesg segment
start: mov ax,2000h
mov ds,ax
mov bx,0
s: mov cl,[bx]
mov ch,0
jcxz ok //检查cx的值,为0则查找结束,跳向ok标志地址
inc bx
jmp short s //查找失败则循环继续查找
ok: mov dx,bx
mov ax,4c00h
int 21h
codesg ends
end start
codesg segment
start: mov ax,2000h
mov ds,ax
mov bx,0
s: mov cl,[bx]
mov ch,0
jcxz ok //检查cx的值,为0则查找结束,跳向ok标志地址
inc bx
jmp short s //查找失败则循环继续查找
ok: mov dx,bx
mov ax,4c00h
int 21h
codesg ends
end start