📄 cjgl.asm
字号:
;学生成绩管理系统 written by Jerry liu
student struc
sname db 6 dup(' ')
sno db 8 dup(' ')
ssxdd db 3 dup(' ')
skxwh db 3 dup(' ')
ssx db 3 dup(' ')
szh db 3 dup(' ')
scjpm db 3 dup(' ')
sjl db 3 dup(' ')
student ends
stsg segment stack 's'
dw 32 dup(?)
stsg ends
anykey macro
;push ax
mov ah,7
int 21h
;pop ax
endm
anykeyback macro
anykey
showmsg back
endm
;回车换行
crlfm macro
push ax
push dx
mov ah,9
lea dx,crlf
int 21h
pop dx
pop ax
endm
exchange macro i,j
;交换studentx中相邻表项的内容:i->前项,j->后项
;注意cmpsb过程中si,di指针的自动变化!
push cx
push si
push di
mov cx,32;t=[i],即t=前项
mov si,i
lea di,stutemp
rep movsb
mov cx,32;i=j,si->后项,即前项=后项
mov di,i ;
rep movsb
mov cx,32;j=t,di->后项,即后项=t
lea si,stutemp
rep movsb
mov swapped,1
pop di
pop si
pop cx
endm
space macro
;输出空格符
push dx
push ax
lea dx,gap
mov ah,9
int 21h
pop ax
pop dx
endm
;显示提示信息
showmsg macro n
push ax
push dx
mov ah,9
lea dx,msg&n
int 21h
pop dx
pop ax
endm
movitem macro dst,src
;movitem(int dst,int src)
push cx
push di
push si
cld
mov cx,32
lea di,[dst]
lea si,[src]
rep movsb
pop si
pop di
pop cx
endm
data segment
studentx student 30 dup(<>)
stutemp db 32 dup (0),'$';临时保存一条item信息
studisp db 39 dup(0),'$'
;---------定义名字 学号 分数的输入缓冲区---------------------------------------------------------
namepar LABEL BYTE;输入缓冲区
maxnlen db 7
namelen db ?
namefld db 7 dup(?)
numpar label byte
maxmlen db 9
numlen db ?
numfld db 9 dup(?)
sxszpar label byte
maxsxsz db 4
sxszlen db ?
sxszfld db 4 dup(?)
kxwhpar label byte
maxkxwh db 4
kxwhlen db ?
kxwhfld db 4 dup(?)
sxpar label byte
maxsx db 4
sxlen db ?
sxfld db 4 dup(?)
zhpar label byte
maxzh db 4
zhlen db ?
zhfld db 4 dup(?)
cjpmpar label byte
maxcjpm db 4
cjpmlen db ?
cjpmfld db 4 dup(?)
jlpar label byte
maxjl db 4
jllen db ?
jlfld db 4 dup(?)
;输入文件路径缓冲区
pathpar label byte
pathmax db 40
pathlen db ?
pathnam db 40 dup(?)
crlf db 13,10,'$'
titl db ' Students Database System',0DH,0AH,' ',0DH,0AH,0DH,0AH
menu1 db ' I:Insert',0DH,0AH ;menu
menu2 db ' L:Open and Browse',0DH,0AH
menu4 db ' D:Delete',0DH,0AH
menu9 db ' E:Exit and Save',0DH,0AH,'$'
mmenutip db ' choose a number from the menu above',0DH,0AH,'$'
msgprinttitle db 0DH,0AH,0DH,0AH,' name xuehao sxdd kxwh sx zh pm',0DH,0AH,'$'
gap db ' $'
cur_i dw ?
scofld db 4 dup(?)
msgnoext db 'There is no such item!',13,10,'$'
stu dw ?
stustored dw 0;已写至内存中的item数
swapped db 0
sav_cnt dw ?
stusaved dw 0;已存盘的item数
saveflag db 1;是否已存盘标志
errcde db 0;文件操作错误标志
endcde db 0;读文件结束标志
endaddr dw ?
filehandle dw ?
msg_titleln db ' --------------------------------------------------------------------',13,10,'$'
msgsepln db '--------------------------------------------------------------------',0DH,0AH,'$'
msg02 db 'Please input the new student info.',13,10,'$'
msg03 db 'Name:','$'
msg04 db 'xuehao:','$'
msg05 db 'sxddsz:','$'
msg051 db 'kxwhsz:','$'
msg052 db 'sxsz:','$'
msg053 db 'zhsz:','$'
msg054 db 'cjpm:','$'
msg055 db 'jlhao:','$'
;msg06 db 'Press any key to continue!$'
msg07 db 'Successly Saved!',13,10,'$'
msginsed db 'Successly Inserted item(s)!',13,10,'$'
msgqforins db 'Insert this item?(y/n):',13,10,'$'
msgback db 'Press any key to back.$'
msgexit db 'Press any key to exit.$'
msgdeled db 'Successly Deleted a item!',13,10,'$'
msg09 db 'students out of 30.',13,10,'$'
;msg19 db 'The scores have been sorted!',13,10,'$'
msg20 db 'There are more than 30 students.',13,10,'$'
msg21 db 'Save as:',13,10,'$'
msg22 db 'Please input the file you want to operate:',13,10,'$'
msg23 db 'Read successly!',13,10,'$'
msg233 db 'XueYuan: xinxigongcheng BanJi: zidonghua0402 RenShu: 30',13,10,'$'
msg27 db 'There isn',27h,'t any student.',13,10,'$'
msg_delnamin db 'Please input the name you want to delete:',13,10,'$'
msgstattit db 9,9,'The result of statistics is listed as follow:',13,10,'$'
msgqsave db 'The ducoment have not saved.Do you want to save it now(y/n)?','$'
opnmsg db '***Error occured while opening file***',13,10,'$'
wrtmsg db '***Error occured while writing file***',13,10,'$'
readmsg db '***Error occured while reading file***',13,10,'$'
routemsg db '***Path name is invalid***',13,10,'$'
data ends
;------------------------------------------------------------------------
code segment
assume cs:code,ds:data,ss:stsg,es:data
main proc far
start:
mov ax,data
mov ds,ax
mov es,ax
mainmenu:
mov AX,0600H ;ah=6,al=0,clear screen
mov CX,0000H;左上角:0,0
mov DX,174FH;右下角:18,4f
mov BH,07
int 10H
mov AH,02 ;set cursor
mov BH,0
mov DX,1400H
int 10H
lea DX,titl ;display menu
mov AH,9
int 21H
showmsg _titleln
lea DX,mmenutip
mov AH,9
int 21H
case: ;switch(ch=getch()) wait for selection from menu
mov ah,0
int 16h
;mov AH,1
;int 21H
cmp ah,17h;'i'
je addone
cmp ah,26h;'l'
je browse
cmp ah,20h;'d'
je delete
cmp ah,12h;'e'
je exit
addone:
call insert_in
anykeyback
jmp mainmenu
browse:
call browse_in
anykeyback
jmp mainmenu
exit:
call quit
delete:
call del_in
anykeyback
jmp mainmenu
main endp
insert_in proc near
call clear
call cursor
call near ptr input
call name_sort
;call near ptr insert
ret
insert_in endp
browse_in proc near
call near ptr clear
call near ptr cursor
call near ptr readall
call name_sort
call near ptr print
ret
browse_in endp
clear proc near
;clear screen
push ax
push bx
push cx
push dx
mov AX,0600H ;clear screen
mov CX,0
mov DX,174FH
mov BH,07
int 10H
pop dx
pop cx
pop bx
pop ax
ret
clear endp
print proc near
;void print() 输出整个studentx表
push si
push cx
push dx
push ax
cmp stustored,0
je qprint
crlfm ;回车、换行
crlfm ;
showmsg 233
showmsg printtitle
showmsg sepln;打印表头
lea si,studentx
mov cx,stustored
pline: call near ptr printline
loop pline ;没输完则循环输出
pop ax
pop dx
pop cx
pop si
qprint: ret
print endp
printline proc near
;void printline() 打印一行,需要预先设置si
push di
push cx
push dx
push ax
lea di,studisp;stutemp=studentx[i]
mov cx,6 ;每一次loop si会自动修正
rep movsb ;
mov [studisp+6],9
add di,1
mov cx,8
rep movsb
mov [studisp+15],9
add di,1
mov cx,3
rep movsb
mov [studisp+24],9
add di,1
mov cx,3
rep movsb
mov [studisp+33],9
add di,1
mov cx,3
rep movsb
mov [studisp+42],9
add di,1
mov cx,3
rep movsb
mov [studisp+51],9
add di,1
mov cx,3
rep movsb
mov [studisp+60],9
add di,1
mov cx,3
rep movsb
mov ah,9
lea dx,studisp
int 21h
crlfm
showmsg sepln
pop ax
pop dx
pop cx
pop di
ret
printline endp
readall proc near
;void readall() 从磁盘文件中读取全部item信息到内存中
push ax
mov endcde,0
call near ptr openh
cmp endcde,0
jne rexit;endcde=1,结束
mov stustored,0
contin: call near ptr readh
cmp endcde,0
jne r20;endcde=1,结束
call near ptr stor2
cmp stustored,30
ja oexit
jmp contin
r20: call near ptr clseh
call clear
call cursor
showmsg 23
jmp rexit
oexit: call near ptr clseh
mov saveflag,0
showmsg 09;
rexit: showmsg back;
;mov ah,1
;int 21h
pop ax
ret
readall endp
stor2 proc near
;void stor2() 从stutemp临时变量中往内存studentx表中写入一条item
push si
push di
push ax
push bx
push cx
cmp stutemp,0;写入item不为空
je exitt
lea si,stutemp
lea di,studentx
mov ax,stustored
mov bl,32
mul bl
add di,ax
mov cx,32;
rep movsb
inc stustored
pop cx
pop bx
pop ax
pop di
pop si
exitt: ret
stor2 endp
openh proc near
;void openh() 打开一个磁盘文件,取得文件句柄并保存
push ax
push cx
push dx
call near ptr get_path
mov ah,3dh
mov cx,0;0=读
lea dx,pathnam
int 21h
jc o1
mov filehandle,ax
pop dx
pop cx
pop ax
ret
o1: mov endcde,01;打开文件出错处理,置endcde为1
lea dx,opnmsg
call near ptr errm
pop dx
pop cx
pop ax
ret
openh endp
errm proc near
;磁盘操作的容错处理
push ax
mov ah,9
int 21h
mov errcde,01
pop ax
ret
errm endp
get_path proc near
;void get_path() 从输入端获取文件路径
push ax
push bx
push dx
showmsg 22;'Please input the file you want to operate:'
;crlfm
mov ah,0ah
lea dx,pathpar
int 21h
;crlfm
mov bl,pathlen
mov bh,0
mov pathnam[bx],0
pop dx
pop bx
pop ax
ret
get_path endp
readh proc near
;void readh() 从文件中读出一条项目到临时变量stutemp中
push ax
push bx
push cx
push dx
mov ah,3fh;read file
mov bx,filehandle
mov cx,32
lea dx,stutemp
int 21h
jc c1;如果出错输出信息
cmp ax,0
je c2;ax=0,end of file,quit
cmp stutemp,1ah;EOF Marker?
je c2
pop dx
pop cx
pop bx
pop ax
ret
c1: lea dx,readmsg
call near ptr errm
c2: mov endcde,1
pop dx
pop cx
pop bx
pop ax
ret
readh endp
clseh proc near
;void clseh() clsoe a file
push ax
push bx
mov ah,3eh
mov bx,filehandle
int 21h
pop bx
pop ax
ret
clseh endp
cursor proc near
push ax
push bx
push dx
mov ah,2
mov bh,0;bh=页号
mov dx,0;dh:row,dl:column
int 10h
pop dx
pop bx
pop ax
ret
cursor endp
name_sort proc near
;void sort() 有交换标志的冒泡排序
;注意cmpsb过程中si,di指针的自动变化!
push si
push di
push ax
push bx
push dx
push cx
cmp stustored,1
je qsort ;比较名字个数,只有一个名字无需排序,退出
lea bx,studentx
push bx
mov ax,stustored
sub ax,1
mov bl,32
mul bl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -