📄 score.asm
字号:
;学生成绩管理系统
;这个系统是我去年课程设计时做的,完成了输入姓名、成绩、列表的功能
;还有几个功能像排序、修改、打印等功能还没有完成
;QQ:52995764 呢称:刀走偏锋
;*********************************************************************
.Model small
.stack 200h
;*********************************************************************
.const
;屏幕菜单内容
szTitle db 13 dup(' '), 'Students Grade Management System', 0dh, 0ah, '$'
szInsert db 09h, 09h, '1(I): Insert one record', 0dh, 0ah, '$'
szList db 09h, 09h, '2(L): List all records', 0dh, 0ah, '$'
szQuery db 09h, 09h, '3(Q): Query by name', 0dh, 0ah, '$'
szDelete db 09h, 09h, '4(D): Delete a record by name', 0dh, 0ah, '$'
szModify db 09h, 09h, '5(M): Modify a record by name', 0dh, 0ah, '$'
szCount db 09h, 09h, '6(C): Count all records by grade', 0dh, 0ah, '$'
szPrint db 09h, 09h, '7(P): Print all records', 0dh, 0ah, '$'
szEnd db 09h, 09h, '8(E): Exit', 0dh, 0ah, '$'
szErrMsg db 'Invalid choice, Input again!', 0dh, 0ah, '$'
szRecord db 'Name', 09h, 09h, 'Chinese', 09h, 'English', 09h, 'Maths', 0dh, 0ah, '$'
szChoice db 'Input your choice: ', '$'
szNewLine db 0dh, 0ah, '$'
szNamePrmpt db 'Please input the name: ', '$'
szChPrompt db 'Please input Chinese score: ', '$'
szEnprompt db 'Please input English score: ', '$'
szMaPrompt db 'Please input Math score: ', '$'
szFileName db 'c:\wjp\score.dat', 0
szOpenErr db 'Can not open file!', 0dh, 0ah, '$'
szWriteErr db 'Can not write file!', 0dh, 0ah, '$'
nameLen db 10
del db 6 dup('0')
.data
handle dw ?
scores label byte
theName db 10 dup(' ')
ScoreCh db 0, 0
ScoreEn db 0, 0
ScoreMa db 0, 0
szBuffer db 10 dup(?)
;*********************************************************************
;--------------------------------------------------------------------
;
pushAll macro
push ax
push bx
push cx
push dx
endm
;--------------------------------------------------------------------
;
popAll macro
pop dx
pop cx
pop bx
pop ax
endm
;--------------------------------------------------------------------
;输出信息的宏
showMsg macro msgAddr
push ax
push dx
mov dx, offset msgAddr
mov ah, 9
int 21h
pop dx
pop ax
endm
;--------------------------------------------------------------------
;回车换行
newLine macro
push ax
push dx
mov dx, offset szNewLine
mov ah, 9
int 21h
pop dx
pop ax
endm
;--------------------------------------------------------------------
;判断输入的选择字符
choice macro choice1, choice2, choice3, location
cmp al, choice1
je location
cmp al, choice2
je location
cmp al, choice3
je location
endm
;--------------------------------------------------------------------
;打开文件
openFile macro fileName, attribute
mov dx, offset fileName
mov al, attribute
mov ah, 3dh
int 21h
mov handle, ax
endm
;--------------------------------------------------------------------
;
readFile macro buffer, count
mov dx, offset buffer
mov cx, count
mov ah, 3fh
int 21h
endm
;--------------------------------------------------------------------
;写文件
writeFile macro record, length
mov dx, offset record
mov cx, length
mov ah, 40h
int 21h
endm
;--------------------------------------------------------------------
;
closeFile macro file
mov bx, file
mov ah, 3eh
int 21h
endm
;--------------------------------------------------------------------
;获得输入
getIn macro addrs, count
local setItZero, input, endInput, endThis
pushAll
xor bx, bx
mov cl, count
setItZero:
mov addrs[bx], ' '
inc bx
dec cl
jnz setItZero
xor bx, bx
mov cl, count
input:
mov ah, 1
int 21h
cmp al, 0dh
je endInput
mov addrs[bx], al
inc bx
dec cl
jnz input
endInput:
cmp al, 0dh
je endThis
mov ah, 1
int 21h
jmp endInput
endThis:
popAll
endm
;--------------------------------------------------------------------
;输出学生成绩的记录
showRec macro addrs
local showName, showScore
push bx
push cx
xor bx, bx
showName:
mov dl, addrs[bx]
mov ah, 2
int 21h
inc bx
cmp bx, 10
jb showName
mov cx, 3
;mov bx, 10
showScore:
mov dl, 9
mov ah, 2
int 21h
mov dl, addrs[bx]
mov ah, 2
int 21h
inc bx
mov dl, addrs[bx]
mov ah, 2
int 21h
inc bx
loop showScore
pop cx
pop bx
endm
;--------------------------------------------------------------------
;学生信息结构体
student struc
hisName db 10 dup(?)
Chinese db 0, 0
English db 0, 0
Math db 0, 0
student ends
;*********************************************************************
.code
;--------------------------------------------------------------------
;屏幕初始化
_Screen proc
mov bh, 1eh
mov cx, 0
mov dx, 184h
mov ax, 0601h
int 10h
ret
_Screen endp
;--------------------------------------------------------------------
;显示菜单
_ShowMenu proc
newLine
showMsg szTitle
showMsg szInsert
showMsg szList
showMsg szQuery
showMsg szDelete
showMsg szModify
showMsg szCount
showMsg szPrint
showMsg szEnd
newLine
ret
_ShowMenu endp
;--------------------------------------------------------------------
;创建文件
_CreateFile proc
mov cx, 0 ;一般属性
mov dx, offset szFileName
mov ah, 3ch
int 21h
jc err
mov handle, ax
ret
err:
showMsg szOpenErr
ret
_CreateFile endp
;--------------------------------------------------------------------
;
_Compare proc
choice 'i', 'I', '1', I
choice 'l', 'L', '2', L
choice 'q', 'Q', '3', Q
choice 'd', 'D', '4', D
choice 'm', 'M', '5', M
choice 'c', 'C', '6', C
choice 'p', 'P', '7', P
choice 'e', 'E', '8', E
showMsg szErrMsg
ret
I:
call _Insert
ret
L:
call _List
ret
Q:
call _Query
ret
D:
call _Delete
ret
M:
call _Modify
ret
C:
call _Count
ret
P:
call _Print
ret
E:
call _End
ret
_Compare endp
;--------------------------------------------------------------------
;
_GetRecord proc
showMsg szNamePrmpt
getIn theName, nameLen
newLine
showMsg szChPrompt
getIn ScoreCh, 2
newLine
showMsg szEnPrompt
getIn ScoreEn, 2
newLine
showMsg szMaPrompt
getIn ScoreMa, 2
newLine
ret
_GetRecord endp
;--------------------------------------------------------------------
;插入记录
_Insert proc
pushAll
openFile szFileName, 2
mov bx, ax
call _GetRecord
;移动文件指针
mov cx, 0
mov dx, 0
mov al, 2
mov ah, 42h
int 21h
;写文件
writeFile scores, 16
writeFile szNewLine, 2
closeFile handle
popAll
ret
_Insert endp
;--------------------------------------------------------------------
;浏览成绩表
_List proc
pushAll
showMsg szRecord
openFile szFileName, 2
mov bx, ax
showRecord:
readFile scores, 18
cmp ax, 0
jz endThis
showRec scores
newLine
jmp showRecord
endThis:
closeFile handle
popAll
ret
_List endp
;--------------------------------------------------------------------
;按人名查询
_Query proc
pushAll
openFile szFileName, 2
mov bx, ax
getIn theName, 10
showMsg szRecord
nameMatch:
readFile szBuffer, 18
cmp ax, 0
je endQuery
lea si, theName
lea di, szBuffer
mov cx, 10
comp:
mov al, byte ptr[si]
cmp al, byte ptr[di]
jnz nameMatch
inc si
inc di
loop comp
mov [szBuffer+17], '$'
showRec szBuffer
endQuery:
closeFile handle
popAll
ret
_Query endp
;--------------------------------------------------------------------
;按人名删除记录
_Delete proc
pushAll
openFile szFileName, 2
mov bx, ax
getIn szBuffer, 10
match:
readFile scores, 18
cmp ax, 0
je endDelete
mov si, offset scores
mov di, offset szBuffer
mov cx, 10
;cld
;repe cmpsb
next:
mov dl, byte ptr [si]
cmp dl, byte ptr [di]
jnz match
inc si
inc di
loop next
;移动文件指针
mov bx, handle
mov al, 1
mov cx, 0ffffh
mov dx, -6
mov ah, 42h
int 21h
writeFile del, 6
closeFile handle
popAll
endDelete:
ret
_Delete endp
;--------------------------------------------------------------------
;按人名修改记录
_Modify proc
showMsg szModify
ret
_Modify endp
;--------------------------------------------------------------------
;按分数段统计人数
_Count proc
showMsg szCount
ret
_Count endp
;--------------------------------------------------------------------
;打印成绩表
_Print proc
showMsg szprint
ret
_print endp
;--------------------------------------------------------------------
;退出程序
_End proc
showMsg szEnd
mov ah, 4ch
int 21h
_End endp
;--------------------------------------------------------------------
Main proc
mov ax, @data
mov ds, ax
mov es, ax
call _CreateFile
rotate:
call _ShowMenu
showMsg szChoice
;input your choice
mov ah, 1
int 21h
newLine
call _Compare
jmp rotate
exit:
mov ah, 4ch
int 21h
Main endp
;*********************************************************************
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -