;**********************电话号码表实现*******************************;在本次试验中需要注意基址寄存器BX的移动方法,对以字为单位的数组,BX的移动方式
;是每移动一次加2或者减2
;另外函数调用的过程中需要小心PUSH和pop的调用是否安全,例如在name_sort中pop CX的
;时候没有先Push CX,导致了name_sort函数不可以调用
;此程序使用比较高效的方法只是对号码单的首地址进行排序,为此开辟了一个地址数组
;AdTable,类似C语言中的指针数组
;在每个名字的前面存有每个名字的长度,有利于对名字进行比较,体现了空间换时间
;程序调试难度较大,费时2天长度,长度349行
;12月7日于海韵
;==================================================================DateArea segment
TemplateName db20,?,20dup(?)
TemplateNumber db9,?,9dup(?)
PhoneTable db50dup (21dup (?),8dup (?),'$')
AdTable dw50dup (?)
FindedAdress dw1dup (?)
InputNamePrint db13,10,'Input name:','$'InputNumPrint db13,10,'Input a telephone number:','$'AskForNumPrint db13,10,'Do you want a telepment numbre:(Y/N)','$'NamePrint db13,10,'name?','$'AnswerFindedPrint db13,10,'name',16dup (20h),'tel.',13,10,'$'AnswerNoFindPrint db13,10,'NO SUCH NAME!','$'DateArea ends
;=====================================================================CodeArea segment
assume cs:CodeArea,ds:DateArea,es:DateArea
;-----------------------------main proc farpushdssubax,axpushax
mov ax,DateArea
mov ds,ax
mov es,ax
;
mov bx,0lea si,PhoneTable
Start:lea dx,InputNamePrint
mov ah,09hint21h
;
lea di,AdTable
mov AdTable[bx],si
call input_name;该函数还要返回输入字母为终止时候的提示,;可以返回一个寄存器的状态来表示
jz Search
call stor_name
;
lea dx,InputNumPrint
mov ah,09hint21h
;
call inphone
;
add si,30add bx,2jmp Start
Search:;lea dx,AskForNumPrint
;mov ah,09h
;int21h
call name_sort
lea dx,AskForNumPrint
mov ah,09hint21h
;
mov ah,1int21hsubal,4Eh
;
jzExit;
lea dx,NamePrint
mov ah,09hint21h
;
call input_name
;
call name_search
;
call printline
;
jmp SearchExit:ret
main endp
;------------------------------input_name proc nearpushaxpushbxpushcxpushdxpushsipushdi
;
lea dx,TemplateName
mov ah,0ahint21h
lea di,TemplateName
add di,1mov al,[di]
cmp al,0;popdipopsipopdxpopcxpopbxpopax
;
ret
input_name endp
;------------------------------stor_name proc nearpushaxpushbxpushcxpushdxpushsipushdi
;
mov di,AdTable[bx]
lea si,TemplateName
add si,1mov dx,21mov cl,[si]
mov al,cl
cbw
mov cx,ax
inc cxsubdx,cx
cld
repnz movsb
mov cx,dx
cld
mov al,20h
repnz stosb
;popdipopsipopdxpopcxpopbxpopax
;
ret
;
stor_name endp
;------------------------------inphone proc nearpushaxpushbxpushcxpushdxpushsipushdi
;
lea dx,TemplateNumber
mov ah,0ahint21h
;
mov di,AdTable[bx]
add di,21lea si,TemplateNumber
add si,1mov cl,[si]
mov al,cl
cbw
mov cx,ax
add si,1cld
repnz movsb
;popdipopsipopdxpopcxpopbxpopax
;
ret
inphone endp
;------------------------------name_sort proc nearpushaxpushbxpushcxpushdxpushsipushdi
lea dx,AskForNumPrint
mov ah,09hint21h
mov cx,bx
OuterSort:mov bx,0InnerSort:mov si,AdTable[bx]
add bx,2mov di,AdTable[bx]
mov al,[si]
mov dl,[di]
cmp al,dlpushcx
jg AxGrBx
mov al,dl
cbw
mov cx,ax
jmp PassAGB
AxGrBx:cbw
mov cx,ax
PassAGB:add si,1add di,1cld
repz cmpsbpopcx
jb Belower
mov ax,AdTable[bx]subbx,2mov dx,AdTable[bx]
xchg ax,dx
mov AdTable[bx],dx
add bx,2mov AdTable[bx],ax
Belower:mov ax,bx
add ax,2cmp ax,cx
jnz InnerSortsubcx,2cmp cx,2jnz OuterSortpopdipopsipopdxpopcxpopbxpopax
ret
name_sort endp
;------------------------------name_search proc nearpushaxpushbxpushcxpushdxpushsipushdi
mov ax,bx
mov bx,0mLoop:lea si,TemplateName+1mov cl,[si]pushax
mov al,cl
cbw
mov cx,ax
add cx,1popax
mov di,AdTable[bx]
cld
repz cmpsb
jz FindOutNum
add bx,2cmp bx,ax
jz FindNoNum
jmp mLoop
FindNoNum:popdipopsipopdxpopcxpopbxpopax
ret
FindOutNum:mov dx,AdTable[bx]
add dx,1mov FindedAdress,dx
;mov ah,09h
;int21hpopdipopsipopdxpopcxpopbxpopax
ret
name_search endp
;------------------------------printline proc nearpushaxpushbxpushcxpushdxpushsipushdi
jz NoFind
lea dx,AnswerFindedPrint
mov ah,09int21h
mov dx,[FindedAdress]
mov ah,09hint21h
JMP RetPlace
NoFind:lea dx,AnswerNoFindPrint
mov ah,09hint21h
RetPlace:popdipopsipopdxpopcxpopbxpopax
ret
printline endp
;------------------------------CodeArea ends
end main