CODE SEGMENT
ASSUME CS:CODE
ORG 100H
START: JMP BEGIN
MSG0 DB 13,10,'Please input the scores of students: ',13,10,13,10,'$'
ADD1 EQU $
MSG1 DB 13,10,13,10,'Fail(below60):$'
ADD2 EQU $
MSG2 DB 13,10,13,10,'Pass(6-69):$'
ADD3 EQU $
MSG3 DB 13,10,13,10,'Medium(70-79):$'
ADD4 EQU $
MSG4 DB 13,10,13,10,'Good(80-89):$'
ADD5 EQU $
MSG5 DB 13,10,13,10,'Outstanding(above 90):$'
ADDRS DW ADD1,ADD2,ADD3,ADD4,ADD5
NUMS DW 0,0,0,0,0
BEGIN: PUSH CS
POP DS
PUSH CS
POP ES
LEA DX,MSG0
MOV AH,9
INT 21H
CALL INPUTNUM
LEA SI,@ARRAY
MOV CX,@NUM
LEA DI,NUMS
CLD
@1:
LODSW
CMP AX,50
JG @2
MOV AX,50
@2:
SUB AX,50
MOV DL,10
DIV DL
MOV AH,0
MOV BX,AX
SHL BX,1
INC WORD PTR [BX+DI]
LOOP @1
MOV CX,5
LEA SI,ADDRS
LEA DI,NUMS
ADD SI,8
ADD DI,8
@3:
MOV DX,[SI]
MOV AH,9
INT 21H
MOV AX,[DI]
CALL DISPAXS
DEC SI
DEC SI
DEC DI
DEC DI
LOOP @3
MOV AH,4CH
INT 21H
;===============================================
; 键盘输入数值数组子程序(数组名为@array,元素个数存放在@num中)
; 可以是负数
INPUTNUM PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSHF
; 对数组@array清零
MOV CX,100
MOV AX,0
LEA DI,@ARRAY
REP STOSW
MOV WORD PTR @NUM,0
; 输入的数据以一个空格分隔,以回车符结束输入
LEA DX,@STRA
MOV AH,10
INT 21H
MOV CL,@STRN
MOV CH,0
MOV WORD PTR @STRM,CX
LEA SI,@STR
CLD
LEA DI,@ARRAY
MOV WORD PTR @NUM,0
@STIN:
MOV AX,0
PUSH AX
MOV BYTE PTR @SIGNN,0
@AGAIN1:
CMP WORD PTR @STRM,0
JE @LINE0
LODSB
DEC WORD PTR @STRM
CMP AL,' '
JE @LINE0
CMP AL,'-'
JNE @INPUT1
MOV BYTE PTR @SIGNN,1
JMP @AGAIN1
@INPUT1:
SUB AL,30H
MOV AH,0
MOV BX,AX
POP AX
MOV CL,10
MOV CH,0
MUL CX
ADD AX,BX
PUSH AX
JMP @AGAIN1
@LINE0:
POP AX
CMP BYTE PTR @SIGNN,1
JNE @INPUT2
NEG AX
@INPUT2:
MOV WORD PTR[DI],AX
INC WORD PTR @NUM
CMP WORD PTR @STRM,0
JE @STINEND
INC DI
INC DI
JMP @STIN
@STINEND:
POPF
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
@STRA DB 255
@STRN DB 0
@STR DB 255 DUP(?)
@STRM DW 0
@ARRAY DW 100 DUP(0)
@NUM DW 0
@CHAR DB 0
@SIGNN DB 0
INPUTNUM ENDP
;=========================================
; 将要显示的有符号数置于 ax 中
DISPAXS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSH DS
PUSH ES
PUSHF
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,6
LEA DI,DISPAXSS
@DISPAXS:
MOV BYTE PTR [DI],32
INC DI
LOOP @DISPAXS
PUSH AX
MOV DL,32
MOV AH,2
INT 21H
POP AX
MOV BYTE PTR NZS,0
MOV BYTE PTR SIGNS,0
CMP AX,0
JGE @DISPAXS0
MOV BYTE PTR SIGNS,1
NEG AX
@DISPAXS0:
PUSH AX
LEA SI,DIVARRS
LEA DI,DISPAXSS
INC DI
MOV CX,5
@DISPAXS1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @DISPAXS2
CMP BYTE PTR NZS,1
JE @DISPAXS2
CMP CX,1
JE @DISPAXS2
MOV DL,20H
JMP @DISPAXS3
@DISPAXS2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZS,1
@DISPAXS3:
MOV BYTE PTR[DI],DL
INC SI
INC SI
INC DI
LOOP @DISPAXS1
POP DX
CMP BYTE PTR SIGNS,1
JNE @DISPAXS6
LEA SI,DISPAXSS
ADD SI,5
@DISPAXS4:
CMP BYTE PTR [SI],32
JE @DISPAXS5
DEC SI
JMP @DISPAXS4
@DISPAXS5:
MOV BYTE PTR [SI],'-'
@DISPAXS6:
LEA DX,DISPAXSS
MOV AH,9
INT 21H
POPF
POP ES
POP DS
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
DIVARRS DW 10000,1000,100,10,1
NZS DB 0
SIGNS DB 0
DISPAXSS DB 32,32,32,32,32,32,'$'
DISPAXS ENDP
;==================================
CODE ENDS
END START