文章目录
前言
汇编综合实验–学生管理系统
一、程序完整的代码
代码如下(示例):
DATA SEGMENT
STRING_1 DB "********************************","$"
STRING_2 DB "ENTER YOUR PIN ","$"
STRING_3 DB "1.Input message","$"
STRING_4 DB "2.Score sort","$"
STRING_5 DB "3.Failed in statistics","$"
STRING_6 DB "4.Output","$"
STRING_14 DB "5.Average","$"
STRING_7 DB "6.Delete","$"
STRING_18 DB "7.Insertion!","$"
STRING_19 DB "8.Modify!","$"
STRING_15 DB "9.BREAK!","$"
STRING_8 DB "INPUT NAME: ","$"
STRING_9 DB "INPUT NUM: ","$"
STRING_10 DB "INPUT SCORE: ","$"
STRING_11 DB "NAME: ","$"
STRING_12 DB " NUM: ","$"
STRING_13 DB " SCORE: ","$"
STRING_16 DB "INPUT NAME(DELECT): ","$"
STRING_20 DB "INPUT NAME(MODIFY): ","$"
STRING_17 DB "INPUT MESSAGE(INSERTION): ","$"
FIRST DB "usename: ","$"
SECOND DB "password: ","$"
NAME1 DB 'yy'
PASSWORD DB '123456'
TEMPNAME DB 15,?,15 dup (?)
TEMPPASSWORD DB 15 dup (?)
WELCOME DB 'welcome!','$'
ERROR DB "ERROR!","$"
SUM DW ?
SAVERAGE DB 'Average: ','$'
NUMPASS DW ?
NUM DW 4
ARRAY DB 10 DUP(?)
SUNP DB 'Number of fails: ','$'
NAMES DB 120 DUP(?)
NUMS DB 120 DUP(?)
FINDNAME DB 10 DUP(?)
SUNF DB "UNFOUND","$"
SUNS DB "SUCCESSFUL !","$"
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
CALL PIN
CMP BX,1
JE BREAK
WHILE:
CALL MENU
MOV AH,01H
INT 21H
SUB AL,30H
CALL CASE
CMP AL,9
JNE WHILE
BREAK:
MOV AH,4CH
INT 21H
PIN PROC NEAR
MOV DX,OFFSET STRING_2
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET FIRST
MOV AH,09H
INT 21H
MOV AH,0AH
MOV DX,OFFSET TEMPNAME
INT 21H
CMP BYTE PTR TEMPNAME+1,02H
JNE EXIT1
MOV CX,2
MOV SI,OFFSET NAME1
MOV DI,OFFSET TEMPNAME+2
CLD
REPE CMPSB
JNZ EXIT1
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,09H
MOV DX,OFFSET SECOND
INT 21H
MOV SI,OFFSET TEMPPASSWORD
MOV CX,0
INTPUTPASS:
MOV AH,07H
INT 21H
MOV [SI],AL
CMP AL,0DH
JE CONTINUEP
MOV AH,2
MOV DL,'*'
INT 21H
INC SI
INC CX
JMP INTPUTPASS
CONTINUEP:
CMP CX,06H;
JNZ EXIT1
MOV CX,6
MOV SI,OFFSET PASSWORD
MOV DI,OFFSET TEMPPASSWORD
MOV AX,DATA
CLD
REPE CMPSB
JNZ EXIT1
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,09H
MOV DX,OFFSET WELCOME
INT 21H
JMP OUT1
EXIT1:
MOV BX,1
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,09H
MOV DX,OFFSET ERROR
INT 21H
OUT1:
RET
PIN ENDP
MENU PROC NEAR
PUSH DX
PUSH AX
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_1
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_3
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_4
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_5
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_6
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_14
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_7
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_18
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_19
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_15
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_1
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
POP AX
POP DX
RET
MENU ENDP
CASE PROC NEAR
PUSH AX
MOV BL,1
CMP AL,BL
JNE CASE2
MOV DL,0AH
MOV AH,02H
INT 21H
MOV CX,NUM
MOV DI,0
NEXTYY:
CALL INPUTS
INC DI
LOOP NEXTYY
MOV DL,0AH
MOV AH,02H
INT 21H
JMP EXIT
CASE2:
MOV BL,2
CMP AL,BL
JNE CASE3
CALL SORTS
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET SUNS
MOV AH,09H
INT 21H
JMP EXIT
CASE3:
MOV BL,3
CMP AL,BL
JNE CASE4
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FUNPASS
JMP EXIT
CASE4:
MOV BL,4
CMP AL,BL
JNE CASE5
MOV CX,NUM
MOV DI,0
CONTINUEOUTPUTS:
CALL OUTPUTS
INC DI
LOOP CONTINUEOUTPUTS
MOV DL,0AH
MOV AH,02H
INT 21H
JMP EXIT
CASE5:
MOV BL,5
CMP AL,BL
JNE CASE6
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FAVERAGE
JMP EXIT
CASE6:
MOV BL,6
CMP AL,BL
JNE CASE7
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FDELETE
JMP EXIT
CASE7:
MOV BL,7
CMP AL,BL
JNE CASE8
MOV DL,0AH
MOV AH,02H
INT 21H
CALL INSERTION
JMP EXIT
CASE8:
MOV BL,8
CMP AL,BL
JNE CASE9
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FMODIFY
JMP EXIT
CASE9:
MOV BL,9
CMP AL,BL
JNE EXIT
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_15
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
JMP EXIT
EXIT:
POP AX
RET
CASE ENDP
INPUTS PROC NEAR
PUSH AX
PUSH CX
PUSH BX
PUSH DX
MOV AH,09H
MOV DX,OFFSET STRING_8
INT 21H
MOV SI,1
MOV AX,DI
MOV BX,10
MUL BX
MOV BX,AX
MOV DX,0
INTPUTNAME:
MOV AH,01H
INT 21H
CMP AL,0DH
JE CONTINUENUM
MOV NAMES[BX+SI],AL
INC SI
INC DX
JMP INTPUTNAME
CONTINUENUM:
MOV NAMES[BX],DL
MOV AH,09H
MOV DX,OFFSET STRING_9
INT 21H
MOV SI,1
MOV DX,0
INTPUTNUM:
MOV AH,01H
INT 21H
CMP AL,0DH
JE CONTINUES
MOV NUMS[BX+SI],AL
INC SI
INC DX
JMP INTPUTNUM
CONTINUES:
MOV NUMS[BX],DL
MOV AH,09H
MOV DX,OFFSET STRING_10
INT 21H
CALL DEINPUT
MOV ARRAY[DI],BL
POP DX
POP BX
POP CX
POP AX
INPUTS ENDP
DEINPUT PROC NEAR
MOV BX,0
GO:
MOV AH,01H
INT 21H
SUB AL,30H
JL EXITDE
CMP AL,9
JG EXITDE
CBW
XCHG AX,BX
MOV DX,10
MUL DX
XCHG AX,BX
ADD BX,AX
JMP GO
EXITDE:
RET
DEINPUT ENDP
OUTPUTS PROC NEAR
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_11
MOV AH,09H
INT 21H
MOV BX,10
MOV AX,DI
MUL BX
MOV BX,AX
MOV DH,NAMES[BX]
MOV SI,1
OUTPUTNAME:
MOV DL,NAMES[BX+SI]
MOV AH,02H
INT 21H
INC SI
DEC DH
CMP DH,0
JNE OUTPUTNAME
MOV DX,OFFSET STRING_12
MOV AH,09H
INT 21H
MOV DH,NUMS[BX]
MOV SI,1
OUTPUTNUM:
MOV DL,NUMS[BX+SI]
MOV AH,02H
INT 21H
INC SI
DEC DH
CMP DH,0
JNE OUTPUTNUM
MOV DX,OFFSET STRING_13
MOV AH,09H
INT 21H
MOV AL,ARRAY[DI]
MOV AH,0
CALL DEOUT
RET
OUTPUTS ENDP
DEOUT PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV CX,0
NEXT:
MOV DX,0
MOV BX,10
DIV BX
PUSH DX
INC CX
CMP AX,0
JNE NEXT
OUTS:
POP DX
ADD DL,30H
MOV AH,02H
INT 21H
LOOP OUTS
POP DX
POP CX
POP BX
POP AX
RET
DEOUT ENDP
FUNPASS PROC NEAR
PUSH AX
PUSH DX
PUSH BX
PUSH DI
MOV DI,0
MOV CX,NUM
MOV NUMPASS,0
JUG_UNP:
MOV AL,ARRAY[DI]
MOV AH,0
CMP AX,60
JNB NEXT_UNP
INC NUMPASS
CALL OUTPUTS
NEXT_UNP:
INC DI
LOOP JUG_UNP
MOV DL,0AH
MOV AH,02H
INT 21H
LEA DX,SUNP
MOV AH,9
INT 21H
MOV AX,NUMPASS
CALL DEOUT
MOV DL,0AH
MOV AH,2
INT 21H
POP DI
POP BX
POP DX
POP AX
RET
FUNPASS ENDP
FAVERAGE PROC NEAR
PUSH AX
PUSH BX
PUSH DX
PUSH DI
MOV DI,0
MOV SUM,DI
MOV CX,NUM
LEA DX,SAVERAGE
MOV AH,9
INT 21H
FSUM:
MOV AL,ARRAY[DI]
MOV AH,0
ADD SUM,AX
INC DI
LOOP FSUM
MOV DX,0
MOV AX,SUM
MOV BX,NUM
MOV CX,100
DIV BX
CALL DEOUT
PUSH DX
MOV DL,'.'
MOV AH,02H
INT 21H
POP DX
MOV AX,DX
MUL CX
MOV DX,0
DIV BX
CALL DEOUT
MOV DL,0AH
MOV AH,2
INT 21H
POP DI
POP DX
POP BX
POP AX
RET
FAVERAGE ENDP
CHANGE PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BX,0
MOV CX,10
MOV AX,DI
MUL CX
MOV DI,AX
MOV AX,SI
MUL CX
MOV SI,AX
NEXTC:
MOV AL,NAMES[SI+BX]
MOV DL,NAMES[DI+BX]
MOV NAMES[DI+BX],AL
MOV NAMES[SI+BX],DL
MOV AL,NUMS[SI+BX]
MOV DL,NUMS[DI+BX]
MOV NUMS[DI+BX],AL
MOV NUMS[SI+BX],DL
INC BX
CMP BX,10
JNE NEXTC
POP DX
POP CX
POP BX
POP AX
RET
CHANGE ENDP
SORTS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV DI,0
MOV SI,0
MOV CX,NUM
DEC CX
SORTF1:
MOV SI,DI
INC SI
SORTF2:
MOV AL,ARRAY[DI]
MOV BL,ARRAY[SI]
CMP AL,BL
JNA NEXTSORT
MOV ARRAY[DI],BL
MOV ARRAY[SI],AL
PUSH DI
PUSH SI
CALL CHANGE
POP SI
POP DI
NEXTSORT:
INC SI
CMP SI,NUM
JNE SORTF2
INC DI
LOOP SORTF1
POP DX
POP CX
POP BX
POP AX
RET
SORTS ENDP
FDELETE PROC NEAR
PUSH DX
PUSH BX
PUSH SI
PUSH DI
MOV DX,OFFSET STRING_16
MOV AH,09H
INT 21H
CALL FFIND
JZ DELETE
JMP EXIT_D
DELETE:
DEC CX
JCXZ DEC_CNT
NEXT_EL:
ADD BX,10
INC DX
PUSH CX
MOV CL,NUMS[BX]
MOV SI,1
TRANS_NUMS:
MOV Al,NUMS[BX+SI]
MOV NUMS[BX-10+SI],Al
INC SI
LOOP TRANS_NUMS
MOV CL,NAMES[BX]
MOV SI,1
TRANS_NAMES:
MOV Al,NAMES[BX+SI]
MOV NAMES[BX-10+SI],Al
INC SI
LOOP TRANS_NAMES
TRANS_SCORES:
POP CX
MOV DI,DX
MOV Al,ARRAY[DI]
MOV ARRAY[DI-1],Al
LOOP NEXT_EL
DEC_CNT:
DEC NUM
MOV DX,OFFSET SUNS
MOV AH,09H
INT 21H
EXIT_D:
POP DI
POP SI
POP BX
POP DX
RET
FDELETE ENDP
INSERTION PROC NEAR
MOV DX,OFFSET STRING_17
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DI,NUM
CALL INPUTS
INC NUM
MOV DX,OFFSET SUNS
MOV AH,09H
INT 21H
CALL SORTS
RET
INSERTION ENDP
FMODIFY PROC NEAR
PUSH DX
PUSH AX
PUSH BX
PUSH CX
MOV DX,OFFSET STRING_20
MOV AH,09H
INT 21H
CALL FFIND
JZ MODIFY
JMP EXIT_M
MODIFY:
MOV AX,BX
MOV DX,0
MOV CX,10
DIV CX
MOV DI,AX
CALL INPUTS
EXIT_M:
POP CX
POP BX
POP AX
POP DX
RET
FMODIFY ENDP
FFIND PROC NEAR
PUSH DI
PUSH AX
PUSH SI
MOV DI,1
MOV BL,0
IN_F:
MOV AH,01H
INT 21H
CMP AL,0DH
JE NEXT_F
INC BL
MOV FINDNAME[DI],AL
INC DI
JMP IN_F
NEXT_F:
MOV FINDNAME[0],BL
MOV BX,0
MOV DX,0
MOV CX,NUM
MOV SI,1
FIND_F:
PUSH CX
MOV AL,NAMES[BX]
CMP AL,FINDNAME[0]
JNE UNFOUND
LEA DI,FINDNAME[1]
LEA SI,NAMES[BX+SI]
MOV CL,NAMES[BX]
CLD
REPE CMPSB
JZ FOUND
UNFOUND:
POP CX
ADD BX,10
INC DX
MOV SI,1
LOOP FIND_F
LEA DX,SUNF
MOV AH,09H
INT 21H
JMP EXIT_F
FOUND:
POP CX
EXIT_F:
POP SI
POP AX
POP DX
RET
FFIND ENDP
CODE ENDS
END START
二、各各子程序的功能讲解
1.登入功能
思路:首先调用dos 0A功能输入一个用户名,利用串匹配与事先在数据段存的用户名进行比较,如果ZF寄存器位1则说明输入的用户名正确,输入密码由于要求输入数据变星号(*),则不能直接调用0A功能,这时就要调用07功能输入不回显,并在输入一个字符后输出一个星号,输入成功后就与比较用户名一样比较密码,如果输入账号正确则提示成功并进入学生管理系统,反之提示错误。
代码如下:
PIN PROC NEAR
MOV DX,OFFSET STRING_2
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET FIRST
MOV AH,09H
INT 21H
MOV AH,0AH
MOV DX,OFFSET TEMPNAME
INT 21H
CMP BYTE PTR TEMPNAME+1,02H
JNE EXIT1
MOV CX,2
MOV SI,OFFSET NAME1
MOV DI,OFFSET TEMPNAME+2
CLD
REPE CMPSB
JNZ EXIT1
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,09H
MOV DX,OFFSET SECOND
INT 21H
MOV SI,OFFSET TEMPPASSWORD
MOV CX,0
INTPUTPASS:
MOV AH,07H
INT 21H
MOV [SI],AL
CMP AL,0DH
JE CONTINUEP
MOV AH,2
MOV DL,'*'
INT 21H
INC SI
INC CX
JMP INTPUTPASS
CONTINUEP:
CMP CX,06H;
JNZ EXIT1
MOV CX,6
MOV SI,OFFSET PASSWORD
MOV DI,OFFSET TEMPPASSWORD
MOV AX,DATA
CLD
REPE CMPSB
JNZ EXIT1
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,09H
MOV DX,OFFSET WELCOME
INT 21H
JMP OUT1
EXIT1:
MOV BX,1
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,09H
MOV DX,OFFSET ERROR
INT 21H
OUT1:
RET
PIN ENDP
2.菜单功能
思路:利用JMP JNE跳转,模拟C的switch case,输入1跳到1号功能以此类推。
代码如下(示例):
MENU PROC NEAR
PUSH DX
PUSH AX
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_1
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_3
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_4
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_5
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_6
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_14
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_7
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_18
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_19
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_15
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_1
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
POP AX
POP DX
RET
MENU ENDP
CASE PROC NEAR
PUSH AX
MOV BL,1
CMP AL,BL
JNE CASE2
MOV DL,0AH
MOV AH,02H
INT 21H
MOV CX,NUM
MOV DI,0
NEXTYY:
CALL INPUTS
INC DI
LOOP NEXTYY
MOV DL,0AH
MOV AH,02H
INT 21H
JMP EXIT
CASE2:
MOV BL,2
CMP AL,BL
JNE CASE3
CALL SORTS
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET SUNS
MOV AH,09H
INT 21H
JMP EXIT
CASE3:
MOV BL,3
CMP AL,BL
JNE CASE4
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FUNPASS
JMP EXIT
CASE4:
MOV BL,4
CMP AL,BL
JNE CASE5
MOV CX,NUM
MOV DI,0
CONTINUEOUTPUTS:
CALL OUTPUTS
INC DI
LOOP CONTINUEOUTPUTS
MOV DL,0AH
MOV AH,02H
INT 21H
JMP EXIT
CASE5:
MOV BL,5
CMP AL,BL
JNE CASE6
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FAVERAGE
JMP EXIT
CASE6:
MOV BL,6
CMP AL,BL
JNE CASE7
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FDELETE
JMP EXIT
CASE7:
MOV BL,7
CMP AL,BL
JNE CASE8
MOV DL,0AH
MOV AH,02H
INT 21H
CALL INSERTION
JMP EXIT
CASE8:
MOV BL,8
CMP AL,BL
JNE CASE9
MOV DL,0AH
MOV AH,02H
INT 21H
CALL FMODIFY
JMP EXIT
CASE9:
MOV BL,9
CMP AL,BL
JNE EXIT
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_15
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
JMP EXIT
EXIT:
POP AX
RET
CASE ENDP
3.输入功能
思路:对于输入功能,主要分为两类:一类是学号姓名的输入,就直接调用dos 01输入一个字符一个字符的输入,而对于成绩把输入的字符串转换为数字。
代码如下(示例):
INPUTS PROC NEAR
PUSH AX
PUSH CX
PUSH BX
PUSH DX
MOV AH,09H
MOV DX,OFFSET STRING_8
INT 21H
MOV SI,1
MOV AX,DI
MOV BX,10
MUL BX
MOV BX,AX
MOV DX,0
INTPUTNAME:
MOV AH,01H
INT 21H
CMP AL,0DH
JE CONTINUENUM
MOV NAMES[BX+SI],AL
INC SI
INC DX
JMP INTPUTNAME
CONTINUENUM:
MOV NAMES[BX],DL
MOV AH,09H
MOV DX,OFFSET STRING_9
INT 21H
MOV SI,1
MOV DX,0
INTPUTNUM:
MOV AH,01H
INT 21H
CMP AL,0DH
JE CONTINUES
MOV NUMS[BX+SI],AL
INC SI
INC DX
JMP INTPUTNUM
CONTINUES:
MOV NUMS[BX],DL
MOV AH,09H
MOV DX,OFFSET STRING_10
INT 21H
CALL DEINPUT
MOV ARRAY[DI],BL
POP DX
POP BX
POP CX
POP AX
INPUTS ENDP
DEINPUT PROC NEAR
MOV BX,0
GO:
MOV AH,01H
INT 21H
SUB AL,30H
JL EXITDE
CMP AL,9
JG EXITDE
CBW
XCHG AX,BX
MOV DX,10
MUL DX
XCHG AX,BX
ADD BX,AX
JMP GO
EXITDE:
RET
DEINPUT ENDP
4.输出功能
思路:输出功能类似于输入功能,只要区别是输出数字还是字符串
代码如下(示例):
OUTPUTS PROC NEAR
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DX,OFFSET STRING_11
MOV AH,09H
INT 21H
MOV BX,10
MOV AX,DI
MUL BX
MOV BX,AX
MOV DH,NAMES[BX]
MOV SI,1
OUTPUTNAME:
MOV DL,NAMES[BX+SI]
MOV AH,02H
INT 21H
INC SI
DEC DH
CMP DH,0
JNE OUTPUTNAME
MOV DX,OFFSET STRING_12
MOV AH,09H
INT 21H
MOV DH,NUMS[BX]
MOV SI,1
OUTPUTNUM:
MOV DL,NUMS[BX+SI]
MOV AH,02H
INT 21H
INC SI
DEC DH
CMP DH,0
JNE OUTPUTNUM
MOV DX,OFFSET STRING_13
MOV AH,09H
INT 21H
MOV AL,ARRAY[DI]
MOV AH,0
CALL DEOUT
RET
OUTPUTS ENDP
DEOUT PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV CX,0
NEXT:
MOV DX,0
MOV BX,10
DIV BX
PUSH DX
INC CX
CMP AX,0
JNE NEXT
OUTS:
POP DX
ADD DL,30H
MOV AH,02H
INT 21H
LOOP OUTS
POP DX
POP CX
POP BX
POP AX
RET
DEOUT ENDP
5.成绩排序功能
思路:排序我这里用的是选择排序(由于选择排序比较简单我这里就不赘述了),排序的难点在于数据的交换,对于成绩可以直接交换,但对于学号姓名就要求一个一个字符交换了。
代码如下(示例):
CHANGE PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BX,0
MOV CX,10
MOV AX,DI
MUL CX
MOV DI,AX
MOV AX,SI
MUL CX
MOV SI,AX
NEXTC:
MOV AL,NAMES[SI+BX]
MOV DL,NAMES[DI+BX]
MOV NAMES[DI+BX],AL
MOV NAMES[SI+BX],DL
MOV AL,NUMS[SI+BX]
MOV DL,NUMS[DI+BX]
MOV NUMS[DI+BX],AL
MOV NUMS[SI+BX],DL
INC BX
CMP BX,10
JNE NEXTC
POP DX
POP CX
POP BX
POP AX
RET
CHANGE ENDP
SORTS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV DI,0
MOV SI,0
MOV CX,NUM
DEC CX
SORTF1:
MOV SI,DI
INC SI
SORTF2:
MOV AL,ARRAY[DI]
MOV BL,ARRAY[SI]
CMP AL,BL
JNA NEXTSORT
MOV ARRAY[DI],BL
MOV ARRAY[SI],AL
PUSH DI
PUSH SI
CALL CHANGE
POP SI
POP DI
NEXTSORT:
INC SI
CMP SI,NUM
JNE SORTF2
INC DI
LOOP SORTF1
POP DX
POP CX
POP BX
POP AX
RET
SORTS ENDP
6.不及格人数统计功能
思路:这个比较简单就不赘述了
代码如下(示例):
FUNPASS PROC NEAR
PUSH AX
PUSH DX
PUSH BX
PUSH DI
MOV DI,0
MOV CX,NUM
MOV NUMPASS,0
JUG_UNP:
MOV AL,ARRAY[DI]
MOV AH,0
CMP AX,60
JNB NEXT_UNP
INC NUMPASS
CALL OUTPUTS
NEXT_UNP:
INC DI
LOOP JUG_UNP
MOV DL,0AH
MOV AH,02H
INT 21H
LEA DX,SUNP
MOV AH,9
INT 21H
MOV AX,NUMPASS
CALL DEOUT
MOV DL,0AH
MOV AH,2
INT 21H
POP DI
POP BX
POP DX
POP AX
RET
FUNPASS ENDP
7.删除学习信息功能
思路:这个比较简单就不赘述了。
代码如下(示例):
FDELETE PROC NEAR
PUSH DX
PUSH BX
PUSH SI
PUSH DI
MOV DX,OFFSET STRING_16
MOV AH,09H
INT 21H
CALL FFIND
JZ DELETE
JMP EXIT_D
DELETE:
DEC CX
JCXZ DEC_CNT
NEXT_EL:
ADD BX,10
INC DX
PUSH CX
MOV CL,NUMS[BX]
MOV SI,1
TRANS_NUMS:
MOV Al,NUMS[BX+SI]
MOV NUMS[BX-10+SI],Al
INC SI
LOOP TRANS_NUMS
MOV CL,NAMES[BX]
MOV SI,1
TRANS_NAMES:
MOV Al,NAMES[BX+SI]
MOV NAMES[BX-10+SI],Al
INC SI
LOOP TRANS_NAMES
TRANS_SCORES:
POP CX
MOV DI,DX
MOV Al,ARRAY[DI]
MOV ARRAY[DI-1],Al
LOOP NEXT_EL
DEC_CNT:
DEC NUM
MOV DX,OFFSET SUNS
MOV AH,09H
INT 21H
EXIT_D:
POP DI
POP SI
POP BX
POP DX
RET
FDELETE ENDP
8.插入学生信息功能
思路:这个比较简单就不赘述了。
代码如下(示例):
INSERTION PROC NEAR
MOV DX,OFFSET STRING_17
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DI,NUM
CALL INPUTS
INC NUM
MOV DX,OFFSET SUNS
MOV AH,09H
INT 21H
CALL SORTS
RET
INSERTION ENDP
9.修改学生信息功能
思路:
这个比较简单就不赘述了 。
代码如下(示例):
FMODIFY PROC NEAR
PUSH DX
PUSH AX
PUSH BX
PUSH CX
MOV DX,OFFSET STRING_20
MOV AH,09H
INT 21H
CALL FFIND
JZ MODIFY
JMP EXIT_M
MODIFY:
MOV AX,BX
MOV DX,0
MOV CX,10
DIV CX
MOV DI,AX
CALL INPUTS
EXIT_M:
POP CX
POP BX
POP AX
POP DX
RET
FMODIFY ENDP
FFIND PROC NEAR
PUSH DI
PUSH AX
PUSH SI
MOV DI,1
MOV BL,0
IN_F:
MOV AH,01H
INT 21H
CMP AL,0DH
JE NEXT_F
INC BL
MOV FINDNAME[DI],AL
INC DI
JMP IN_F
NEXT_F:
MOV FINDNAME[0],BL
MOV BX,0
MOV DX,0
MOV CX,NUM
MOV SI,1
FIND_F:
PUSH CX
MOV AL,NAMES[BX]
CMP AL,FINDNAME[0]
JNE UNFOUND
LEA DI,FINDNAME[1]
LEA SI,NAMES[BX+SI]
MOV CL,NAMES[BX]
CLD
REPE CMPSB
JZ FOUND
UNFOUND:
POP CX
ADD BX,10
INC DX
MOV SI,1
LOOP FIND_F
LEA DX,SUNF
MOV AH,09H
INT 21H
JMP EXIT_F
FOUND:
POP CX
EXIT_F:
POP SI
POP AX
POP DX
RET
FFIND ENDP
10.求学生的平均成绩
思路:这里有一个点要注意,那就是成绩我保留了两位小数,对于汇编来讲除法会保留余数,所有要实现保留小数就简单了,就把余数乘与100在拿去除人数,然后把结果在小数点后输出。
代码如下(示例):
FAVERAGE PROC NEAR
PUSH AX
PUSH BX
PUSH DX
PUSH DI
MOV DI,0
MOV SUM,DI
MOV CX,NUM
LEA DX,SAVERAGE
MOV AH,9
INT 21H
FSUM:
MOV AL,ARRAY[DI]
MOV AH,0
ADD SUM,AX
INC DI
LOOP FSUM
MOV DX,0
MOV AX,SUM
MOV BX,NUM
MOV CX,100
DIV BX
CALL DEOUT
PUSH DX
MOV DL,'.'
MOV AH,02H
INT 21H
POP DX
MOV AX,DX
MUL CX
MOV DX,0
DIV BX
CALL DEOUT
MOV DL,0AH
MOV AH,2
INT 21H
POP DI
POP DX
POP BX
POP AX
RET
FAVERAGE ENDP
总结
提示:本文章仅供参考,文章使用的方法不是最优的,仅仅只是实现了功能。最后希望看到这的人,如果这篇文章对你有用可以动动你的小手点点赞👍。