logo资料库

简易电话号码簿程序设计.doc

第1页 / 共8页
第2页 / 共8页
第3页 / 共8页
第4页 / 共8页
第5页 / 共8页
第6页 / 共8页
第7页 / 共8页
第8页 / 共8页
资料共8页,全文预览结束
简易电话号码簿程序设计 一、设计目标 编写一个管理电话号码的程序。 二、设计要求 1. 实现人名、电话号码的录入(假定一个人只有一个电话号码)。 2. 人名、电话号码的删除、修改。 3. 根据人名查询该人的电话号码。 4. 用文件保存电话簿。 5. 根据电话号码查询该人的名字。 6. 根据人名进行电话号码的模糊查询(如输入某人的姓,则同姓的其他人的电话号码也可 以显示出来)。 三、设计提示 文件操作、键盘操作和屏幕操作可利用 DOS 和 BIOS 系统中断完成。相关核心提示见“单 词记忆测试器程序设计”一题。 DATAS SEGMENT count db 4 buf db 'li 'liu 'hu 'zhang 20 dup(10 dup (0),10 dup (0)) ', ;存储人名和电话号码的数据单元区 ','54698765 ','69856456 ', ','565664789 ', ','569874123 ', ;为再存入数据开辟空间 _name db 10, ?,10 dup(?) num db 10, ?,10 dup(?) ;缓冲区——键盘输入name字符串 ;缓冲区——键盘输入num字符串 { this main menu } ; 缓冲区——存入人名和电话簿信息 (people phonenumber management system)',0ah,0dh temp db 20 dup(?),0dh,0ah,'$' menuitem db ' db ' db ' db ' db ' db ' db ' db ' db ' db 'please select(q,i,m,d or e):',0ah,0dh,'$' @************************&&&**************************@',0ah,0dh #',0ah,0dh # #',0ah,0dh # #',0ah,0dh # # #',0ah,0dh #',0ah,0dh # # #',0ah,0dh @************************&&&**************************@',0ah,0dh 1. query 2. insert 3. modify 4. delete 5. exit is (q) (i) (m) (d) (e) ;显示主菜单相关信息 mess1 mess2 mess3 mess4 mess5 mess6 mess7 mess8 mess9 db 'name',10 dup(' '),'tel',0ah,0dh,'$' db 'please Input the name:$' db 'please Input the telephone number:$' db 0ah,0dh,'$' ;专门定义一个MESS4,以便在代码中用9号功能调用实现换行 db 'Insert succed!$' db 'delete succed!$' db 'the information!$' db 'modify succed!$' db 'please Input the new name:$' 1
mess10 db'please Input the new number:$' err1 DATAS ENDS db 'there is not exsit the people!',0ah,0dh,'$' ;错误提示信息 STACKS SEGMENT db 2000 dup(?) STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS main proc far ;显示主菜单选择界面 ;从键盘输入字符 ;若所输字符是‘q‘,则调用子程序 query ; 若所输字符是‘i‘,则调用子程序 insert n1 mov ax,datas mov ds,ax mov es,ax lea dx,menuitem mov ah,9 int 21h mov ah,1 int 21h cmp al,'q' jnz n2 call query jmp cmp al,'i' jnz call insert jmp cmp al,'m' jnz n4 call modify cmp al,'d' jnz n5 call delete cmp al,'e' jz jmp exit n3 n1 n1 n1: n2: n3: n4: n5: exit: mov ah,7 int 21h mov ah,4ch int 21h ret main endp query proc near push ds ;退出 ;查找的主程序 2
xor ax,ax push ax mov ax,datas mov ds,ax mov es,ax cld lea dx,mess4 mov ah,9 int 21h lea dx,mess2 mov ah,9 int 21h call ipname lea dx,mess4 mov ah,9 int 21h call search mov ah,7 int 21h ret query endp ipname proc near lea dx,_name mov ah,10 int 21h mov bh,0 mov bl,_name+1 mov cx,10 sub cx,bx r: mov _name[bx+2],20h inc bx loop r ret ipname endp search proc near di,buf lea push di mov mov bh,0 bl,count ;清除方向标志 ;换行 ;调用子程序 ipname,从键盘上输入人名 ;具体查找的子程序 ;从键盘输入名字 ;存放待查找的人名地址 ;bl 存放从键盘输入的字符串长度 ;计算剩下的长度 ;剩下的地方补空格 ;di 中存放表首地址 l: lea si,_name+2 mov cx,10 repe cmpsb jz n6 ;比较 si 和di的前10个字节 ;不相等时不跳转 3
n6: pop di add di,20 push di dec bx jnz l lea dx,err1 mov ah,9 int 21h jmp n1 pop di mov si,di lea di,temp mov cx,20 rep movsb lea dx,mess1 mov ah,9 int 21h lea dx,temp mov ah,9 int 21h ret search endp insert proc near lea dx,mess4 mov ah,9 int 21h lea dx,mess2 mov ah,9 int 21h lea dx,mess4 mov ah,9 int 21h call ipname lea dx,mess4 mov ah,9 int 21h lea dx,mess3 mov ah,9 int 21h call ipnumber cld mov al,20 mov cl,count mul cl lea di,buf ;di 偏移地址加20 ;提示‘找不到。。‘信息 ; 将人名和号码信息传入 temp ;输出temp中的 人名和号码 ;调用输入人名的子程序 ;调用输入号码的子程序 ;ax 存放 buf里已有数据的字节数 4
;将di移动指向数据单元中的已经存入的最后人的电话后 ;将 si 中数据(人名) 传 di中 ;再传数据(号码)到 di中 ;count 加一条记录 add di,ax lea si,_name+2 mov cx,10 rep movsb lea si,num+2 mov cx,10 rep movsb inc count lea dx,mess5 mov ah,9 int 21h lea dx,mess4 mov ah,9 int 21h mov ah,7 int 21h ret insert endp ipnumber proc near ;从键盘输入号码 ;存放待存入的电话号码 ;存放从键盘输入的字符串长度 lea dx,num mov ah,10 int 21h lea dx,mess4 mov ah,9 int 21h mov bh,0 mov bl,num+1 mov cx,10 sub cx,bx mov num[bx+2],20h ;补空格 inc bx loop c1 ret c1: ipnumber endp delete proc near lea dx,mess4 mov ah,9 int 21h lea dx,mess2 mov ah,9 int 21h lea dx,mess4 mov ah,9 int 21h call ipname lea dx,mess4 5
;di 中存放表首地址 ;比较 si 和di的前10个字节 ;不相等时不跳转 ;di 偏移地址加20 ;提示‘找不到。。‘信息 mov ah,9 int 21h call delete1 ret delete endp delete1 proc near di,buf lea push di mov mov bh,0 bl,count p: a: a lea si,_name+2 mov cx,10 repe cmpsb jz pop di add di,20 push di dec bx jnz p lea dx,err1 mov ah,9 int 21h jmp n1 pop di lea dx,mess4 mov ah,9 int 21h lea dx,mess7 mov ah,9 int 21h lea dx,mess4 mov ah,9 int 21 ;计算最后一个数据的偏移量dx mov al,20 mov cl,count dec cl mul cl mov dx,ax lea si,buf add si,dx mov cx,20 cld 6
rep movsb dec count lea dx,mess6 mov ah,9 int 21h lea dx,mess4 mov ah,9 int 21h mov ah,7 int 21h ret delete1 endp modify proc near lea dx,mess4 mov ah,9 int 21h lea dx,mess2 mov ah,9 int 21h call ipname lea dx,mess4 mov ah,9 int 21h call modify1 lea dx,mess4 mov ah,9 int 21h lea dx,mess8 mov ah,9 int 21h lea dx,mess4 mov ah,9 int 21h mov ah,7 int 21h ret modify endp modify1 proc near di,buf lea push di mov mov bh,0 bl,count ;di 中存放表首地址 m: lea si,_name+2 mov cx,10 repe cmpsb ;比较 si 和di的前10个字节 7
;不相等时不跳转 ;di 偏移地址加20 ;提示‘找不到。。‘信息 n: n jz pop di add di,20 push di dec bx jnz m lea dx,err1 mov ah,9 int 21h jmp n1 pop di lea dx,mess4 mov ah,9 int 21h lea dx,mess9 mov ah,9 int 21h call ipname lea dx,mess4 mov ah,9 int 21h lea dx,mess10 mov ah,9 int 21h call ipnumber lea si,_name+2 mov cx,10 cld rep movsb ;将 si 中数据(人名) 传 di中 lea si,num+2 mov cx,10 cld rep movsb ret modify1 endp ;再传数据(号码)到 di中 codes ends end main ;程序结束 8
分享到:
收藏