⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sgms.asm

📁 用汇编语言编写的一个简单的学生成绩管理系统
💻 ASM
字号:
DATA SEGMENT

msg1		db	0ah,0dh,'            Student grade management system',0ah,0dh
		db	'     this is main menu',0ah,0dh
		db	'  meau      <m>',0ah,0dh
		db	'  list      <L>',0ah,0dh
		db	'  insert    <I>',0ah,0dh
		db	'  modify    <M>',0ah,0dh
		db	'  delete    <D>',0ah,0dh
		db	'  query     <Q>',0ah,0dh
		db	'  exit      <E>',0ah,0dh
		db	0ah,0dh
		db	'*******************************************************',0ah,0dh,'$'
msgList		db	0ah,0dh,'name           Math    English Chinese ',0ah,0dh,'$'
msgModify	db	0ah,0dh,'input the line you want to modify',0ah,0dh,'$'
msgDelete	db	0ah,0dh,'input the line you want to delete',0ah,0dh,'$'
msgQuery	db	0ah,0dh,'input the name you want to query',0ah,0dh,'$'
msgStop		db	0ah,0dh,'input <g> to coutinue',0ah,0dh,'$'
notFind		db	0ah,0dh,'can not find the name you want to query',0ah,0dh,'$'
readerr1	db	'read error!',0ah,0dh,'$'
err1		db	'there is not this student',0ah,0dh,'$'
err2		db	'file close error',0ah,0dh,'$'
fname		db	'score.txt',0
handle		dw	?
find		db	?
part		db	?
line		db	3
		db	?
		db	3 dup(?)
bufferQuery	db	16
		db	?
		db	16 dup(?)
buffer1		db	41 dup(?)
buffer2		db	41
		db	?
		db	41 dup(20h)
DATA ENDS

CODE SEGMENT
	ASSUME CS:CODE,DS:DATA
MAIN PROC FAR
	mov	ax,data
	mov	ds,ax

	mov	ah,9h
	lea	dx,msg1
	int 21h

start:	mov	ah,1
	int 21h
	
	cmp	al,'m'
	JE	meau			;显示菜单

	cmp	al,'L'
	JNE	n1
	call	list			;显示学生成绩
	jmp	start

n1:	cmp	al,'I'
	JNE	n2
	call	insert
	jmp	start
	
n2:	cmp	al,'M'
	JNE	n3
	call	modify
	jmp	start

n3:	cmp	al,'D'
	JNE	n4
	call	delete
	jmp	start
	
n4:	cmp	al,'Q'
	JNE	n5
	call	query
	jmp	start
	
n5:	cmp	al,'E'
	je	end1			;退出
	jmp	start


meau:	mov	ah,9h
	lea	dx,msg1
	int 21h
	jmp	start

end1:	mov	ax,4c00h
	int 21h
MAIN ENDP

LIST PROC NEAR

	push	ax
	push	bx
	push	cx
	push	dx

	call openf			;打开文件
	mov	ah,9
	lea	dx,msgList
	int 21h

	mov	bx,handle
	mov	byte ptr part,1

again:	lea	dx,buffer1
	mov	cx,41
	mov	ah,3fh			;读文件
	int 21h
	
	mov	byte ptr buffer1[40],'$'
	cmp	ax,0
	jz	readend
	mov	ah,9
	lea	dx,buffer1
	int 21h
	call	crlf
	
	mov	al,byte ptr part
	mov	ah,0
	mov	cl,10
	div	cl
	cmp	ah,0
	jne	again1
	call	stop

again1:	inc	byte ptr part
	jmp	again

readend:mov	ah,3eh			;关闭文件
	int 21h

	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret

LIST ENDP

INSERT PROC NEAR

	push	ax
	push	bx
	push	cx
	push	dx

	mov	ah,9
	lea	dx,msgList
	int 21h

	mov	ah,10
	lea	dx,buffer2
	int 21h
	mov	word ptr buffer2[42],0a0dh

	call	crlf

	call	openf			;打开文件
	mov	bx,handle

	mov	cx,0			
	mov	dx,0			;移动0个字节
	mov	al,2			;从文件尾开始移
	mov	ah,42h			;移动文件指针
	int 21h
	
	mov	cx,41	
	lea	dx,buffer2+2
	mov	ah,40h			;写文件
	int 21h

	mov	ah,3eh
	int 21h				;关闭文件
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret

INSERT ENDP

MODIFY PROC NEAR

	push ax
	push bx
	push cx
	push dx

	mov	ah,9
	lea	dx,msgModify
	int 21h

	mov	ah,10
	lea	dx,line
	int 21h

	mov	al,line[2]
	sub	al,30h
	mov	bl,10
	mul	bl
	add	al,line[3]
	sub	al,30h
	dec	al

	mov	bl,41
	mul	bl

	mov	dx,ax
	mov	cx,0			;移动(n-1)*41个字节
	
	call	openf			;打开文件
	mov	bx,handle

	mov	al,0			;从文件头开始移
	mov	ah,42h			;移动文件指针
	int 21h

	mov	ah,9
	lea	dx,msgList
	int 21h

	mov	ah,10
	lea	dx,buffer2
	int 21h
	mov	word ptr buffer2[42],0a0dh

	call	crlf

	mov	cx,41	
	lea	dx,buffer2+2
	mov	ah,40h			;写文件
	int 21h

	mov	ah,3eh
	int 21h				;关闭文件
	pop dx
	pop cx
	pop bx
	pop ax
	ret

MODIFY ENDP

DELETE PROC NEAR

	push ax
	push bx
	push cx
	push dx

	mov	ah,9
	lea	dx,msgDelete
	int 21h

	mov	ah,10
	lea	dx,line
	int 21h

	mov	al,line[2]
	sub	al,30h
	mov	bl,10
	mul	bl
	add	al,line[3]
	sub	al,30h
	dec	al

	mov	bl,41
	mul	bl

	mov	dx,ax
	mov	cx,0			;移动(n-1)*41个字节
	
	call	openf			;打开文件
	mov	bx,handle

	mov	al,0			;从文件头开始移
	mov	ah,42h			;移动文件指针
	int 21h

	mov	cx,41
	mov	si,0
lop1:	mov	buffer1[si],20h
	inc	si
	loop	lop1

	mov	cx,41	
	lea	dx,buffer1
	mov	ah,40h			;写文件
	int 21h

	mov	ah,3eh
	int 21h				;关闭文件
	pop dx
	pop cx
	pop bx
	pop ax
	ret

DELETE ENDP

QUERY PROC NEAR

	push ax
	push bx
	push cx
	push dx

	mov	ah,9
	lea	dx,msgQuery
	int 21h

	mov	ah,10
	lea	dx,bufferQuery
	int 21h

	call	openf			;打开文件
	mov	byte ptr find,0
	
	mov	bx,handle

lop2:	lea	dx,buffer1
	mov	cx,41
	mov	ah,3fh			;读文件
	int 21h

	cmp	ax,0
	jz	endfind
	
	mov	cx,15
	mov	si,0
lop3:	mov	al,byte ptr bufferQuery[si+2]
	cmp	al,byte ptr buffer1[si]
	JNE	lop4
	inc	si
	loop	lop3

	inc	byte ptr find

	call	crlf
	cmp	find,1
	jne	next
	mov	ah,9
	lea	dx,msgList
	int 21h
	
next:	mov	byte ptr buffer1[40],'$'
	mov	ah,9
	lea	dx,buffer1
	int 21h
	call	crlf
	
lop4:	jmp	lop2

endfind:cmp	find,0
	jne	endquery
	mov	ah,9
	lea	dx,notfind
	int 21h

endquery:mov	ah,3eh
	int 21h				;关闭文件
	pop dx
	pop cx
	pop bx
	pop ax
	ret

QUERY ENDP

OPENF PROC NEAR

	push	dx
	push	ax

	lea	dx,fname
	mov	al,02h			;读写打开
	mov	ah,3dh			;打开一个已有文件
	int 21h
	mov	handle,ax

	pop	ax
	pop	dx
	ret

OPENF ENDP

CRLF PROC NEAR
	
	push	ax
	push	dx
	mov	ah,2h
	mov	dl,0ah
	int 21h
	mov	dl,0dh
	int 21h

	pop	dx
	pop	ax
	ret

CRLF ENDP

STOP PROC NEAR

	push	ax
	push	dx
	
	mov	ah,9
	lea	dx,msgStop
	int 21h

stop1:	mov	ah,1
	int 21h
	cmp	al,0dh
	jne	stop1

	pop	dx
	pop	ax
	ret

STOP ENDP
CODE ENDS
	END MAIN

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -