怎样用汇编实现简单电话簿程序设计?

怎样用汇编实现简单电话簿程序设计?,第1张

没人帮我出点子,不过纯岩哗我的课程设计已经做玩了。我自己把答案附上来,枣李给需要的朋友一点帮助。

stack segment stack

dw 512 dup(?)

stack ends

data segment

titlestr db 'Welcome to telephone directory!',0dh,0ah,'Enter your choice please!',0dh,0ah,'$'

menustr db '1:Select',0dh,0ah,'2:Insert',0dh,0ah,'3:Modify',0dh,0ah,'4:Delete',0dh,0ah,'5:Show all record',0dh,0ah,'8:Esc',0dh,0ah,'$'

namelist db 20 dup(20 dup(0))

telelist db 20 dup(20 dup(0))

newname db 20 dup(0)

newtele db 20 dup(0)

cnt db 1 dup(0)

cntselect db 1 dup(0)

choice db 1 dup(0)

enter db 0dh,0ah,'$'

disname db 'Name:$'

distele db 'Tele:$'

backstr db 'Key 6 to main menu!',0dh,0ah,'$'

disstr db 'All record!',0dh,0ah,'$'

selstr1 db '1:Select by name',0dh,0ah,'2:Select by telephone',0dh,0ah,'$'

selstr2 db 'The imformation!',0dh,0ah,'$'

selstr3 db 'Name is not exist!',0dh,0ah,'$'

selstr4 db 'Telephone is not exist!',0dh,0ah,'$'

selstr5 db 'Telephone directory is empty!',0dh,0ah,'$'

addstr1 db 'Input the newname and newtele!',0dh,0ah,'$'

addstr2 db 'Telephone directory is full!',0dh,0ah,'$'

addstr3 db 'Add successfully!',0dh,0ah,'$'

modstr1 db 'Newname:$'

modstr2 db 'Newtele:$'

modstr3 db 'Input new record!',0dh,0ah,'$'

modstr4 db 'Modified successfully!',0dh,0ah,'$'

delstr1 db 'Telephone directory is empty!',0d,0ah,'$'

delstr2 db 'Deleted successfully!',0dh,0ah,'$'

name1 db '做行aaaaaaaaa$'

name2 db 'bbbbbbbbb$'

name3 db 'ccccccccc$'

name4 db 'ddddddddd$'

name5 db 'eeeeeeeee$'

telephone1 db '11111111111$'

telephone2 db '22222222222$'

telephone3 db '33333333333$'

telephone4 db '44444444444$'

telephone5 db '55555555555$'

data ends

code segment

main proc far

assume cs:code,ds:data

displaytitle proc near

lea dx,titlestr

mov ah,9

int 21h

lea dx,menustr

int 21h

ret

displaytitle endp

cshdata proc near

mov bx,0

lea si,name1

lea di,namelist

add di,bx

mov cx,20

cshname11:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshname12

loop cshname11

cshname12:

add bx,20

lea si,name2

lea di,namelist

add di,bx

mov cx,20

cshname21:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshname22

loop cshname21

cshname22:

add bx,20

lea si,name3

lea di,namelist

add di,bx

mov cx,20

cshname31:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshname32

loop cshname31

cshname32:

add bx,20

lea si,name4

lea di,namelist

add di,bx

mov cx,20

cshname41:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshname42

loop cshname41

cshname42:

add bx,20

lea si,name5

lea di,namelist

add di,bx

mov cx,20

cshname51:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshname52

loop cshname51

cshname52:

add bx,20

mov ax,bx 初始化计数器cnt

mov bl,20

div bl

lea si,cnt

mov [si],al

mov bx,0

lea si,telephone1

lea di,telelist

add di,bx

mov cx,20

cshtele11:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshtele12

loop cshtele11

cshtele12:

add bx,20

lea si,telephone2

lea di,telelist

add di,bx

mov cx,20

cshtele21:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshtele22

loop cshtele21

cshtele22:

add bx,20

lea si,telephone3

lea di,telelist

add di,bx

mov cx,20

cshtele31:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshtele32

loop cshtele31

cshtele32:

add bx,20

lea si,telephone4

lea di,telelist

add di,bx

mov cx,20

cshtele41:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshtele42

loop cshtele41

cshtele42:

add bx,20

lea si,telephone5

lea di,telelist

add di,bx

mov cx,20

cshtele51:

mov al,[si]

mov [di],al

inc si

inc di

cmp al,'$'

jz cshtele52

loop cshtele51

cshtele52:

add bx,20

ret

cshdata endp

disdata proc near

lea dx,disstr

mov ah,09h

int 21h

lea si,cnt

mov cl,[si]

mov bx,0

disdata1:

lea dx,disname

mov ah,09h

int 21h

lea dx,namelist

add dx,bx

mov ah,09h

int 21h

lea dx,enter

mov ah,09h

int 21h

lea dx,distele

mov ah,09h

int 21h

lea dx,telelist

add dx,bx

mov ah,09h

int 21h

lea dx,enter

mov ah,09h

int 21h

add bx,20

loop disdata1

ret

disdata endp

adder proc near

lea si,cnt 判断电话簿是否已满

mov al,[si]

cmp al,20

jb adder5

lea dx,addstr2

mov ah,09h

int 21h

jmp adder6

adder5: lea dx,addstr1

mov ah,09h

int 21h

lea dx,disname

mov ah,09h

int 21h

mov cl,19

lea si,newname

adder1: mov ah,01h

int 21h

cmp al,0dh

je adder2

mov [si],al

inc si

loop adder1

adder2: mov al,24h

mov [si],al

lea si,cnt 计算目的地址的偏移量

mov bl,[si]

xor ax,ax

mov al,20

mul bl

lea si,newname

lea di,namelist

add di,ax

mov cx,20

cld

rep movsb

lea dx,enter

mov ah,09h

int 21h

lea dx,distele

mov ah,09h

int 21h

mov cl,19

lea si,newtele

adder3: mov ah,01h

int 21h

cmp al,0dh

je adder4

mov [si],al

inc si

loop adder3

adder4: mov al,24h

mov [si],al

lea si,cnt

mov bl,[si]

xor ax,ax

mov al,20

mul bl

lea si,newtele

lea di,telelist

add di,ax

mov cx,20

cld

rep movsb

lea dx,enter

mov ah,09h

int 21h

lea si,cnt 计数器加1

mov al,[si]

inc al

mov [si],al

lea dx,addstr3

mov ah,09h

int 21h

lea si,newname

mov cx,20

adder7:

mov al,0

mov [si],al

inc si

loop adder7

lea si,newtele

mov cx,20

adder8:

mov al,0

mov [si],al

inc si

loop adder8

adder6: ret

adder endp

selbyname proc near

lea si,cnt

mov al,[si]

cmp al,0

ja selname6

lea dx,selstr5

mov ah,09h

int 21h

jmp selname5

selname6:

lea dx,disname

mov ah,09h

int 21h

lea si,newname

mov cx,19

selname1:

mov ah,01h

int 21h

cmp al,0dh

je selname2

mov [si],al

inc si

loop selname1

selname2:

mov al,24h

mov [si],al

lea dx,enter

mov ah,09h

int 21h

lea si,cnt 设置循环次数

mov dx,[si]

mov bx,0

selname3:

lea si,newname

lea di,namelist

add di,bx

mov cx,20

cld

repe cmpsb

jz selname4

add bx,20

dec dx

cmp dx,0

jnz selname3

lea dx,selstr3 记录不存在

mov ah,09h

int 21h

jmp selname5

selname4:

lea dx,selstr2 存在

mov ah,09h

int 21h

lea dx,disname

mov ah,09h

int 21h

lea dx,namelist

add dx,bx

mov ah,09h

int 21h

lea dx,enter

mov ah,09h

int 21h

lea dx,distele

mov ah,09h

int 21h

lea dx,telelist

add dx,bx

mov ah,09h

int 21h

lea dx,enter

mov ah,09h

int 21h

mov ax,bx 计算器记录查询到的是第几个

mov bl,20

div bl

inc al

lea si,cntselect

mov [si],al

selname5:

lea si,newname

mov cx,20

selname7:

mov al,0

mov [si],al

inc si

loop selname7

ret

selbyname endp

selbytele proc near

lea si,cnt

mov al,[si]

cmp al,0

ja seltele6

lea dx,selstr5

mov ah,09h

int 21h

jmp seltele5

seltele6:

lea dx,distele

mov ah,09h

int 21h

lea si,newtele

mov cx,19

seltele1:

mov ah,01h

int 21h

cmp al,0dh

je seltele2

mov [si],al

inc si

loop seltele1

seltele2:

mov al,24h

mov [si],al

lea dx,enter

mov ah,09h

int 21h

lea si,cnt 设置循环次数

mov dx,[si]

mov bx,0

seltele3:

lea si,newtele

lea di,telelist

add di,bx

mov cx,20

cld

repe cmpsb

jz seltele4

add bx,20

dec dx

cmp dx,0

jnz seltele3

lea dx,selstr4 记录不存在

mov ah,09h

int 21h

jmp seltele5

seltele4:

lea dx,selstr2 存在

mov ah,09h

int 21h

lea dx,disname

mov ah,09h

int 21h

lea dx,namelist

add dx,bx

mov ah,09h

int 21h

lea dx,enter

mov ah,09h

int 21h

lea dx,distele

mov ah,09h

int 21h

lea dx,telelist

add dx,bx

mov ah,09h

int 21h

lea dx,enter

mov ah,09h

int 21h

seltele5:

lea si,newname

mov cx,20

seltele7:

mov al,0

mov [si],al

inc si

loop seltele7

ret

selbytele endp

select proc near

select1:

lea dx,selstr1

mov ah,09h

int 21h

mov ah,01h

int 21h

cmp al,'1'

jz select2

cmp al,'2'

jz select3

jmp select1

select2:

call clear

call selbyname

jmp select4

select3:

call clear

call selbytele

select4: ret

select endp

modify proc near

call selbyname

lea si,cntselect

mov al,[si]

cmp al,0

jz modify5

lea dx,modstr3

mov ah,09h

int 21h

lea dx,modstr1

mov ah,09h

int 21h

lea si,newname

mov cx,20

modify1:

mov ah,01h

int 21h

cmp al,0dh

jz modify2

mov [si],al

inc si

loop modify1

modify2:

mov al,24h

mov [si],al

lea dx,enter

mov ah,09h

int 21h

jmp modify6

modify5:

jmp modify7

modify6:

lea dx,modstr2

mov ah,09h

int 21h

lea si,newtele

mov cx,20

modify3:

mov ah,01h

int 21h

cmp al,0dh

jz modify4

mov [si],al

inc si

loop modify3

modify4:

mov al,24h

mov [si],al

lea dx,enter

mov ah,09h

int 21h

lea si,cntselect 计算被修改数据的偏移量ax

mov al,[si]

dec al

mov bl,20

mul bl

lea si,newname 把新名字拷入

lea di,namelist

add di,ax

mov cx,20

cld

rep movsb

lea si,newtele 把新号码拷入

lea di,telelist

add di,ax

mov cx,20

cld

rep movsb

lea si,cntselect 计数器清0

mov ax,0

mov [si],ax

lea dx,modstr4

mov ah,09h

int 21h

modify7:

lea si,newname

mov cx,20

modify8:

mov al,0

mov [si],al

inc si

loop modify8

lea si,newname

mov cx,20

modify9:

mov al,0

mov [si],al

inc si

loop modify9

ret

modify endp

delete proc near

lea si,cnt

mov al,[si]

cmp al,0

ja delete1

lea dx,delstr1

mov ah,09h

int 21h

jmp delete2

delete1:

call selbyname

lea si,cntselect

mov al,[si]

cmp al,0

jz delete1

lea si,cntselect 计算要删除数据的偏移量bx

mov cl,[si]

dec cl

mov al,20

mul cl

mov bx,ax

lea si,cnt 计算最后一个数据的偏移量dx

mov cl,[si]

dec cl

mov al,20

mul cl

mov dx,ax

lea si,namelist

lea di,namelist

add si,dx

add di,bx

mov cx,20

cld

rep movsb

lea si,telelist

lea di,telelist

add si,dx

add di,bx

mov cx,20

cld

rep movsb

lea si,cnt 计数器减1

mov al,[si]

dec al

mov [si],al

lea si,cntselect cntselect清零

mov al,0

mov [si],al

lea dx,delstr2

mov ah,09h

int 21h

delete2: ret

delete endp

clear proc near

mov ah,0fh

int 10h

mov ah,0

int 10h

ret

clear endp

start:

mov ax,data

mov ds,ax

mov es,ax

call cshdata

menu1:

call clear

call displaytitle

mov ah,01h

int 21h

cmp al,'1'

jz sel

cmp al,'2'

jz adde

cmp al,'3'

jz modi

cmp al,'4'

jz del

cmp al,'5'

jz dis

cmp al,'8'

jz out1

jmp menu1

sel:

call clear

call select

jmp back

adde:

call clear

call adder

jmp back

modi:

call clear

call modify

jmp back

del:

call clear

call delete

jmp back

dis:

call clear

call disdata

back:

lea dx,backstr 返回主菜单提示语“Please enter 6 to bace main menu!”

mov ah,09h

int 21h

mov ah,01h

int 21h

lea si,choice

mov [si],al

cmp al,'6'

jz menu1 输入6,返回主菜单

call clear

jmp back

out1:

main endp 主函数结束

code ends

end start

最好先自己写,不正冲敏确贴上来我没给你参谋一下~

先给你一段参考,试着自己改改吧~

#include<iostream>

using namespace std

struct tel

{

char name[20]

char number[15]// 此处用用字符型处理数字

}

void search1(tel toatal[],char name[], int n)

{

int intsearch=0

for(int i=0i<ni++)

{

if(strcmp(toatal[i].name,name)==0)//姓名的精确查找

{

cout<<"你输入的姓名是:"<<toatal[i].name<<" "<<"对应的号码是:"<<toatal[i].number<<endl

intsearch++

}

}

if(intsearch==0)

{

cout<<"对不起,你输入的姓名没有在资料库里面,请重新选择功能1键,进行重新查找"<<endl

}

}

void search2(tel toatal[],char number[], int n)//号码的精确查找

{

int intsearch=0

for(int i=0i<ni++)

{

if(strcmp(toatal[i].number,number)==0)

{

cout<<toatal[i].name<<" "<<toatal[i].number<<endl

intsearch++

}

}

if(intsearch==0)

cout<<"对不起,没有你要找的记录"<<endl

else

cout<<"共找到了"<<intsearch<<"条记录"<<endl

}

void search3(tel toatal[],char name[], int n)//姓名模糊查询

{

int intsearch=0

for(int i=0i<ni++)

{

if((toatal[i].name[0]==name[0])&&(toatal[i].name[1]==name[1]))// 直接判断

{

cout<<"姓名:"<<toatal[i].name<<" "<<"学号:"<<键判镇toatal[i].number<<endl

intsearch++

}

}

if(intsearch==0)

cout<<"对不起,没有找到相关的记录!"<<endl

else

cout<<"总共找到"<<intsearch<<"记录"<<endl

}

void search4(tel toatal[],char number[], int n)//号码的模糊查询

{

int intsearch=0

for(int i=0i<ni++)

for(int j=0j<3j++)

{

if(toatal[i].number[j]==number[j])//此可以把号码前三位一样的输出

{

if(j==2)

{

cout<<"学号对应的姓名:"<<toatal[i].name<<" "<<"对应的学号是"<<toatal[i].number<<endl

intsearch++

}

}

else

break

}

if(intsearch==0)

cout<<"对不起,没有这样的学号"<<endl

else

cout<<"总共找到"<<intsearch<<"条记录"<<endl

}

main()

{

tel toatal[100]

char name[10], number[15]

int i=0

int iSelect

cout<<"请输入数据:"<<endl

cout<<"注释:当输入的姓名为0时,而且输入的学号为0时,输入结束"<<endl

for(i<100i++)

{

cout<<"请输入第稿粗"<<i+1<<"个姓名:"

cin>>toatal[i].name

cout<<endl

cout<<"请输入第"<<i+1<<"个号码:"

cin>>toatal[i].number

cout<<endl

if(toatal[i].name[0]=='0')

break

}

cout<<"please input the number that your want to do:"<<endl

cout<<"***********************************"<<endl

cout<<" ***0:退出查询系统***"<<endl

cout<<"***********************************"<<endl

cout<<" ***1:姓名精确查找***"<<endl

cout<<"***********************************"<<endl

cout<<" ***2:号码精确查找***"<<endl

cout<<"***********************************"<<endl

cout<<" ***3:姓名模糊查找***"<<endl

cout<<"***********************************"<<endl

cout<<" ***4:号码模糊查找***"<<endl

cout<<"***********************************"<<endl

cout<<"****** ****** "<<endl

while(cin>>iSelect)

{

switch(iSelect)

{

case 0:

cout<<"!!!"<<endl

return 0

case 1:

cout<<"enter the search name(请输入要寻找的姓名信息):::"<<endl//姓名的精确查找,输入全名

cin>>name

search1(toatal,name,i)

break

case 2:

cout<<"enter the search number(请输入要寻找的学号信息):::"<<endl//号码的精确查找,输入全号码

cin>>number

search2(toatal,number,i)

break

case 3:

cout<<"enter the vague name(请输入一个姓氏):::"<<endl//姓名模糊查找,只输入姓

cin>>name

search3(toatal,name,i)

break

case 4:

cout<<"enter the vague number(请输入号码的前三位):::"<<endl//号码模糊查找,只输入号码前三位

cin>>number

search4(toatal,number,i)

break

default :

cout<<"please input the right number!!"<<endl

break

}

cout<<"请输入你要选择的功能键(0---4)"<<endl

}

}

你好, 你是想实现一个具有查询功能的不带数据库的小程序吧?

这样给你写有点不可能:里面难点给你写出来思升好高路

1.这里袜信用text记事本代替数据库实现这个功能(程序打开可能会有2s加载时间)

2.使用open函数 打开并且写入数据;建议人名+电话号;

3.每次打开时候加载text 也是可以用open

4.获取到open的数据 并用split(string,"")分开,再通过 +

分开人名和电话 得到一个2维数组

5.遍历这个数组 和你要查询人名做出匹配

ok

祝楼主好吵尺运


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8234145.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存