上学期汇编课交的大作业 .....HOHO自我感觉还不错啦...
DOS下的.....MASM5.11通过编译
;message list
dataseg segment
savebloks dw 32*6 dup (?)
titstr1 db 'Name List$'
titstr2 db 'Phone List$'
namcolor db 1eh ;name space color
phcolor db 1eh ;phone sapce color
titcolor db 01110000b ;title color
ibcolor db 01110000b ;infobox color
cmdlcolor db 00100100b ;command line color
msgcolor db 01100111b
msgadr dw 3 dup(0)
handle dw ?
showin db 1
searchstr db 30 dup(' ')
searchphone db 30 dup(' ')
searchn db 0
exactmatch db 0
lastone db 0
inputbuf db 34
actlen db ?
inputstr db 34 dup(' ')
infomsg1 db 'Info: Give your command below $'
infomsg2 db 'Warning: Unanalysable command,type again $'
infomsg3 db 'Info: Input your name below $'
infomsg4 db 'Info: Input your phone number below $'
infomsg5 db 'Info: Input the number of item you want below$'
msgempty db '<Empty List>$'
msgeol db '<End Of List>$'
msg0 db ' Welcome to use '
msg00 db ' G-Adresser 0.9 beta '
msg000 db ' Write by Gengyiting '
msgblank db ' ','$'
pathnam db 'NAME.DAT',0
msg10 db 'Press any key to continue.....'
msg1 db ' Cannot find Name.dat '
msg2 db ' Program Will Creat the File '
msg3 db ' ../NAME.DAT '
msg4 db ' Open File Successfully '
msg5 db ' Creat File Fail '
msg6 db ' Program Terminate '
msg7 db ' Creat File Successfully '
msg8 db ' Read file failed,exit '
msg9 db ' Write file failed,exit '
msgfind db ' The item you found is: '
msgferr db ' Cannot find the item '
msgferr2 db ' Check your input! '
;in big size
filebuf dw 00
arraybuf dw 250 dup(0)
itemlist db 250 dup(30 dup(0),20 dup(0))
teststr1 db 30 dup('1'),20 dup('2')
teststr2 db 30 dup('5'),20 dup('6')
dataseg ends
codeseg segment
assume cs:codeseg,ds:dataseg,es:dataseg,ss:dataseg
main proc far
push ds
xor ax,ax
push ax
mov ax,dataseg
mov ds,ax
mov es,ax
call setscrmode
call clrscr
call buildframe
lea si,msg0
mov msgadr,si
lea si,msg00
mov msgadr+2,si
lea si,msg000
mov msgadr+4,si
call showmsg
call findfile
call showitems
call getcommand ;this is the main subprogram
ret
main endp
setscrmode proc near
mov ah,0
mov al,3
int 10h
ret
setscrmode endp
clrscr proc near
mov ax,0619h
mov cx,0
mov dx,184fh
mov bh,1eh ;here is color value
int 10h
ret
clrscr endp
gotoxy proc near
push ax
push bx
mov ah,2
mov bh,0
int 10h
pop bx
pop ax
ret
gotoxy endp
hidecursor proc near
mov ah,3
mov bh,0
int 10h
or ch,30h
mov ah,1
int 10h
ret
hidecursor endp
showcursor proc near
mov bh,0
mov ah,3
int 10h
mov ah,1
mov cx,0607h
int 10h
ret
showcursor endp
waitfk proc near
mov ah,0h
int 16h
ret
waitfk endp
showmsg proc near
call hidecursor
lea si,savebloks ;save original scr
mov cx,0
mov dh,8
l1:
mov cl,0
inc dh
mov dl,23
l2:
inc dl
call gotoxy
mov ah,8
mov bh,0
int 10h
mov [si],al
inc si
mov [si],ah
inc si
inc cl
cmp cl,32
jne l2
inc ch
cmp ch,6
jne l1 ;save scr end here
mov ax,0600h ;creat a window in the scr
mov bh,msgcolor ;msgcolor
mov ch,9
mov cl,24
mov dh,14
mov dl,55
int 10h
call drawmsgbox ;creating end here
call waitfk
lea si,savebloks
mov cx,0
mov dh,8
l11:
mov cl,0
inc dh
mov dl,23
l21:
inc dl
call gotoxy
mov ah,9
mov al,[si]
inc si
mov bl,[si]
inc si
push cx
mov cx,1
mov bh,0
int 10h
pop cx
inc cl
cmp cl,32
jne l21
inc ch
cmp ch,6
jne l11
call showcursor
ret
showmsg endp
drawmsgbox proc near
mov cx,0
mov dh,9
mbl1: mov cl,0
mov dl,24
mbl2:
inc dl
call gotoxy
mov ah,0ah
mov al,'?
push cx
mov cx,1
mov bh,0
int 10h
pop cx
inc cl
cmp cl,31
jne mbl2
inc ch
add dh,5
cmp ch,2
jne mbl1
mov cx,0
mov dl,24
mbll1:
mov cl,0
mov dh,9
mbll2:
inc dh
call gotoxy
mov ah,0ah
mov al,'?
push cx
mov bh,0
mov cx,1
int 10h
pop cx
inc cl
cmp cl,5
jne mbll2
inc ch
add dl,31
cmp ch,2
jne mbll1
mov cx,1
mov bh,0
mov dh,9
mov dl,24
call gotoxy
mov ah,0ah
mov al,'?
int 10h
add dh,5
call gotoxy
mov al,'?
int 10h
add dl,31
call gotoxy
mov al,'?
int 10h
mov dh,9
mov dl,24+31
call gotoxy
mov al,'?
int 10h
mov cx,3
mov dh,9
mov dl,25
lea si,msgadr
shmsg:
inc dh
mov bp,[si]
push cx
mov cx,30
add si,2
mov bl,msgcolor
mov bh,0
mov al,0
mov ah,13h
int 10h
pop cx
loop shmsg
lea bp,msg10
mov cx,30
mov dh,13
mov dl,25
mov bl,msgcolor
and bl,0f0h
or bl,0fh
mov bh,0
mov al,0
mov ah,13h
int 10h
ret
drawmsgbox endp
findfile proc near ;find file ,exist open
mov ah,3dh ;not exist ,creat
mov al,2
lea dx,pathnam
int 21h
jc fif ;jump when file not exist
mov handle,ax
call readfile
lea si,msg4
mov msgadr,si
lea si,msgblank
mov msgadr+2,si
lea si,msg3
mov msgadr+4,si
call showmsg
ret
fif:
lea si,msg1
mov msgadr,si
lea si,msg2
mov msgadr+2,si
lea si,msg3
mov msgadr+4,si
call showmsg
mov ah,3ch
mov al,0
mov cx,0
lea dx,pathnam
int 21h
jc ffwrong
mov handle,ax
lea si,msg7 ;creatfile
mov msgadr,si
lea si,msg3
mov msgadr+2,si
lea si,msgblank
mov msgadr+4,si
call showmsg
call fillitem
ret
ffwrong:
lea si,msg5
mov msgadr,si
lea si,msg6
mov msgadr+2,si
lea si,msgblank
mov msgadr+4,si
call showmsg
call exitpro ;exit when creat failed
findfile endp
readfile proc near ;read items from file when open
mov ah,3fh
mov bx,handle
mov cx,251*2+50*250
lea dx,filebuf
int 21h
jnc rfret
lea si,msg8
mov msgadr,si
lea si,msgblank
mov msgadr+2,si
mov msgadr+4,si
call showmsg
call exitpro
rfret:
ret
readfile endp
exitpro proc near ;exit with err code
mov al,1
mov ah,4ch
int 21h
exitpro endp
fillitem proc near ;fill items when creatfile
mov bx,handle
mov ah,40h
mov cx,50*250+251*2
lea dx,filebuf
int 21h
jc fierr
ret
fierr: ;write file error
lea si,msg9
mov msgadr,si
lea si,msgblank
mov msgadr+2,si
mov msgadr+4,si
call showmsg
call exitpro
fillitem endp
getcommand proc near
call showcursor
gcinput:
mov dh,23
mov dl,0
call gotoxy
lea dx,infomsg1
mov ah,09h
int 21h
gcinputerr:
call clrcmdline
call clrinputstr
call gotoxy
mov ah,0ah
lea dx,inputbuf
int 21h
cmp actlen,0
ja getcom
jmp gcinput
getcom:
lea si,inputstr
cmp byte ptr[si],'/'
je gcnext
mov dh,23
mov dl,0
call gotoxy
lea dx,infomsg2
mov ah,09h
int 21h
jmp gcinputerr
;need coding
gcnext:
inc si
mov al,[si]
cmp al,'A'
jne gc1
cmp byte ptr filebuf,250
jae gcinput
call getname
call clrcmdline
call clrinputstr
call getphone
call additem
jmp gcinput
gc1: cmp al,'D'
jne gc2
call delitem
jmp gcinput
gc2: cmp al,'E'
jne gc3
call edititem
jmp gcinput
gc3: cmp al,'S'
jne gc4
call getname
call search
lea si,filebuf
sub di,si
shr di,1
mov ax,di
dec ax
mov bl,50
mul bl
add si,ax
add si,251*2
mov cx,30
lea di,searchstr
cld
rep movsb
mov cx,20
lea di,searchphone
cld
rep movsb
lea si,msgfind
mov msgadr,si
lea si,searchstr
mov msgadr+2,si
lea si,searchphone
mov msgadr+4,si
call showmsg
jmp gcinput
gc4: cmp al,'N'
jne gc5
call getsearchn
cmp searchn,250
jbe startsearch
mov al,byte ptr filebuf
cmp searchn,al
jbe startsearch
nomatchitem:
lea si,msgferr
mov msgadr,si
lea si,msgblank
mov msgadr+2,si
lea si,msgferr2
mov msgadr+4,si
call showmsg
jae gcinput
startsearch:
call searchnitem
cmp lastone,0ffh
je nomatchitem
lea si,filebuf
sub di,si
shr di,1
mov ax,di
dec ax
mov bl,50
mul bl
add si,ax
add si,251*2
mov cx,30
lea di,searchstr
cld
rep movsb
mov cx,20
lea di,searchphone
cld
rep movsb
lea si,msgfind
mov msgadr,si
lea si,searchstr
mov msgadr+2,si
lea si,searchphone
mov msgadr+4,si
call showmsg
jmp gcinput
gc5: cmp al,'Q'
jne gc6
call closefile
jmp gcinput
gc6:
mov dh,23
mov dl,0
call gotoxy
lea dx,infomsg2
mov ah,09h
int 21h
jmp gcinputerr
getcommand endp
clrcmdline proc near
mov dh,24
mov dl,0
call gotoxy
mov ah,9
lea dx,msgblank
int 21h
mov dh,24
mov dl,0 ;clear commandbox
call gotoxy
ret
clrcmdline endp
clrinputstr proc near
mov cx,34
lea di,inputstr
lea si,msgblank
cld
rep movsb
ret
clrinputstr endp
getname proc near
mov cx,30
lea si,msgblank
lea di,searchstr
cld
rep movsb
mov dh,23
mov dl,0
call gotoxy
lea dx,infomsg3
mov ah,09h
int 21h
getn:
call clrcmdline
mov ah,0ah
lea dx,inputbuf
int 21h
cmp actlen,0
jbe getn
cmp actlen,30
jbe getnnext
mov actlen,30
getnnext:
mov cl,actlen
mov ch,0
lea si,inputstr
lea di,searchstr
cld
rep movsb
ret
getname endp
getphone proc near
mov cx,20
lea si,msgblank
lea di,searchphone
cld
rep movsb
mov dh,23
mov dl,0
call gotoxy
lea dx,infomsg4
mov ah,09h
int 21h
getp:
call clrcmdline
mov ah,0ah
lea dx,inputbuf
int 21h
cmp actlen,0
jbe getp
cmp actlen,20
jbe getpnext
mov actlen,20
getpnext:
mov cl,actlen
mov ch,0
lea si,inputstr
lea di,searchphone
cld
rep movsb
ret
getphone endp
getsearchn proc near
mov cx,20
lea si,msgblank
lea di,searchphone
cld
rep movsb
mov dh,23
mov dl,0
call gotoxy
lea dx,infomsg5
mov ah,09h
int 21h
getpn:
call clrcmdline
mov ah,0ah
lea dx,inputbuf
int 21h
cmp actlen,0
je getpn
cmp actlen,3
jbe getpnextn
mov actlen,3
getpnextn:
mov cl,actlen
mov ch,0
lea si,inputstr
xor ax,ax
mov dx,ax
getnloop1:
mov al,[si]
and al,0fh
dec cx
cmp cx,0
je getnret
push cx
getnloop2:
mov bl,10
mul bl
loop getnloop2
pop cx
add dl,al
inc si
jmp getnloop1
getnret:
add dl,al
mov searchn,dl
ret
getsearchn endp
additem proc near
cmp byte ptr filebuf,0
je addfirst
call search ;return di
mov cx,0
ailoop:
lea si,arraybuf
add si,cx
cmp word ptr [si],0
je eailoop
add cx,2
jmp ailoop
eailoop:
shr cx,1
inc cx
push di
push si
lea si,filebuf
sub di,si
pop si
mov bx,di
shr bx,1
pop di
xor ax,ax
cmp lastone,0ffh
je addlastone
mov al,[di]
mov [si],al
mov [si+1],bl
mov [di],cl
shl al,1
mov ah,0
lea di,filebuf
add di,ax
mov [di+1],cl
mov ax,cx
dec ax
addstr:
mov bl,50
mul bl
add ax,251*2
lea di,filebuf
add di,ax
lea si,searchstr
mov cx,30
cld
rep movsb
mov cx,20
lea si,searchphone
cld
rep movsb
inc byte ptr filebuf
call showitems
ret
addfirst:
lea si,filebuf
mov byte ptr [si+1],1
mov word ptr [si+2],0ff00h
mov ax,0
jmp addstr
addlastone:
mov byte ptr[si+1],0ffh
mov [si],bl
mov [di+1],cl
mov al,cl
dec al
jmp addstr
additem endp
delitem proc near
ret
delitem endp
edititem proc near
ret
edititem endp
search proc near
mov exactmatch,0
mov lastone,0
lea si,filebuf
inc si
sealoop:
mov al,[si]
xor ah,ah
mov bx,ax
push ax
shl ax,1
lea di,filebuf
mov si,di
add di,ax
pop ax
dec ax
push bx
mov bl,50
mul bl
pop bx
add si,251*2
add si,ax
push si
push di
mov di,si
lea si,searchstr
mov cx,30
cld
repe cmpsb
pop di
pop si
ja seanext
jne searet
mov exactmatch,1
searet:
ret
seanext:
mov si,di
inc si
cmp byte ptr [si],0ffh
je lastret
jmp sealoop
lastret:
mov lastone,0ffh
ret
search endp
searchnitem proc near
mov lastone,0
lea si,filebuf
inc si
mov dl,0
nsealoop:
mov al,[si]
inc dx
xor ah,ah
mov bx,ax
push ax
shl ax,1
lea di,filebuf
mov si,di
add di,ax
pop ax
dec ax
cmp dl,searchn
je nsearet
jmp nseanext
nsearet:
ret
nseanext:
mov si,di
inc si
cmp byte ptr [si],0ffh
je nlastret
jmp nsealoop
nlastret:
mov lastone,0ffh
ret
searchnitem endp
showitems proc near
mov showin,1
lea si,filebuf
cmp byte ptr[si],0
je sempty
inc si
sloop:
mov al,[si]
xor ah,ah
push ax
shl ax,1
lea di,filebuf
mov si,di
add di,ax
pop ax
dec ax
mov bl,50
mul bl
add si,251*2
add si,ax
mov bp,si
mov al,1
mov cx,30
mov dh,showin
cmp dh,22
jb shinext
call scrollscr
shinext:
mov dl,0
mov bh,0
mov bl,namcolor
mov ah,13h
int 10h
inc showin ;increace shown items number
add bp,30
mov cx,20
mov dl,44
mov bl,phcolor
int 10h
mov si,di
inc si
cmp byte ptr[si],0ffh
je showend
jmp sloop
showend:
mov dh,showin
cmp dh,22
jb shnext2
call scrollscr
shnext2:
mov dl,0
call gotoxy
mov ah,9
lea dx,msgeol
int 21h
ret
sempty:
mov dh,1
mov dl,0
call gotoxy
lea dx,msgempty
mov ah,9
int 21h
ret
showitems endp
closefile proc near
mov ah,42h
mov al,00
mov bx,handle
mov cx,0
mov dx,0
int 21h
lea dx,filebuf
mov bx,handle
mov cx,251*2+250*50
mov ah,40h
int 21h
mov ah,3eh
int 21h
call exitpro
ret
closefile endp
buildframe proc near
mov al,1
mov ch,0
mov cl,0
mov dh,0
mov dl,79
mov bh,titcolor ;here is color value
int 10h
mov al,22
mov ch,1
mov cl,0
mov dh,22
mov dl,42
mov bh,namcolor ;here is color value
int 10h
mov cl,43
mov dl,79
mov bh,phcolor
int 10h
mov al,1
mov ch,23
mov cl,0
mov dh,23
mov dl,79
mov bh,ibcolor ;here is color value
int 10h
mov al,1
mov ch,24
mov cl,0
mov dh,24
mov dl,79
mov bh,cmdlcolor ;here is color value
int 10h
mov dh,0
mov dl,0
call gotoxy
mov ah,9
lea dx,titstr1
int 21h
mov dh,0
mov dl,43
call gotoxy
lea dx,titstr2
int 21h
ret
buildframe endp
scrollscr proc near
push ax
push bx
push cx
push dx
mov ah,6
mov al,1
mov ch,1
mov cl,0
mov dh,22
mov dl,42
mov bh,namcolor ;here is color value
int 10h
mov cl,43
mov dl,79
mov bh,phcolor
int 10h
pop dx
pop cx
pop bx
pop ax
mov showin,21
ret
scrollscr endp
codeseg ends
end main