代码
DSEG SEGMENT
GRADE DB 5 DUP(0)
XUEHAO DB '1','2','3','4','5'
BUF DB 4 DUP(0)
INF DB "Student",'$'
NEWLINE DB 0DH,0AH
DSEG ENDS
SSEG SEGMENT STACK
SKTOP DB 50 DUP(0)
SSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG,DS:DSEG,SS:SSEG
START:
MOV AX,DSEG
MOV DS,AX
MOV AX,SSEG
MOV SS,AX
CALL CIN
LEA DI,NEWLINE
MOV DL,DS:[DI]
MOV AH,2
INT 21H
MOV DL,DS:[DI+1]
INT 21H
CALL selectionSort
CALL COUT
MOV AH,4CH
INT 21H
CIN PROC NEAR
XOR SI,SI
LEA SI,XUEHAO
XOR DI,DI
XOR BX,BX
XOR CX,CX
PUSH CX;输入5个学生成绩的计数
LEA CX,BUF
LEA DI,GRADE
PUSH DI
LOP:
POP DI
POP CX
CMP CX,5
JE ENDCIN
INC CX
PUSH CX
PUSH DI
LEA DI,BUF
MOV DX,SEG INF
MOV DS,DX
LEA DX,INF
MOV AH,9
INT 21H
MOV DL,DS:[SI]
INC SI
MOV AH,02H
INT 21H
MOV DL,':'
INT 21H
INGRADE:
MOV AH,01H
INT 21H
MOV DS:[DI],AL
INC DI
CMP AL,0DH
JNE INGRADE
MOV DX,DI
POP DI
CALL C_to_N
PUSH DI
JMP LOP
ENDCIN: RET
CIN ENDP
C_to_N PROC NEAR
PUSH DI
PUSH SI
MOV DI,DX
LEA SI,BUF
DEC SI
XOR DX,DX
SUB DI,2
MOV CL,1
TURN: MOV BL,DS:[DI]
SUB BL,30H
MOV AL,CL
MUL BL
ADD DL,AL
MOV AL,10
MUL CL
MOV CL,AL
DEC DI
CMP DI,SI
JNE TURN
POP SI
POP DI
MOV DS:[DI],DL
INC DI
RET
C_to_N ENDP
selectionSort PROC NEAR
LEA DI,GRADE;MinIndex
MOV CX,4
MOV DX,4
LOP1:
MOV SI,DI
INC SI
PUSH CX
MOV BX,DI
MOV CX,DX
MOV AL,DS:[DI]
LOP2:
CMP AL,DS:[SI]
JA EXCHANGE
INC SI
JMP NEXT
EXCHANGE:
MOV AL,DS:[SI]
MOV BX,SI
INC SI
NEXT: LOOP LOP2
XCHG AL,DS:[DI]
XCHG AL,DS:[BX]
PUSH DI;学号交换
PUSH DX
MOV AX,DI
LEA DI,GRADE
LEA SI,XUEHAO
SUB AX,DI
SUB BX,DI
ADD AX,SI
MOV DI,AX
ADD BX,SI
MOV DL,DS:[DI]
XCHG DL,DS:[BX]
XCHG DL,DS:[DI]
POP DX
POP DI
DEC DX
INC DI
POP CX
LOOP LOP1
RET
selectionSort ENDP
COUT PROC NEAR
XOR CX,CX
MOV CX,5
LEA DI,GRADE
LEA SI,XUEHAO
LOP3:
PUSH CX
MOV DX,SEG INF
MOV DS,DX
LEA DX,INF
MOV AH,9
INT 21H
MOV DL,DS:[SI]
INC SI
MOV AH,02H
INT 21H
MOV DL,':'
INT 21H
XOR AX,AX
XOR BX,BX
MOV BL,0AH
MOV AL,DS:[DI]
INC DI
PUSH DI
PUSH SI
LEA DI,BUF
LEA SI,BUF
DEC SI
NEXT1: DIV BL
ADD AH,30H
XOR DX,DX
MOV DS:[DI],AH
CMP AL,0
JE OUTBUF
INC DI
MOV DL,AL
XOR AX,AX
MOV AL,DL
JMP NEXT1
OUTBUF:
MOV DL,DS:[DI]
DEC DI
MOV AH,2
INT 21H
CMP SI,DI
JNE OUTBUF
LEA DI,NEWLINE
MOV DL,DS:[DI]
MOV AH,2
INT 21H
MOV DL,DS:[DI+1]
INT 21H
POP SI
POP DI
POP CX
LOOP LOP3
RET
COUT ENDP
CSEG ENDS
END START
标签:排序,DX,DI,MOV,SI,CX,模块,成绩,DS
From: https://blog.csdn.net/2201_76131920/article/details/139497153