学生成绩管理(8086汇编)

原本想写个完整的学生成绩管理系统,不过想想还是算了,所以此程序就没有使用文件及链表什么的,仅作为基本练习,演示了成绩管理基本功能、分页显示数据、文本选单。

 

.model small

;***************************************
;定义学生结构体类型
student struc
   id     dw  0  ;学号
   sname  db  16 dup('$')  ;姓名
   score  dw  0  ;分数
   order  dw  0  ;排名
student ends
;***************************************


;***************************************
;回车换行
newline macro
   push ax
   push dx
   mov ah,2
 mov dl,0dh
 int 21h
 mov ah,2
 mov dl,0ah
 int 21h
 pop dx
 pop ax
 endm
;***************************************

COUNT equ 30 ;学生人数
LIMIT equ 300  ;分数上限

.stack 200h
.data
   str1   db "student (ID: ",'$'
   str2   db ") score: ",'$'
   str3   db "ID name score order",0dh,0ah,'$'
   space  db " ",'$'
   tip1   db "Student ID: ",'$'
   tip2   db "Name: ",'$'
   tip3   db "Score: ",'$'
   error1 db "Not found! Please input again.",0dh,0ah,'$'
   error2 db "Too high. Please input again.",0dh,0ah,'$'
   menu1  db "   ***************************************",0dh,0ah
          db "   *                                     *",0dh,0ah
          db "   *   1.input score                     *",0dh,0ah
          db "   *   2.modify                          *",0dh,0ah
          db "   *   3.display                         *",0dh,0ah
          db "   *   4.quit                            *",0dh,0ah
          db "   ***************************************",0dh,0ah,'$'        
   buf    db 16
   len    db 0
   buffer db 16 dup('$')
   temp   student <>
 array  student <1,"Tom">
        student <2,"Jack">
        student <3,"Rose">
        student <4,"Lusy">
        student <5,"Lily">
        student <6,"David">
        student <7,"Tim">
        student <8,"Ana">
        student <9,"Ivy">
        student <10,"Joe">
        student <11,"John">
        student <12,"Joson">
        student <13,"Lulu">
        student <14,"Kitty">
        student <15,"Kite">
        student <16,"Joy">
        student <17,"Jill">
        student <18,"Bily">
        student <19,"Bill">
        student <20,"Jane">
        student <21,"Bean">
        student <22,"Iris">
        student <23,"Ishara">
        student <24,"Jamie">
        student <25,"Jenny">
        student <26,"Judy">
        student <27,"June">
        student <28,"Kate">
        student <29,"Linda">
        student <30,"Lisa">
 
.CODE

;***************************************
;读取正整数子程序
;功能描述:进行过滤性输入,非法字符不会接收及被显示,以回车键结束输入;
;         按退格键可以删除之前输入的数字,按ESC键则结束子程序并置DX为1
;入口参数:无
;出口参数:AX=所接收的整数值,DX=0|1(1表示输入了ESC字符,0表示没有)

read proc
   local flag: WORD
   push di
   push si
   push bx
   push cx
   xor di,di
a00:  
   mov flag,0
a10:
   mov ah,8
   int 21h
   inc flag
   cmp al,1Bh
   je  a50
   cmp al,8
   jne a01
   cmp flag,1
   je  a00
   test di,di
   jz  a00
   dec di
   pop ax
   mov ah,2
   mov dl,8
   int 21h
   mov ah,2
   mov dl,' '
   int 21h
   mov ah,2
   mov dl,8
   int 21h
   jmp a10
a01:  
   cmp al,0Dh
   jne a11
   cmp flag,1
   je  a00
   jmp a20
a11:  
   cmp al,30h
   jb  a10
   cmp al,39h
   ja  a10
   mov ah,2
   mov dl,al
   int 21h
   sub al,30h
   xor ah,ah
   push ax
   inc di
   jmp a10
a20:
   xor bx,bx
   mov si,10
   xor cx,cx
a21:  
   pop ax
   push cx
   test cx,cx
   jz  a40
a30:  
   mul si
   loop a30
a40:
   pop cx
   inc cx
   add bx,ax
   dec di
   test di,di
   jnz a21
   xor dx,dx
   mov ax,bx
   jmp a60
a50:
   xor ax,ax
   mov dx,1
a60:  
   pop cx
   pop bx
   pop si
   pop di
   ret
read endp
;***************************************


;***************************************
;显示正整数子程序
;功能描述:以十进制方式输出任意的16位正整数
;入口参数:AX=要输出的整数

write proc
  push si
  push bx
  push cx
  push dx
  xor si,si
 mov bx,10
tostring:
   xor dx,dx
 div bx
 add dx,30h
 push dx
 inc si
 test ax,ax
 jnz tostring
 mov cx,si
display:
 pop ax
 mov ah,2
 mov dl,al
 int 21h
 loop display
 pop dx
 pop cx
 pop bx
 pop si
 ret
write endp
;***************************************


;***************************************
;清屏子程序

cls proc
   push ax
   push bx
   push cx
   push dx
   mov ax,3
   int 10h
   mov ah,6
   xor al,al
   mov bh,1fh
   xor cx,cx
   mov dx,184fh
   int 10h
   pop dx
   pop cx
   pop bx
   pop ax
   ret
cls endp
;***************************************


;***************************************
;输入分数子程序

input proc
   push si
   push di
   push cx
   push dx
   call cls
   xor si,si
   mov di,1
   mov cx,COUNT
b10:
   lea dx,str1
   mov ah,9
   int 21h
   mov ax,di
   call write
   inc di
   lea dx,str2
   mov ah,9
   int 21h
   call read
   cmp dx,1
   je  over
   cmp ax,LIMIT
   jb  b11
   newline
   dec di
   lea dx,error2
   mov ah,9
   int 21h
   newline
   jmp b10
b11:  
   mov array[si].score, ax
   newline
   add si,size student
   loop b10
over: 
   pop dx
   pop cx
   pop di
   pop si
   ret
input endp
;***************************************


;***************************************
;显示记录子程序
;功能描述:显示一个结构体变量的值
;入口参数:BX=结构体变量的地址

ShowMsg proc
   push ax
   push dx
   mov ax,(student ptr [bx]).id
   call write
   lea dx,space
   mov ah,9
   int 21h
   lea dx,(student ptr [bx]).sname
   mov ah,9
   int 21h
   lea dx,space
   mov ah,9
   int 21h
   mov ax,(student ptr [bx]).score
   call write
   lea dx,space
   mov ah,9
   int 21h
   mov ax,(student ptr [bx]).order
   call write
   pop dx
   pop ax
   ret
ShowMsg endp
;***************************************


;***************************************
;输出子程序
;功能描述:在屏幕上显示最多20条记录
;入口参数:SI=结构数组起始下标

PageScreen proc
   push si
   push ax
   push bx
   push cx
   push dx
   cmp si,COUNT
   jae quit 
   call cls
   lea dx,str3
   mov ah,9
   int 21h
   mov ax,si
   mov si,size student
   mul si
   mov si,ax
   mov cx,20
disp:  
   lea bx,array[si]
   call ShowMsg
   newline
   add si,size student
   cmp si,size student*(COUNT-1)
   jg  quit  
   loop disp
quit:  
   pop dx
   pop cx
   pop bx
   pop ax
   pop si
   ret
PageScreen endp
;***************************************


;***************************************
;分屏显示子程序
;功能描述:分屏显示数据,按'a'键向上翻页,'d'向下翻页,'w'上移一条记录,'s'下移一条记录

output proc
   push si
   push ax
   xor si,si
   call PageScreen
last0:  
   mov ah,7
   int 21h
   cmp al,1Bh
   je last4  
   cmp al,'d'
   jne last1
   add si,20
   cmp si,COUNT
   jle c00
   mov si,COUNT
c00:  
   call PageScreen
   jmp last0
last1:  
   cmp al,'a'
   jne last2
   sub si,20
   cmp si,0
   jge c01
   xor si,si
c01:  
   call PageScreen
   jmp last0
last2:  
   cmp al,'s'
   jne last3
   inc si
   cmp si,COUNT
   jle  c03
   mov si,COUNT
c03:  
   call PageScreen
   jmp last0
last3:  
   cmp al,'w'
   jne last0
   mov bx,si
   dec si
   cmp si,0
   jge  c04
   xor si,si
c04:
   call PageScreen
   jmp last0
last4:
   pop ax
   pop si
   ret
output endp
;***************************************


;***************************************
;结构体值对换子程序
;功能描述:交换两个结构变量的值
;入口参数:SI=结构变量1的地址,DI=结构变量2的地址

swap proc
   push ax
   push bx
   push dx
   mov ax,si
   mov bx,di
   cld
   lea di,temp
   mov cx,size student
   rep movsb
   mov si,bx
   mov di,ax
   mov cx,size student
   rep movsb
   lea si,temp
   mov di,bx
   mov cx,size student
   rep movsb
   pop dx
   pop bx
   pop ax
   ret
swap endp
;***************************************


;***************************************
;排序子程序
;功能描述:根据成绩对学生结构数组进行排序

sort proc
   local m: WORD
   mov m,size student
   push ax
   push bx
   push cx
   push dx
   push si
   push di
   xor cx,cx
outer:  
   mov bx,cx
   inc bx
inner:  
   mov ax,cx
   mul m
   mov si,ax
   mov ax,bx
   mul m
   mov di,ax
   mov ax,array[si].score
   cmp ax,array[di].score
   jbe next
   push si
   push di
   lea si,array[si]
   lea di,array[di]
   call swap
   pop di
   pop si
next: 
   inc bx
   cmp bx,COUNT
   jb inner
   inc cx
   cmp cx,COUNT
   jb  outer
   pop di
   pop si
   pop dx
   pop cx
   pop bx
   pop ax
   ret
sort endp
;***************************************


;***************************************
;排名子程序
;功能描述:根据学生成绩进行排名

ranking proc
   push si
   push ax
   push bx
   mov si,(COUNT-1)*size student
   mov bx,1
   mov ax,array[si].score
lop: 
   cmp ax,array[si].score
   je  step
   inc bx
step:  
   mov array[si].order,bx
   mov ax,array[si].score
   sub si,size student
   cmp si,0
   jge lop
   pop bx
   pop ax
   pop si
   ret
ranking endp
;***************************************


;***************************************
;修改学生信息子程序

modify proc
   push ax
   push bx
   push dx
   push si
   push di
   call cls
again1:  
   lea dx,tip1
   mov ah,9
   int 21h
   call read
   newline
   cmp dx,1
   je  overall
   test ax,ax
   jz b00  
   cmp ax,COUNT
   jbe b01
b00:  
   lea dx,error1
   mov ah,9
   int 21h
   newline
   jmp again1
b01:  
;   dec ax
;   mov si,size student
;   mul si
   call search
   mov si,ax
   lea dx,tip2
   mov ah,9
   int 21h
   lea dx,buf
   mov ah,0ah
   int 21h
   mov cl,len
   xor di,di
   xor bx,bx
copy1:  
   mov al,buffer[di]
   mov array[si].sname[bx],al
   inc di
   inc bx
   loop copy1
   newline
again2:  
   lea dx,tip3
   mov ah,9
   int 21h
   call read
   newline
   cmp dx,1
   je  overall
   cmp ax,LIMIT
   ja  b02
   mov array[si].score,ax
   jmp overall
b02:  
   lea dx,error2
   mov ah,9
   int 21h
   newline
   jmp again2
overall:  
   pop di
   pop si
   pop dx
   pop bx
   pop ax
   ret
modify endp
;***************************************


;***************************************
;搜索子程序
;入口参数:AX=学生学号
;出口参数:AX=所找到的学生记录在数组中的索引

search proc
   push si  
   xor si,si
tofind:  
   cmp ax,array[si].id
   je  found
   add si,size student
   cmp si,size student*COUNT
   jb  tofind
found:  
   mov ax,si
   pop si
   ret
search endp
;***************************************


;***************************************
;主菜单程序

menu proc
   push ax
   push dx
step0:  
   call cls
   lea dx,menu1
   mov ah,9
   int 21h
   mov ah,8
   int 21h
   cmp al,'1'
   jne step1
   call input
   jmp step0
step1:  
   cmp al,'2'
   jne step2
   call modify
   jmp step0
step2:  
   cmp al,'3'
   jne step3
   call sort
   call ranking
   call output
   jmp step0
step3:
   pop dx
   pop ax
   ret
menu endp
;***************************************


START:
 mov ax,@data
 mov ds,ax
 mov es,ax
 call menu
 mov ah,4ch
 int 21h 
END START

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章