📄 224.asm
字号:
;_____________________________________________________
data segment
mess1 db 'Please input a name:',13,10,'$'
mess2 db 'Please input a telephone number:',13,10,'$'
mess3 db 'Do you want a telephone number?(y/n)$'
mess4 db 'names tel',13,10,'$'
mess5 db 'not found',13,10,'$'
nam label byte
namemax_len db 21
name_len db ?
nam_fld db 21 dup(?)
num label byte
nummax_len db 9
num_len db ?
num_fld db 9 dup(?)
namecmp db 21 dup(' ')
telctr db 0
YorN label byte
y_max_len db 3
y_input db ?
y_fld db 1 dup(?)
;namecmp db 20 dup(?)
;telctr db 0
tel_tab db 50 dup(28 dup(' '))
telsav db 28 dup(?),13,10,'$'
crlf db 13,10,'$'
endaddr dw ?
swapped db 0
data ends
;________________________________________________________________
program segment
assume cs:program,ds:data,es:data
main proc near ;主程序
push ds
push es
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov es,ax
lea di,tel_tab
inputname: ;输入名 当输入为空时结束输入
call input
sub ax,ax
mov al,byte ptr[name_len]
cmp al,0
jz next
call stor_nam
inputnum: ;输入电话号码
call inphone
cmp [num_len],0
jz inputnum
call stor_num
jmp inputname
next:
cmp [telctr],1
jbe exit
call sort
call print
search: ;查找
lea dx,mess3
mov ah,09h
int 21h
lea dx,YorN
mov ah,0ah
int 21h
mov al,byte ptr[y_fld]
cmp al,79h
jnz exit
lea dx,crlf
mov ah,09h
int 21h
call name_search
jmp search
exit:
mov ah,4ch
int 21h
main endp
;________________________________________________________________
input proc near ;输入名字子程序
lea dx,mess1
mov ah,09h
int 21h
lea dx,[nam]
mov ah,0ah
int 21h
lea dx,crlf
mov ah,09h
int 21h
mov bh,0
mov bl,byte ptr[name_len]
mov cx,21
sub cx,bx
input20:
mov byte ptr nam_fld[bx],20h
inc bx
loop input20
ret
input endp
;________________________________________________________________
inphone proc near ; 输入号码子程序
lea dx,mess2
mov ah,09h
int 21h
lea dx,num
mov ah,0ah
int 21h
lea dx,crlf
mov ah,09h
int 21h
mov bh,0
mov bl,byte ptr[num_len]
mov cx,9
sub cx,bx
inphone20:
mov num_fld[bx],20h
inc bx
loop inphone20
ret
inphone endp
;________________________________________________________________
stor_nam proc near ;名字保存
lea si,nam_fld
cld
mov cx,10
rep movsw
ret
stor_nam endp
;________________________________________________________________
stor_num proc near ;号码保存
inc [telctr]
lea si,num_fld
cld
mov cx,4
rep movsw
ret
stor_num endp
;________________________________________________________________
name_search proc near ;按名字查找
lea dx,crlf
mov ah,09h
int 21h
call input
cld
lea si,tel_tab
sub bx,bx
mov bl,[telctr]
scopy:
mov ax,si
mov cx,20
lea di,[namecmp]
rep movsb
scmp:
mov cx,20
lea di,[namecmp]
lea si,[nam_fld]
repe cmpsb
jnz repeat
call printline
ret
repeat:
dec bl
cmp bl,0
jz sexit
mov si,ax
add si,28
jmp scopy
sexit:
lea dx,mess5
mov ah,09h
int 21h
ret
name_search endp
;________________________________________________________________
printline proc near ; 输出线
cld
mov cx,28
mov si,ax
lea di,telsav
rep movsb
lea dx,telsav
mov ah,09
int 21h
ret
printline endp
;________________________________________________________________
sort proc near ;排序子程序
sub di,56
mov [endaddr],di
s20:
mov swapped,0
lea si,tel_tab
s30:
mov cx,28
mov di,si
add di,28
mov ax,di
mov bx,si
repe cmpsb
jbe s40
call exchange
s40:
mov si,ax
cmp si,[endaddr]
jbe s30
cmp [swapped],0
jnz s20
ret
sort endp
;________________________________________________________________
exchange proc near ;交换子程序
mov cx,28
lea di,telsav
mov si,bx
rep movsb
mov cx,28
mov di,bx
rep movsb
mov cx,28
lea si,telsav
rep movsb
mov [swapped],1
ret
exchange endp
;________________________________________________________________
print proc near ;输出子程序
lea si,tel_tab
lea dx,mess4
mov ah,09h
int 21h
sub bx,bx
mov bl,[telctr]
p20:
lea di,telsav
cld
mov cx,28
rep movsb
lea dx,telsav
mov ah,09h
int 21h
dec bl
jnz p20
lea dx,crlf
mov ah,09h
int 21h
ret
print endp
;________________________________________________________________
program ends ;结束
end main
;________________________________________________________________
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -