📄 汇编编写电话号码表.asm
字号:
data segment
tel_tab db 1800 dup(' ')
tel_tab_num db 0
printfline1 db '--------------------------------------------------------------------------------$'
choosecmd0 db ' Press "1" to add a new record $'
choosecmd1 db ' press "2" to find record $'
choosecmd2 db ' press "3" to show all the records $'
choosecmd3 db ' press other keys to exit $'
printfline2 db '--------------------------------------------------------------------------------$'
inputn db 'please Input name:','$'
inputp db 'please Input a telephone number:','$'
cmd db 2,0,2 dup(?)
printf db 'name tel$'
putname db 21,0,21 dup(' ')
noname db 'The name you input is not exist!$'
yorn db 'n' ;用于判断是否找到所输入的名字
data ends
prognam segment
main proc far
assume cs:prognam,ds:data
start:
mov ax,data
mov ds,ax
addnew: ;添加新的记录
lea dx,inputn
mov ah,09h
int 21h
call stor_name
call crlf
lea dx,inputp
mov ah,09h
int 21h
call inphone
inc tel_tab_num
call name_sort
again:
call crlf
lea dx,printfline1
mov ah,09h
int 21h
lea dx,choosecmd0
mov ah,09h
int 21h
call crlf
lea dx,choosecmd1
mov ah,09h
int 21h
call crlf
lea dx,choosecmd2
mov ah,09h
int 21h
call crlf
lea dx,choosecmd3
mov ah,09h
int 21h
call crlf
lea dx,printfline2
mov ah,09h
int 21h
lea dx,cmd
mov ah,0ah
int 21h
mov bx,dx
mov dx,[bx+2] ;让用户选择下一步所要进行的动作
and dx,00ffh
cmp dl,31h
jz addnew
cmp dl,32h
jz search
cmp dl,33h
jz showall
jmp prognam_exit
showall:
lea dx,printf
mov ah,09h
int 21h
call crlf
call print_all
jmp again
search:
lea dx,inputn
mov ah,09h
int 21h
mov cx,20
mov si,0
setspace:
mov putname[si+2],' '
inc si
loop setspace
lea dx,putname
mov ah,0ah
int 21h
xor bx,bx
mov bl,putname[1]
mov putname[bx+2],'$'
call search_name
jmp again
prognam_exit:
mov ah,4ch
int 21h
stor_name proc near ;输入名字并保存到表中
mov al,tel_tab_num
mov bl,36
mul bl
mov si,ax
call crlf
mov tel_tab[si+0],21
lea dx,tel_tab[si+0]
mov ah,0ah
int 21h
xor bx,bx
mov bl,tel_tab[si+1]
mov tel_tab[si+bx+2],'$'
jmp stor_exit
call crlf
mov ah,09h
lea dx,tel_tab[si+2]
int 21h
call crlf
mov ah,02h
mov dl,tel_tab[si+2]
int 21h
stor_exit:
ret
stor_name endp
inphone proc near ;输入电话并保存到表中
mov al,tel_tab_num
mov bl,36
mul bl
mov si,ax
call crlf
mov tel_tab[si+24],9
lea dx,tel_tab[si+24]
mov ah,0ah
int 21h
xor bx,bx
mov bl,tel_tab[si+25]
mov tel_tab[si+bx+26],'$'
jmp inph_exit
call crlf
mov ah,09h
lea dx,tel_tab[si+26]
int 21h
call crlf
mov ah,02h
mov dl,tel_tab[si+26]
int 21h
inph_exit:
ret
inphone endp
name_sort proc near ;将输入的名字和电话按名字排序
xor cx,cx
mov cl,tel_tab_num
dec cx
cmp cx,0
jz sort_exit_jmp
jmp loop1
sort_exit_jmp:
jmp sort_exit
loop1: mov di,cx
mov bx,0
loop2: mov al,tel_tab[bx+2]
cmp al,tel_tab[bx+38]
jl cotinue
jz equare
jmp great
equare:
mov bp,cx
mov cx,20
mov dx,bx
next: inc bx
mov al,tel_tab[bx+2]
cmp al,tel_tab[bx+38]
jl nochange
jg yeschange
loop next
jmp nochange
yeschange:
mov cx,bp
mov bx,dx
great:
mov bp,cx
mov cx,36
mov si,bx
xchange:
mov al,tel_tab[si]
xchg al,tel_tab[si+36]
mov tel_tab[si],al
inc si
loop xchange
mov cx,bp
jmp cotinue
nochange:
mov cx,bp
mov bx,dx
cotinue:
add bx,36
loop loop2
mov cx,di
loop loop1
sort_exit:
ret
name_sort endp
print_all proc near ;排序后,打印所有已记录的名字和电话号码
xor cx,cx
mov cl,tel_tab_num
mov dl,0
print_next:
mov al,dl
mov bl,36
mul bl
mov si,ax
mov bl,dl
mov ah,09h
lea dx,tel_tab[si+2]
int 21h
mov bp,cx
xor cx,cx
mov cl,25
sub cl,tel_tab[si+1]
space_in:
mov ah,02h
mov dl,' '
int 21h
loop space_in
mov ah,09h
lea dx,tel_tab[si+26]
int 21h
call crlf
mov dl,bl
inc dl
mov cx,bp
loop print_next
ret
print_all endp
search_name proc near ;查找并打印所有符合的名字及电话号码
mov yorn,'n'
xor cx,cx
mov cl,tel_tab_num
mov bx,0
n_nmcmp:
mov si,0
mov dx,cx
mov cx,20
namecmp:
mov al,putname[si+2]
cmp al,tel_tab[bx+si+2]
jnz not_equare
inc si
loop namecmp
jmp name_equare
not_equare:
mov cx,dx
add bx,36
loop n_nmcmp
jmp name_match_exit1
name_equare:
mov di,dx
mov al,yorn
cmp al,'y'
jz lop
call crlf
mov ah,09h
lea dx,printf
int 21h
mov yorn,'y'
lop:
call crlf
mov ah,09h
lea dx,tel_tab[bx+2]
int 21h
mov bp,cx
xor cx,cx
mov cl,25
sub cl,tel_tab[bx+1]
space_in2:
mov ah,02h
mov dl,' '
int 21h
loop space_in2
mov ah,09h
lea dx,tel_tab[bx+26]
int 21h
mov dx,di
jmp not_equare
name_match_exit1:
mov al,yorn
cmp al,'y'
jz name_match_exit2
call crlf
mov ah,09h
lea dx,noname
int 21h
name_match_exit2:
ret
search_name endp
crlf proc near ;回车并换行模块
mov dl,13
mov ah,02h
int 21h
mov dl,10
mov ah,02h
int 21h
ret
crlf endp
main endp
prognam ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -