CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: MOV AX,DATAS MOV DS,AX MAIN: CALL LOP2 LEA DX,HINT_10 MOV AH,09H INT 21H SETCHOOSE: MOV AH,01H INT 21H MOV CHOOSE,AL CALL OUTPUTCRLF CMP CHOOSE,'3' JZ CALL3 CMP CHOOSE,'4' JZ CALL4 CMP CHOOSE,'5' JZ CALL5 CMP CHOOSE,'6' JNZ SETCHOOSE CALL3: CALL LOP3 JMP SETCHOOSE CALL4: CALL LOP4 JMP SETCHOOSE CALL5: CALL LOP5 JMP SETCHOOSE OUTPUT PROC MOV BP,SP MOV AX,[BP+2] MOV INDEX,0 OUTPUT2: CWD DIV TEN ADD DX,30H PUSH DX INC INDEX CMP AX,0 JZ OUTPUT3 JMP OUTPUT2 OUTPUT3: CMP INDEX,0 JZ OUTPUTEND POP DX MOV AH,02H INT 21H DEC INDEX JMP OUTPUT3 OUTPUTEND: RET 2 OUTPUT ENDP OUTPUTSPACE PROC MOV DX,20H MOV AH,02H INT 21H RET OUTPUTSPACE ENDP OUTPUTCRLF PROC LEA DX,CRLF MOV AH,09H INT 21H RET OUTPUTCRLF ENDP LOP5 PROC MOV SI,0 MOV CX,COUNT_3 DEC CX MOV BX,GRADE[SI] ADD AVERAGE,BX ADDSUM: ADD SI,2 MOV BX,GRADE[SI] ADC AVERAGE,BX LOOP ADDSUM LEA DX,HINT_9 MOV AH,09H INT 21H MOV AX,AVERAGE CWD DIV COUNT_3 PUSH DX PUSH AX CALL OUTPUT MOV DX,'.' MOV AH,02H INT 21H MOV CX,COUNT_6 POP AX DECIMAL: MUL TEN CWD DIV COUNT_3 PUSH DX PUSH AX CALL OUTPUT POP AX LOOP DECIMAL CALL OUTPUTCRLF RET LOP5 ENDP LOP4 PROC MOV COUNT_5,0 MOV SI,0 MOV CX,0 COMPARE2: MOV BX,SIXTY CMP GRADE[SI],BX JB ACCOUNT RETURN2: ADD SI,2 INC CX CMP CX,COUNT_3 JNZ COMPARE2 JZ END4 ACCOUNT: INC COUNT_5 JMP RETURN2 END4: LEA DX,HINT_8 MOV AH,09H INT 21H MOV AX,COUNT_5 PUSH AX CALL OUTPUT CALL OUTPUTCRLF RET LOP4 ENDP LOP3 PROC MOV CX,0 FIRST: MOV DI,0 INC CX CMP CX,COUNT_3 JZ OUTPUT_3 COMPARE: MOV BX,GRADE[DI] CMP BX,GRADE[DI+2] JB SWAP RETURN1: ADD DI,2 CMP COUNT_4,DI JZ FIRST JMP COMPARE SWAP: MOV AX,GRADE[DI+2] MOV GRADE[DI],AX MOV GRADE[DI+2],BX JMP RETURN1 OUTPUT_3: MOV CX,COUNT_3 MOV SI,0 OUTPUT0: MOV AX,GRADE[SI] PUSH AX CALL OUTPUT CALL OUTPUTSPACE ADD SI,2 DEC CX CMP CX,0 JNZ OUTPUT0 CALL OUTPUTCRLF RET LOP3 ENDP LOP2 PROC MOV CX,0 MOV SI,0 LEA DX,HINT_6 MOV AH,09H INT 21H INPUT: MOV AH,01H INT 21H CMP AL,0DH JZ SAVENUM CMP AL,' ' JZ SAVENUM MOV DL,AL MOV DH,0 PUSH DI PUSH DX CALL ISDIGITAL POP DX POP DI CMP FLAG_1,0 JZ INPUT MOV N,DX SUB N,30H MOV AX,NUM MUL TEN ADD AX,N MOV NUM,AX JMP INPUT SAVENUM: INC CX MOV BX,NUM MOV GRADE[SI],BX MOV NUM,0 ADD SI,2 CMP AL,0DH JZ END2 JMP INPUT END2: MOV COUNT_3,CX LEA DX,HINT_7 MOV AH,09H INT 21H RET LOP2 ENDP ISDIGITAL PROC MOV BP,SP MOV DI,[BP+2] ISBIGGER: CMP DI,'0' JB NONDIGITAL ISSMALL: CMP DI,'9' JBE DIGITAL JMP NONDIGITAL NONDIGITAL: MOV FLAG_1,0 CALL OUTPUTCRLF LEA DX,HINT_5 MOV NUM,0 MOV AH,09H INT 21H RET DIGITAL: MOV FLAG_1,1 RET ISDIGITAL ENDP MOV AH,4CH INT 21H CODES ENDS END START请用注释的形式为我逐句解释这篇代码的功能
时间: 2023-11-13 12:06:01 浏览: 140
```assembly
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
; 初始化数据段寄存器
START:
MOV AX,DATAS
MOV DS,AX
MAIN:
; 调用 LOP2 过程
CALL LOP2
; 输出提示信息
LEA DX,HINT_10
MOV AH,09H
INT 21H
SETCHOOSE:
; 获取用户输入
MOV AH,01H
INT 21H
MOV CHOOSE,AL
; 根据用户输入调用不同的过程
CALL OUTPUTCRLF
CMP CHOOSE,'3'
JZ CALL3
CMP CHOOSE,'4'
JZ CALL4
CMP CHOOSE,'5'
JZ CALL5
CMP CHOOSE,'6'
JNZ SETCHOOSE
CALL3:
; 调用 LOP3 过程
CALL LOP3
JMP SETCHOOSE
CALL4:
; 调用 LOP4 过程
CALL LOP4
JMP SETCHOOSE
CALL5:
; 调用 LOP5 过程
CALL LOP5
JMP SETCHOOSE
OUTPUT PROC
; 从栈中获取 AX 寄存器中的值
MOV BP,SP
MOV AX,[BP+2]
; 将 AX 中的数字转换成字符并输出
MOV INDEX,0
OUTPUT2:
CWD
DIV TEN
ADD DX,30H
PUSH DX
INC INDEX
CMP AX,0
JZ OUTPUT3
JMP OUTPUT2
OUTPUT3:
CMP INDEX,0
JZ OUTPUTEND
POP DX
MOV AH,02H
INT 21H
DEC INDEX
JMP OUTPUT3
OUTPUTEND:
RET 2
OUTPUT ENDP
OUTPUTSPACE PROC
; 输出一个空格
MOV DX,20H
MOV AH,02H
INT 21H
RET
OUTPUTSPACE ENDP
OUTPUTCRLF PROC
; 输出回车换行
LEA DX,CRLF
MOV AH,09H
INT 21H
RET
OUTPUTCRLF ENDP
LOP5 PROC
; 计算成绩平均值
MOV SI,0
MOV CX,COUNT_3
DEC CX
MOV BX,GRADE[SI]
ADD AVERAGE,BX
ADDSUM:
ADD SI,2
MOV BX,GRADE[SI]
ADC AVERAGE,BX
LOOP ADDSUM
LEA DX,HINT_9
MOV AH,09H
INT 21H
; 输出平均值
MOV AX,AVERAGE
CWD
DIV COUNT_3
PUSH DX
PUSH AX
CALL OUTPUT
MOV DX,'.'
MOV AH,02H
INT 21H
; 输出小数部分
MOV CX,COUNT_6
POP AX
DECIMAL:
MUL TEN
CWD
DIV COUNT_3
PUSH DX
PUSH AX
CALL OUTPUT
POP AX
LOOP DECIMAL
; 输出回车换行
CALL OUTPUTCRLF
RET
LOP5 ENDP
LOP4 PROC
; 查找成绩大于等于 60 分的人数
MOV COUNT_5,0
MOV SI,0
MOV CX,0
COMPARE2:
MOV BX,SIXTY
CMP GRADE[SI],BX
JB ACCOUNT
RETURN2:
ADD SI,2
INC CX
CMP CX,COUNT_3
JNZ COMPARE2
JZ END4
ACCOUNT:
INC COUNT_5
JMP RETURN2
END4:
; 输出人数
LEA DX,HINT_8
MOV AH,09H
INT 21H
MOV AX,COUNT_5
PUSH AX
CALL OUTPUT
CALL OUTPUTCRLF
RET
LOP4 ENDP
LOP3 PROC
; 排序并输出成绩
MOV CX,0
FIRST:
MOV DI,0
INC CX
CMP CX,COUNT_3
JZ OUTPUT_3
COMPARE:
MOV BX,GRADE[DI]
CMP BX,GRADE[DI+2]
JB SWAP
RETURN1:
ADD DI,2
CMP COUNT_4,DI
JZ FIRST
JMP COMPARE
SWAP:
MOV AX,GRADE[DI+2]
MOV GRADE[DI],AX
MOV GRADE[DI+2],BX
JMP RETURN1
OUTPUT_3:
MOV CX,COUNT_3
MOV SI,0
OUTPUT0:
MOV AX,GRADE[SI]
PUSH AX
CALL OUTPUT
CALL OUTPUTSPACE
ADD SI,2
DEC CX
CMP CX,0
JNZ OUTPUT0
CALL OUTPUTCRLF
RET
LOP3 ENDP
LOP2 PROC
; 输出提示信息
MOV CX,0
MOV SI,0
LEA DX,HINT_6
MOV AH,09H
INT 21H
INPUT:
; 获取用户输入
MOV AH,01H
INT 21H
CMP AL,0DH
JZ SAVENUM
CMP AL,' '
JZ SAVENUM
MOV DL,AL
MOV DH,0
PUSH DI
PUSH DX
CALL ISDIGITAL
POP DX
POP DI
CMP FLAG_1,0
JZ INPUT
MOV N,DX
SUB N,30H
MOV AX,NUM
MUL TEN
ADD AX,N
MOV NUM,AX
JMP INPUT
SAVENUM:
INC CX
MOV BX,NUM
MOV GRADE[SI],BX
MOV NUM,0
ADD SI,2
CMP AL,0DH
JZ END2
JMP INPUT
END2:
MOV COUNT_3,CX
LEA DX,HINT_7
MOV AH,09H
INT 21H
RET
LOP2 ENDP
ISDIGITAL PROC
; 判断字符是否为数字
MOV BP,SP
MOV DI,[BP+2]
ISBIGGER:
CMP DI,'0'
JB NONDIGITAL
ISSMALL:
CMP DI,'9'
JBE DIGITAL
JMP NONDIGITAL
NONDIGITAL:
MOV FLAG_1,0
CALL OUTPUTCRLF
LEA DX,HINT_5
MOV NUM,0
MOV AH,09H
INT 21H
RET
DIGITAL:
MOV FLAG_1,1
RET
ISDIGITAL ENDP
; 程序结束
MOV AH,4CH
INT 21H
CODES ENDS
END START
```
这段代码是一个简单的成绩管理程序,可以实现以下功能:
1. 输入成绩,最多输入 30 个,保存在数组 `GRADE` 中。
2. 对成绩进行排序并输出。
3. 计算成绩平均值,输出平均值及小数部分。
4. 查找成绩大于等于 60 分的人数,输出人数。
程序的具体实现细节可以参考注释。
阅读全文