I/O:Unit1
编程,从键盘读入学生成绩(0~100分),共15名学生,计算并显示总分、平均成绩、单的学生成绩
1 ;03 47 86 91 72 55 93 88 83 79 61 78 85 90 10 sum:1021 avg:68 2 DATA1 SEGMENT 3 STU DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 4 SUM DW 0 5 BUF DB 0,0,0,0 6 AVG DB 0 7 COUNT EQU 15 8 TIMES EQU 4 9 BASE DB 10 10 DATA1 ENDS 11 12 CODE SEGMENT 13 MAIN PROC FAR 14 ASSUME CS:CODE,DS:DATA1 15 16 START: 17 MOV AX,DATA1 18 MOV DS,AX 19 20 MOV CX,COUNT 21 MOV BX,OFFSET STU 22 MOV DL,10 23 LOOP1: MOV DH,0 24 MOV AH,1 ;读入数据 25 INT 21H 26 SUB AL,48 27 MUL [BASE] 28 ADD DH,AL 29 MOV AH,1 30 INT 21H 31 SUB AL,48 32 ADD DH,AL 33 MOV [BX],DH 34 MOV AH,1 35 INT 21H 36 INC BX 37 LOOP LOOP1 38 39 MOV DL,0DH ;换行 40 MOV AH,2 41 INT 21H 42 MOV DL,0AH 43 MOV AH,2 44 INT 21H 45 46 MOV CX,COUNT 47 MOV BX,OFFSET STU 48 MOV AL,0 49 MOV AH,0 50 CLC 51 LOOP2: ADD AL,[BX] 52 ADC AH,0 53 INC BX 54 LOOP LOOP2 55 56 MOV SUM,AX; 57 MOV CL,COUNT 58 DIV CL 59 MOV AVG,AL 60 61 MOV CX,COUNT ;输出分数 62 MOV BX,OFFSET STU 63 LOOP3: MOV AH,0 64 MOV AL,[BX] 65 DIV [BASE] 66 MOV DL,AL 67 MOV DH,AH 68 ADD DL,48 69 MOV AH,2 ;会影响AL中的数据 70 INT 21H 71 MOV DL,DH 72 ADD DL,48 73 MOV AH,2 74 INT 21H 75 MOV DL,32 76 MOV AH,2 77 INT 21H 78 INC BX 79 LOOP LOOP3 80 81 MOV DL,0DH ;换行 82 MOV AH,2 83 INT 21H 84 MOV DL,0AH 85 MOV AH,2 86 INT 21H 87 88 89 MOV CX,TIMES ;获取总数逐位 90 MOV BX,OFFSET BUF 91 MOV AX,[SUM] 92 LOOP4: DIV [BASE] 93 MOV [BX],AH 94 INC BX 95 MOV AH,0 96 LOOP LOOP4 97 98 MOV DL,115 ;显示sum 99 MOV AH,2 100 INT 21H 101 MOV DL,117 102 MOV AH,2 103 INT 21H 104 MOV DL,109 105 MOV AH,2 106 INT 21H 107 108 MOV CX,TIMES ;显示总数 109 NEXT1: DEC BX ;去前导0 110 DEC CX 111 MOV DL,[BX] 112 CMP DL,0 113 JE NEXT1 114 115 INC BX 116 INC CX 117 118 LOOP5: DEC BX 119 MOV DL,[BX] 120 ADD DL,48 121 MOV AH,2 122 INT 21H 123 LOOP LOOP5 124 125 MOV DL,0DH ;换行 126 MOV AH,2 127 INT 21H 128 MOV DL,0AH 129 MOV AH,2 130 INT 21H 131 132 133 MOV DL,97 134 MOV AH,2 135 INT 21H 136 MOV DL,118 137 MOV AH,2 138 INT 21H 139 MOV DL,103 140 MOV AH,2 141 INT 21H 142 143 MOV AH,0 144 MOV AL,[AVG] ;显示平均数 145 DIV [BASE] 146 MOV DL,AL 147 MOV DH,AH 148 ADD DL,48 149 MOV AH,2 150 INT 21H 151 152 MOV DL,DH 153 ADD DL,48 154 MOV AH,2 155 INT 21H 156 157 MAIN ENDP 158 CODE ENDS 159 END START