📄 tele.asm
字号:
data segment
inf0 db 'Input the ',?,?,?,?,'H name:$'
inf1 db 'Input a telephone number:$'
inf2 db 'add a telephone number?(Y or y to continue)$'
inf3 db 'find a telephone number?(N or n to exit)$'
inf4 db 'name?$'
inf5 db 'name',17 dup(0),'$'
inf6 db 'tel.',4 dup(0),'$'
inf7 db 'the name of you input is not exist',13,10,'$'
db 20 dup (0),'$',10 dup(0),'$'
tel_tab db 50 dup(20 dup (0),'$',10 dup(0),'$')
cur_loca dw 0
tab_size dw 0
name_tempin label byte
namaxlen db 20
nafaclen db ?
name_temp db 20 dup(0)
num_tempin label byte
numaxlen db 10
nufaclen db ?
num_temp db 10 dup(0)
temp db 32 dup(0)
boolin label byte
bomaxlen db 2
bofaclen db ?
bool db 2 dup(0)
found db 0
data ends
code segment
main proc far
assume cs:code,ds:data,es:data
start:
push ds
sub ax, ax
push ax
mov ax, data
mov ds, ax
mov es, ax
continue_add:
call newline
mov bx, tab_size
inc bx
call binihex
lea dx, inf0
mov ah, 09h
int 21h
call input_name
call stor_name
call newline
lea dx, inf1
mov ah, 09h
int 21h
call inphone
call name_sort
call newline
lea dx, inf2
mov ah, 09h
int 21h
lea dx, boolin
mov ah, 0ah
int 21h
cmp bool[0], 'Y'
jz continue_add
cmp bool[0], 'y'
jz continue_add
call print_all
continue_find:
call newline
lea dx, inf3
mov ah, 09h
int 21h
lea dx, boolin
mov ah, 0ah
int 21h
cmp bool[0], 'N'
jz exit
cmp bool[0], 'n'
jz exit
call newline
lea dx, inf4
mov ah, 09h
int 21h
call input_name
call name_search
call newline
call printline
jmp continue_find
exit:
ret
main endp
input_name proc near
call newline
call clear_name_temp
mov ah, 0ah
lea dx, name_tempin
int 21h
mov bl, nafaclen
and bx, 00ffh
mov cl, namaxlen
dec cl
fill_name:
mov name_temp[bx], 0
cmp bl, cl
jz exit_inputname
inc bl
jmp fill_name
exit_inputname:
ret
input_name endp
stor_name proc near
lea di, tel_tab
add di, cur_loca
lea si, name_temp
mov cl, nafaclen
and cx, 00ffh
rep movsb
ret
stor_name endp
inphone proc near
call newline
call clear_num_temp
mov ah, 0ah
lea dx, num_tempin
int 21h
mov bl, nufaclen
and bx, 00ffh
mov cl, numaxlen
dec cl
fill_num:
mov num_temp[bx], 0
cmp bl, cl
jz exit_inputnum
inc bl
jmp fill_num
exit_inputnum:
lea di, tel_tab
add di, cur_loca
add di, 21
lea si, num_temp
mov cl, nufaclen
and cx, 00ffh
rep movsb
add cur_loca, 32
inc tab_size
ret
inphone endp
name_sort proc near
mov bx, tab_size
cmp bx, 1
jbe exit_sort
lea di, temp
lea ax, tel_tab
add ax, cur_loca
sub ax, 32
mov dx, ax
mov si, ax
mov cx, 32
rep movsb
comp_again:
sub ax, 32
dec bx
mov cx, 32
lea si, temp
mov di, ax
repz cmpsb
ja move_before
jmp comp_again
move_before:
add ax, 32
cmp bx, 0
jnz move
mov bx, tab_size
dec bx
jmp move_again
move:
mov cx, tab_size
sub cx, bx
mov bx, cx
sub bx, 1
cmp bx, 0
jz exit_sort
move_again:
cmp bx, 0
jz move_last
mov di, dx
mov si, di
sub si, 32
mov cx, 32
rep movsb
sub dx, 32
dec bx
jmp move_again
move_last:
lea si, temp
mov di, ax
mov cx, 32
rep movsb
exit_sort:
ret
name_sort endp
name_search proc near
mov found, 0
lea bx, tel_tab
mov cx, tab_size
find:
mov di, bx
lea si, name_temp
push cx
mov cx, 20
repz cmpsb
pop cx
jz found_name
add bx, 32
loop find
jmp end_search
found_name:
mov found, 1
end_search:
ret
name_search endp
printline proc near
cmp found, 0
jz not_found
call newline
lea dx, inf5
mov ah, 09h
int 21h
lea dx, inf6
mov ah, 09h
int 21h
call newline
mov dx, bx
mov ah, 09h
int 21h
add dx, 21
int 21h
jmp end_print
not_found:
lea dx, inf7
mov ah, 09h
int 21h
end_print:
ret
printline endp
newline proc near
mov dl, 0dh
mov ah, 02h
int 21h
mov dl, 0ah
mov ah, 02h
int 21h
ret
newline endp
newtable proc near
mov dl, 09h
mov ah, 02h
int 21h
ret
newtable endp
;...........................................
;result is left in BX register
binihex proc near
mov ch, 4 ;2 times
mov cl, 4 ;move 4 bit
sub ax, ax ;move zero into ax
sub si, si ;clear si
mov si, 10
rotate:
rol bx, cl
mov dl, bl
and dl, 0fh
add dl, 30h
cmp dl, 3ah
jl tochar
add dl, 07h
tochar:
mov inf0[si], dl ;move result into char_res for show
inc si
dec ch
jnz rotate
ret
binihex endp
clear_name_temp proc near
mov di, 0
mov cx, 20
clear_name:
mov name_temp[di], 0
inc di
loop clear_name
ret
clear_name_temp endp
clear_num_temp proc near
mov di, 0
mov cx, 8
clear_num:
mov num_temp[di], 0
inc di
loop clear_num
ret
clear_num_temp endp
print_all proc near
mov cx, tab_size
lea bx, tel_tab
next_name:
call newline
mov dx, bx
mov ah, 09h
int 21h
add dx, 21
int 21h
add bx, 32
loop next_name
ret
print_all endp
code ends
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -