📄 tel.asm
字号:
;pre define
NAMESIZE equ 21
TELSIZE equ 16
RECORD_NUM equ 128
PAGESIZE equ 18
ESC_KEY equ 1bh
RIGHT equ 'n'
LEFT equ 'p'
include macro.mac
;data
dataseg segment
records db RECORD_NUM dup(NAMESIZE dup(0),TELSIZE dup(0))
record_end db 0
len db 0
name_buf db NAMESIZE
name_len db 0
namet db NAMESIZE dup(' ')
tel_buf db TELSIZE
tel_len db 0
tel db TELSIZE dup(' ')
msg_do db 'What do your want to do?(1,2,3,or 4):$'
msg_input_name db 'Please Input a name:$'
msg_input_tel db 'Please Input a telephone number:$'
msg_continue db 'Do you want to continue(y/n)?:$'
msg_already_exist db 'already exist$'
msgw1 db '1.Add record 2.Search record 3.Print All 4.Exit$'
msg_black db ' $'
msg_title db '---------Name------------------Telephone--------$'
msg_nextpage db ' PrePage(p) NextPage(n) Quit(Esc) $'
msg_search_who db 'Who',27h,'s telephone number do you want to know?: $'
msg_not_exist db 'is not exist$'
file_name db 'c:\kecheng\hesonghua\TEL.DAT',00h
dataseg ends
stack segment
db 1024 dup(0)
top dw 0
stack ends
;code
codeseg segment
main proc far
assume cs:codeseg,ds:dataseg
start:
mov ax,dataseg
mov ds,ax
mov es,ax
mov ax,stack
mov ss,ax
lea sp,top
GMODE
TMODE
CLEARSCREEN 12,0,0,0,24,79
call Welcome
call Control
CLEARSCREEN 7,0,0,0,24,79
mov ax,4c00h
int 21h
main endp
Welcome proc near
CLEARSCREEN 21,0,0,0,0,79
LOCATE 0,10
DISPSTR msgw1
ret
Welcome endp
Control proc near
PUSHREG
rute:
CLEARSCREEN 12,22,3,0,24,79
LOCATE 3,0
DISPSTR msg_do
get_ch:
GETCH
cmp al,'1'
jz select1
cmp al,'2'
jz select2
cmp al,'3'
jz select3
cmp al,'4'
jz select4
cmp al,ESC_KEY
jz select4
jmp get_ch
select1:
;user code
DISPCHAR al
call AddRecord
jmp rute
select2:
DISPCHAR al
call SearchRecord
jmp rute
select3:
DISPCHAR al
call DispAll
jmp rute
select4:
ControlReturn:
POPREG
ret
Control endp
AddRecord proc near
PUSHREG
; mov cx,78
nextrecord:
CLEARSCREEN 12,22,3,0,24,79
LOCATE 3,0
DISPSTR msg_input_name
lea ax,name_buf
push ax
call InputStr
NEXTLINE
lea ax,namet
push ax
call FindRecord
cmp ax,-1
jnz fail
DISPSTR msg_input_tel
lea ax,tel_buf
push ax
call InputStr
NEXTLINE
jmp success
fail:
DISPSTR namet
DISPCHAR ' '
DISPSTR msg_already_exist
NEXTLINE
NEXTLINE
jmp failnext
success:
lea ax,tel
push ax
lea ax,namet
push ax
call InsertRecord
failnext:
DISPSTR msg_continue
nextch:
GETCH
cmp al,'y'
jz ok
jnz notok
ok:
jmp nextrecord
notok:
cmp al,'n'
jnz nextch
POPREG
ret
AddRecord endp
DispPage proc near;//one param is the page
LOCALENTER
push ax
mov ax,[bp+4]
mov bl,PAGESIZE
mul bl ;(ax)=the record index
mov cx,PAGESIZE
mov dl,len
mov bl,al
xor bh,bh
next_r:
cmp bl,dl
jnl DispPageReturn
push bx
call DispRecord
NEXTLINE
inc bl
loop next_r
DispPageReturn:
pop ax
LOCALLEAVE
ret 2
DispPage endp
DispAll proc near
PUSHREG
CLEARSCREEN 21,1,3+PAGESIZE+2,0,3+PAGESIZE+2,79
LOCATE 3+PAGESIZE+2,0
DISPSTR msg_black
DISPSTR msg_nextpage
HIDECUR
xor ax,ax
mov al,len
mov bl,PAGESIZE
div bl
cmp ah,0
jz notaddal
inc al
notaddal:
xor cx,cx
mov cl,al
cmp cx,0
jz notaddcx
dec cx
notaddcx:
mov bx,0
next_page:
CLEARSCREEN 12,PAGESIZE,3,0,3+PAGESIZE,79
LOCATE 3,0
DISPSTR msg_black
DISPSTR msg_title
NEXTLINE
push bx
call DispPage
next_char:
GETCH
cmp al,RIGHT
jz next_p
cmp al,ESC_KEY
jz endtitle
cmp al,LEFT
jz pre_p
jmp next_char
next_p:
inc bx
jmp loop1
pre_p:
dec bx
loop1:
cmp bx,cx
jg over
cmp bx,0
jl below
jmp next_page
over:
mov bx,cx
jmp next_page
below:
xor bx,bx
jmp next_page
endtitle:
SHOWCUR
POPREG
ret
DispAll endp
SearchRecord proc near
PUSHREG
continue_s:
CLEARSCREEN 12,22,3,0,24,79
LOCATE 3,0
DISPSTR msg_search_who
lea ax,name_buf
push ax
call InputStr
NEXTLINE
lea ax,namet
push ax
call FindRecord
cmp ax,-1
jz noperson
push ax
call DispRecord
jmp iscontinue
noperson:
DISPSTR namet
DISPSTR msg_not_exist
iscontinue:
NEXTLINE
NEXTLINE
DISPSTR msg_continue
next_char1:
GETCH
cmp al,'y'
jz continue_s_temp
jmp continue_o
continue_s_temp:
jmp continue_s
continue_o:
cmp al,'n'
jnz next_char1
POPREG
ret
SearchRecord endp
InputStr proc near ;one param is the buffer address
LOCALENTER
push ax
mov dx,[bp+4];param,buffer
mov ah,0ah
int 21h
mov si,dx
mov al,[si]
mov ah,0
mov bl,[si+1]
mov bh,0
mov cx,ax
sub cx,bx
dec cx
mov di,dx
add di,bx
add di,2
cld
mov al,' '
rep stosb
mov byte ptr [di],'$'
NEXTLINE
pop ax
LOCALLEAVE
ret 2
InputStr endp
InsertRecord proc near ;two param,two string
LOCALENTER
push ax
;bp+4,the first param;bp+6,the second param
mov al,len
mov ah,NAMESIZE+TELSIZE
mul ah
add ax,offset records
mov di,ax
mov si,[bp+4]
mov cx,NAMESIZE
cld
rep movsb
mov si,[bp+6]
mov cx,TELSIZE
rep movsb
inc len
pop ax
LOCALLEAVE
ret 4
InsertRecord endp
DispRecord proc near ;//one param,the index,a word
push bp
mov bp,sp
IRP X,<BX,CX,DX,SI,DI>
push X
endm
mov al,[bp+4]
mov bl,len
dec bl
RECORDADDR al
mov si,ax
DISPSTR msg_black
DISPSTR [si]
DISPCHAR ' '
DISPSTR msg_black
DISPSTR [si+NAMESIZE]
mov ax,-1
IRP X,<DI,SI,DX,CX,BX>
pop X
endm
pop bp
ret 2
DispRecord endp
StrCmp proc near ;three param,bufferaddr,bufferaddr,bufferlen,return -1,1,or 0 to ax
LOCALENTER
mov si,[bp+4]
mov di,[bp+6]
mov cx,[bp+8]
repe cmpsb
jg great
jl less
je equal
great:
mov ax,1
jmp StrCmpReturn
less:
mov ax,-1
jmp StrCmpReturn
equal:
mov ax,0
StrCmpReturn:
LOCALLEAVE
ret 6
StrCmp endp
FindRecord proc near ;buffer address,return index to ax,if not found return -1
LOCALENTER
mov bl,len
xor bh,bh
dec bx ;the max index of record
mov dx,0
continue:
cmp dx,bx
jg notfound
mov ax,NAMESIZE
push ax
push [bp+4]
RECORDADDR dl
push ax
call StrCmp
cmp ax,0
jz found
inc dx
jmp continue
found:
mov ax,dx
jmp FindRecordReturn
notfound:
mov ax,-1
FindRecordReturn:
LOCALLEAVE
ret 2
FindRecord endp
codeseg ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -