;
;******************************************
DATA SEGMENT
PHONE STRUC ;定义结构 struct phone
name db 20 dup (?)
no db 9 dup (?)
PHONE ENDS
tel_tab PHONE 50 dup (< >)
phone_num db 0 ;记录电话簿已存电话数目
;
temp_name db 21
actlen_name db ?
str_name db 21 dup (?)
;
temp_no db 9
actlen_no db ?
str_no db 9 dup (?)
;
menu_msg db 'Please select menu:(1,2) ?: $'
prompt1_msg db 'Iput name: $'
prompt2_msg db 'Iput a telephone number: $'
prompt3_msg db 'Do you want a telephone number?(Y/N): $'
prompt4_msg db 'Name ? $'
continue_msg db 'Continue (Y/N)? $'
err_msg db 'error,please input (Y/N) or (1/2) ?',0dh,0ah,'$'
DATA ENDS
;***********************************************
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
;-----------------------------------------------
MAIN PROC FAR
start:
push ds
sub ax,ax
push ax
;
mov ax,DATA
mov ds,ax
;
LP1:
lea dx,menu_msg ;显示菜单
mov ah,9
int 21h
call DISP_MENU
mov ah,01
int 21h
cmp al,'0'
je last
cmp al,'1'
jne select
cmp al,'2'
jne error
select:
and al,0fh
dec al
call ;地址转移
jmp LP1
error:
call ERR
last:
ret
MAIN ENDP
;**************************************************
;输入电话信息: 姓名,电话号码
INPUT_TELE PROC NEAR
push ax
push dx
LP1:
lea dx,prompt1_msg
mov ah,9
int 21h
call CRLF
call INPUT_NAME
call STORE_NAME
lea dx,prompt2_msg
mov ah,9
int 21h
call INPHONE
inc phone_num ;
call NAME_SORT
lea dx,continue_msg
mov ah,9
int 21h
mov ah,01
int 21h
cmp al,'N'
je last
cmp al,'Y'
je LP1
call ERR
last:
pop dx
pop ax
ret
INPUT_TELE ENDP
;**************************************
SEARCH PROC NEAR
push ax
push dx
LP1:
lea dx,prompt3_msg
mov ah,9
int 21h
mov ah,01
int 21h
cmp al,'N'
je last
cmp al,'Y'
jne error
;
lea dx,prompt4_msg
mov ah,9
int 21h
call INPUT_NAME
call NAME_SEARCH
call PRINTLINE
lea dx,continue_msg
mov ah,9
int 21h
mov ah,01
int 21h
cmp al,'N'
je last
cmp al,'Y'
je LP1
error:
call ERR
last:
pop dx
pop ax
ret
SEARCH ENDP
;--------------------------------------
;显示错误信息
ERR PROC NEAR
push ax
push dx
lea dx,err_msg
mov ah,9
int 21h
mov ah,4ch
int 21h
pop dx
pop ax
ret
ERR ENDP
;======================================
INPUT_NAME PROC NEAR
push ax
push dx
lea dx,temp_name ;先将姓名输入到缓冲区中
mov ah,0ah
int 21h
pop dx
pop ax
ret
INPUT_NAME ENDP
;-----------------------------------------
STORE_NAME PROC NEAR
push si
push di
push cx
push bx
mov cl,actlen_name
mov ch,0
lea si,str_name
mov bl,phone_num
mov bh,0
lea di,tel_tab[bx].name
cld
rep movsb ;再从缓冲区传输到电话簿中
pop bx
pop cx
pop di
pop si
ret
STORE_NAME ENDP
;--------------------------------------
INPHONE PROC NEAR
push ax
push dx
push si
push di
push cx
push bx
lea dx,temp_no ;先将电话号码输入到缓冲区中
mov ah,0ah
int 21h
mov cl,actlen_no
cmp cl,9
jne error
mov ch,0
lea si,str_no
mov bl,phone_num
mov bh,0
lea di,tel_tab[bx].no
cld
rep movsb ;再从缓冲区传输到电话簿中
jmp last
error:
call ERR
last:
pop bx
pop cx
pop di
pop si
pop dx
pop ax
ret
INPHONE ENDP
;--------------------------------------
;电话簿排序,采用插入排序,以后可以考虑用 Shell 排序和 Quick 排序
NAME_SORT PROC NEAR
NAME_SORT ENDP
;--------------------------------------
;--------------------------------------
CRLF PROC NEAR
push ax
push dx
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop dx
pop ax
ret
CRLF ENDP
;-------------------------------------
CODE ENDS
;************************************************
end start