求救各位大侠,帮忙改个汇编程序加个主函数,实现折半查找算法的完整程序功能
; SEARCH-HALF-EX5_9dseg segment
low_idx dw ?
high_idx dw ?
dseg ends
cseg segment
b_search proc near
assume cs:cseg,ds:dseg,es:dseg
push ds
push ax
mov ax,dseg
mov ds,ax
mov es,ax
pop ax
cmp ax,es:[di+2]
ja chk_last
lea si,es:[di+2]
je exit
stc
jmp exit
chk_last:
mov si,es:[di]
shl si,1
add si,di
cmp ax,es:[si]
jb search
je exit
stc
jmp exit
search:
mov low_idx,1
mov bx,es:[di]
mov high_idx,bx
mov bx,di
mid: mov cx,low_idx
mov dx,high_idx
cmp cx,dx
ja no_match
add cx,dx
shr cx,1
mov si,cx
shl si,1
compare: cmp ax,es:[bx+si]
je exit
ja higher
dec cx
mov high_idx,cx
jmp mid
higher: inc cx
mov low_idx,cx
no_match:
stc
exit: pop ds
ret
b_search endp
cseg ends
end
上面是折半查找的实现函数,但是没有主函数,程序无法运行,怎么改啊?
要有输入输出才算完整的程序,比如我输入几个数后再输入一个随机数,如果前面输入的有这个数,则显示匹配 match 没有则显示 no match!希望大虾能理解我意思》_《
[ 本帖最后由 weedson 于 2012-12-10 16:15 编辑 ]