没人帮我出点子,不过我的课程设计已经做玩了。我自己把答案附上来,给需要的朋友一点帮助。
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
温馨提示:内容为网友见解,仅供参考