;***************************************************************
;查找电话号码
;程序接收输入人名和相应的电话号码
;程序可接收需要查找电话号码的人名,按一定格式在屏幕上显示出来
;author:野渡无人
;create date:2007-12-20
;***************************************************************
data segment
No_of_name dw 15
No_of_phone dw 12
total dw 27
cnt_name db ? ;count of input name
inbuf label byte
maxlen db 15
buff_len db ?
buffer db 15 dup(20)
tel_tab db 21 dup(27 dup(?))
message1 db 'please input name:','$'
message2 db 'please input a telephone number:','$'
message3 db ' NAME',10 dup(20h),' TEL.',13,10,'$'
message4 db 'input name? (Y/N) :','$'
message5 db 'Do you want a telephone number? (Y/N) : ','$'
message6 db 'name?','$'
message7 db 'Sorry!There is not such a name!',13,10,'$'
errormessage db 'Input a wrong letter!Input Y(y) or N(n)',13,10,'$'
crlf db 13,10,'$'
flag db ?
input_flag db ?
name_cnt db 10 ;max number of name allowed
swapped db ? ;judge whether exchange happens
search_flag db ? ;=1 stands for search succeed
cmp_flag dw ?
error_flag dw ? ;judge whether error happens
data ends
;**************************************************************
prog segment
;--------------------------------------------------------------
main proc far
assume cs:prog,ds:data
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov flag,0
mov cnt_name,0
input_rotate:
call input_name ;input a name into buffer
inc cnt_name
call stor_name ;store name into tel_tab
call inphone ;add a phone into tel_tab to the according name
;cmp cnt_name,1
;jbe continue
continue:
lea dx,message4 ;input name?
mov ah,09
int 21h
call judge ;judge if input continue
cmp error_flag,1
je continue
cmp input_flag,1
je input_rotate ;Yes,input continue
call name_sort
call printline
search_rotate:
lea dx,message5 ;want a telephone number?
mov ah,09
int 21h
call judge ;judge if want a telephone number
cmp error_flag,1
je search_rotate
cmp input_flag,1
jne exit ;No,exit
lea dx,message6 ;prompt,name?
mov ah,09
int 21h
call input_name ;input a name into buffer
call name_search ;search the name and his telephone
jmp search_rotate
exit:
ret
main endp
;---------------------------------------------------------
input_name proc near
push ax
push dx
lea dx,message1 ;prompt,input name:
mov ah,09
int 21h
mov ah,0ah
lea dx,inbuf
int 21h
mov ah,09
lea dx,crlf
int 21h
mov bh,0
mov bl,buff_len
mov cx,No_of_name
sub cx,bx
input_loop:
mov buffer[bx],20h
inc bx
loop input_loop
pop dx
pop ax
ret
input_name endp
;------------------------------------------------------------
stor_name proc near
push ax
push dx
push cx
push bx
mov dh,0
mov dl,cnt_name
dec dl
mov di,0
mov si,0
mov ax,total
mul dl
add di,ax
mov cx,no_of_name
stor_rotate:
mov bl,buffer[si]
mov tel_tab[di],bl
inc di
inc si
loop stor_rotate
pop bx
pop cx
pop dx
pop ax
ret
stor_name endp
;-------------------------------------------------------------
inphone proc near
push ax
push dx
push cx
lea dx,message2 ;prompt,input telephone number:
mov ah,09
int 21h
mov dl,cnt_name
dec dl
mov di,No_of_name
mov si,0
mov ax,total
mul dl
add di,ax
mov cx,No_of_phone
inphone_rotate:
mov ah,01
int 21h
mov tel_tab[di],al
inc di
loop inphone_rotate
mov ah,09
lea dx,crlf
int 21h
pop cx
pop dx
pop ax
ret
inphone endp
;---------------------------------------------------------
name_sort proc near
push ax
push bx
push cx
push dx
mov swapped,0
mov ch,0
mov cl,cnt_name
dec cl
name_sort_loop:
mov bx,cx
mov cx,0
name_sort_loop1:
mov di,0
mov ax,total
mul cl
inc cl
add di,ax
mov si,di
sub si,total
mov cmp_flag,0
name_sort_loop2:
mov dl,tel_tab[di]
cmp dl,tel_tab[si]
jb name_sort_continue
ja name_sort_continue1
inc di
inc si
inc cmp_flag
mov ax,cmp_flag
cmp ax,No_of_name
jbe name_sort_loop2
name_sort_continue:
call name_exchange
name_sort_continue1:
cmp cx,bx
jbe name_sort_loop1
mov cx,bx
;cmp swapped,0
loop name_sort_loop
pop dx
pop cx
pop bx
pop ax
ret
name_sort endp
;---------------------------------------------------------
name_exchange proc near
push dx
push cx
mov cx,total
sub cx,cmp_flag
name_exchange_rotate:
mov dl,tel_tab[di]
xchg dl,tel_tab[si]
mov tel_tab[di],dl
inc di
inc si
loop name_exchange_rotate
mov swapped,1
pop cx
pop dx
ret
name_exchange endp
;---------------------------------------------------------
printline proc near
push ax
push dx
push cx
lea dx,message3
mov ah,09
int 21h
mov bh,cnt_name
print_again:
mov bl,cnt_name
sub bl,bh
mov di,0
mov ax,total
mul bl
add di,ax
mov cx,total
print_rotate:
mov ah,02
mov dl,tel_tab[di]
int 21h
inc di
loop print_rotate
dec bh
cmp bh,0
mov ah,09
lea dx,crlf
int 21h
jnz print_again
mov ah,09
lea dx,crlf
int 21h
pop cx
pop dx
pop ax
ret
printline endp
;------------------------------------------------------------
name_search proc near
push ax
push bx
push cx
mov search_flag,0
mov cx,No_of_name
mov bh,cnt_name
name_search_rotate:
mov ax,total
cmp bh,0
jbe name_search_judge
dec bh
mov si,0
mov di,0
mul bh
add di,ax
name_search_continue:
mov bl,tel_tab[di]
cmp bl,buffer[si]
jne name_search_rotate
inc di
inc si
loop name_search_continue
mov search_flag,1
name_search_judge:
cmp search_flag,1
jne name_search_failed
mov ah,09
lea dx,message3
int 21h
mov cx,total
mov ax,total
mov di,0
mul bh
add di,ax
name_search_print:
mov ah,02
mov dl,tel_tab[di]
int 21h
inc di
loop name_search_print
mov ah,09
lea dx,crlf
int 21h
jmp name_search_exit
name_search_failed:
mov ah,09
lea dx,message7
int 21h
name_search_exit:
pop cx
pop bx
pop ax
ret
name_search endp
;---------------------------------------------------------
judge proc near
mov error_flag,0
mov ah,01
int 21h
cmp al,'Y'
je judge_continue1
cmp al,'y'
je judge_continue1
cmp al,'N'
je judge_continue2
cmp al,'n'
je judge_continue2
mov ah,09
lea dx,crlf
int 21h
mov ah,09
lea dx,errormessage
int 21h
mov error_flag,1
jmp judge_exit
judge_continue1:
mov input_flag,1
jmp judge_exit
judge_continue2:
mov input_flag,0
judge_exit:
mov ah,09
lea dx,crlf
int 21h
ret
judge endp
;----------------------------------------------------------
prog ends
;*********************************************************
end main