📄 xscjgl.asm
字号:
data segment
mess1 db '+------------------student grade management system-------------+',0ah,0dh,'$'
mess2 db '| 1.main menu: |',0ah,0dh,'$'
mess3 db '| list[l]insert:[i]delete:[d]query:[q]exit:[e]print[p]count[c]|',0ah,0dh,'$'
mess4 db '| 2.input name and grade: |',0ah,0dh,'$'
mess5 db '| name : |',0ah,0dh,'$'
mess6 db '| maths : |',0ah,0dh,'$'
mess7 db '| english : |',0ah,0dh,'$'
mess8 db '| computer: |',0ah,0dh,'$'
mess9 db '| chinese : |',0ah,0dh,'$'
mess10 db'+--------------------------------------------------------------+',0ah,0dh,'$'
mess11 db 'name Ma En Co Ch',0ah,0dh,'$'
;mess13 db ' list (l)',0ah,0dh,'$'
mess12 db 'maths <60<70<80<90<100',0ah,0dh,'$'
err1 db ' there is not this student$'
err2 db ' file close wrong$'
fname db "d:\masm\score.txt"
buffer1 db 23 dup(?)
buffeer db 0ah,0dh,'$'
buffer2 db 30 dup(?)
buffer3 db 8 dup('0')
count db 5
handle dw ?
del db 8 dup('0')
x db ?
data ends
;-------------------------------------------结构体定义
score struc
names db 15 dup(' ')
maths db 0,0
english db 0,0
computer db 0,0
chinese db 0,0
score ends;
;-------------------------------------------- ;显示界面
show macro addrs
lea dx,addrs
mov ah,9 ;显示字符串 DS:DX=缓冲区首址
int 21h
endm
;------------------------------------------------光标位置
set_p1 macro a
mov ah,2 ;光标定位
mov dh,a ;起始行
mov dl,15 ;起始列
mov bh,0
int 10h
endm
set_p2 macro
mov ah,2
mov dh,12
mov dl,2
mov bh,0
int 10h
endm
set_p3 macro
mov ah,2
mov dh,1
mov dl,15
mov bh,0
int 10h
endm
;-------------------------------------------------
clear macro ;all screen
mov al,0 ;AL滚动的行数(AL=0 卷动整个窗口
mov cl,0 ;左上角列数
mov ch,0 ;左上角行数
mov dh,24 ;右下角行数
mov dl,79 ;右下角列数
mov bh,7 ;上滚时添补空行的属性,7为正常,70为反显
mov ah,6 ;06H 直接控制台I/O DL=0FFH(输入请求) DL=字符(输出请求) AL=输入的字符
int 21h
endm
clear1 macro ;lefe screen
mov al,0
mov bh,7
mov ch,4 ;窗口坐标
mov cl,36
mov dh,10
mov dl,79
mov ah,6 ;int 10 的06H的六号功能: 窗口上卷
int 10h
endm
clear2 macro ;down screen
mov al,0
mov bh,7
mov ch,12
mov cl,0
mov dh,24
mov dl,79
int 10h
endm
;-----------------------------------------------换行的宏程序
newline macro
push ax
push dx
mov dl,0dh ;显示"/"
mov ah,2 ;显示输出 DL=显示的字符
int 21h
mov dl,0ah
mov ah,2
int 21h
pop dx
pop ax
endm
;---------------------------------------------------------
show_item macro addrs
local iloop,w10
push bx
push cx
mov bx,0
iloop: mov dl,addrs[bx] ;display char
mov ah,2
int 21h
inc bx
cmp bx,15
jl iloop
mov cx,4
w10: mov dl,' '
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
mov dl,' '
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 w10
newline
pop cx
pop bx
endm
;-----------------------------------------------------------
getin macro addrs,count2
local zeroit,lp,input_end,exit ;伪指令local是为了避免多次调用宏时标号的多重定义
push bx
push ax
mov bx,0
zeroit: mov addrs[bx],' '
inc bx
cmp bx,15
jl zeroit
mov bx,0
lp: mov ah,1 ;键盘输入并回显(al=输入字符)
int 21h
cmp al,0ah
jz input_end
cmp al,0dh
jz input_end
mov addrs[bx],al
inc bx
cmp bx,count2
jl lp
input_end: cmp al,0dh
jz exit
cmp al,0ah
jz exit
mov ah,7
int 21h
jmp input_end
exit:
pop ax
pop bx
endm
;-------------------------------------------------------
code segment
main proc far
assume cs:code,ds:data,es:data
start:
mov ax,data
mov ds,ax
mov ah,0 ;设置显示方式
mov al,3 ;3号表示以彩色文字显示
int 10h
clear ;全屏显示菜单
show mess1
show mess2
;show mess13
show mess3
show mess4
show mess5
show mess6
show mess7
show mess8
show mess9
show mess10
set_p3
w: mov ah,7 ;直接控制台I/O (不显示输入)
int 21h
cmp al,'i'
jnz n1
call insert
jmp w
n1: cmp al,'m'
jnz n2
call modify
jmp w
n2: cmp al,'d'
jnz n3
call delete
jmp w
n3: cmp al,'q'
jnz n4
call query
jmp w
n4: cmp al,'c'
jnz n5
call cot
jmp w
n5: cmp al,'p'
jnz n6
call print
jmp w
n6: cmp al,'l'
jnz n7
call list
jmp w
n7: cmp al,'e'
jz exitf
jmp w
exitf:
mov ah,4ch
int 21h
ret
main endp
;--------------------------------------------------------插入功能子程序
insert proc near
push ax
push bx
push cx
push dx
mov dx,offset fname
mov al,2 ;读/写文件(0读1写2读/写)
mov ah,3dh ;打开文件
int 21h
mov bx,ax
clear1
set_p1 4
call get_rec
;move file pointer to end
mov cx,0 ; cx:dx=位移量
mov dx,0
mov al,2 ;移动方式
mov ah,42h ;int 21的42h功能表示移动文件指针
int 21h
;write file
mov cx,23 ;写入的字节数
mov dx,offset buffer1 ;数据缓冲区地址
mov ah,40h ;int 21 的40h表示写文件
int 21h
mov ah,3eh
int 21h
set_p3
pop dx
pop cx
pop bx
pop ax
ret
insert endp
;-------------------------------------------------------
get_rec proc near
push ax
push bx
getin buffer2,15
mov bx,0
mov cx,15
continue: mov al,buffer2[bx]
mov buffer1[bx],al
inc bx
loop continue
set_p1 5
getin buffer2,2
mov al,buffer2
mov buffer1[bx],al
inc bx
mov al,buffer2+1
mov buffer1[bx],al
inc bx
set_p1 6
getin buffer2,2
mov al,buffer2
mov buffer1[bx],al
inc bx
mov al,buffer2+1
mov buffer1[bx],al
inc bx
set_p1 7
getin buffer2,2
mov al,buffer2
mov buffer1[bx],al
inc bx
mov al,buffer2+1
mov buffer1[bx],al
inc bx
set_p1 8
getin buffer2,2
mov al,buffer2
mov buffer1[bx],al
inc bx
mov al,buffer2+1
mov buffer1[bx],al
inc bx
pop bx
pop ax
ret
get_rec endp
;---------------------------------------------------------打开文件子程序
openf proc near
mov dx,offset fname ;文件偏移地址
mov al,02
mov ah,3dh
int 21h
mov handle,ax
ret
openf endp
;--------------------------------------------------------查询子程序
query proc near
push ax
push bx
push cx
push dx
clear1
clear2
mov dx,offset fname
mov al,2
mov ah,3dh
int 21h
mov bx,ax
set_p2
getin buffer1,15
lea dx,mess11
mov ah,9 ;显示字符串
int 21h
b:
mov ah,3fh
mov cx,23
mov dx,offset buffer2
int 21h
lea si,buffer2
lea di,buffer1
mov cx,15
c:
mov al,byte ptr[si]
cmp al,byte ptr[di]
jnz b
inc si
inc di
loop c
mov [buffer2+23],'$'
show_item buffer2
mov ah,3eh
int 21h
pop dx
pop cx
pop bx
pop ax
ret
query endp
;-----------------------------------------------------------修改子程序
modify proc near
push ax
push bx
push cx
push dx
clear1
set_p1 4
mov dx,offset fname
mov al,2
mov ah,3dh
int 21h
mov bx,ax
mov handle,ax
call get_rec ; contact is in buffer1
read:
mov dx,offset buffer2
mov cx,23
mov ah,3fh
int 21h
lea si,buffer2
lea di,buffer1
mov cx,15
c5:
mov dl,byte ptr[si]
cmp dl,byte ptr[di]
jnz read
inc si
inc di
loop c5
mov bx,handle
mov ah,42h
mov al,1
mov cx,0ffffh
mov dx,-23
int 21h
mov cx,23
mov dx,offset buffer1
mov ah,40h
int 21h
mov ah,3eh
int 21h
jmp exit2
exit1:
set_p2
show err1
exit2:
set_p3
pop dx
pop cx
pop bx
pop ax
ret
modify endp
;------------------------------------------------------删除子程序
delete proc near
push ax
push bx
push cx
push dx
clear1
set_p1 4
mov dx,offset fname
mov al,2
mov ah,3dh
int 21h
mov bx,ax
mov handle,ax
getin buffer1,15 ; contact is in buffer1
read5:
mov dx,offset buffer2
mov cx,23
mov ah,3fh
int 21h
lea si,buffer2
lea di,buffer1
mov cx,15
c6:
mov dl,byte ptr[si]
cmp dl,byte ptr[di]
jnz read5
inc si
inc di
loop c6
mov bx,handle
mov ah,42h
mov al,1
mov cx,0ffffh
mov dx,-8
int 21h
mov cx,8
mov dx,offset del
mov ah,40h
int 21h
mov ah,3eh
int 21h
jmp exit6
exit5:
set_p2
show err1
exit6:
set_p3
pop dx
pop cx
pop bx
pop ax
ret
delete endp
;-------------------------------------------------------------列表子程序
list proc near
push ax
push bx
push cx
push dx
clear1
clear2
set_p2
show mess11
mov dx,offset fname
mov al,2
mov ah,3dh
int 21h
mov bx,ax
again:
mov dx,offset buffer1
mov cx,23
mov ah,3fh
int 21h
cmp ax,0
jz p
show_item buffer1
jmp again
p:
mov ah,3eh
int 21h
set_p3
pop dx
pop cx
pop bx
pop ax
ret
list endp
;----------------------------------------打印子程序
print proc near
push ax
call openf
mov cl,count
mov ch,0
read2:
mov dx,offset buffer1
mov cx,type score
mov ah,3fh
int 21h
mov cx,23h
mov bx,0
next: mov ah,5 ;打印机输出
mov dl,byte ptr buffer1[bx]
int 21h
inc bx
loop next
mov ah,5
mov dl,0dh
int 21h
dec x
cmp x,0
jnz read2
mov bx,handle
mov ah,3eh
int 21h
pop ax
ret
print endp
;--------------------------------------------统计子程序
cot proc
push ax
clear2
set_p2
show mess12
mov dx,offset fname
mov ah,3dh
int 21h
mov bx,ax
mov handle,ax
read0: mov dx,offset buffer2
mov cx,23
mov ah,3fh
int 21h
mov dl,[buffer2+15]
cmp dl,'6'
jl five
cmp dl,'7'
jl six
cmp dl,'8'
jl seven
cmp dl,'9'
jl eight
inc [buffer3+4]
jmp quit
eight:
inc [buffer3+3]
jmp quit
seven: inc [buffer3+2]
jmp quit
six: inc [buffer3+1]
jmp quit
five: inc [buffer3]
quit: cmp ax,0
jnz read0
mov cx,10
a: mov dl,' '
mov ah,2
int 21h
loop a
mov bx,0
a0: mov dl,[buffer3+bx]
mov ah,2
int 21h
inc bx
mov dl,' '
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
cmp bx,5
jnz a0
mov bx,handle
mov ah,3eh
int 21h
set_p3
pop ax
ret
cot endp
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -