当前位置: 代码迷 >> 汇编语言 >> 统计学生成绩,该如何解决
  详细解决方案

统计学生成绩,该如何解决

热度:3546   发布时间:2013-02-26 00:00:00.0
统计学生成绩
以grade为首地址存放若干学生的成绩统计低于60分,60-69,70-79,80-89,90-99,以及100分的人数,分别存放在S5,S6,S7,S8,S9,S10中

------解决方案--------------------------------------------------------
DATA SEGMENT
NUMBER DB 56,69,84,82,73,88,99,63,100,80
S5 DB 30H ;0-59
S6 DB 30H ;60-69
S7 DB 30H ;70-79
S8 DB 30H ;80-89
S9 DB 30H ;90-99
S10 DB 30H ;100
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
AND BX,0000H
AND AL,00H
MOV BX,OFFSET NUMBER

mov cx,S5-NUMBER ;总人数

AGAIN:MOV AL,[BX]
CMP AL,100
JS NEXT_90 ;如果AL等于100(0110 0100),没有产生借位
INC S10
JMP STO

NEXT_90:CMP AL,90
JS NEXT_80
INC S9
JMP STO

NEXT_80:CMP AL,80
JS NEXT_70
INC S8
JMP STO

NEXT_70:CMP AL,70
JS NEXT_60
INC S7
JMP STO

NEXT_60:CMP AL,60
JS NEXT_50
INC S6
JMP STO

NEXT_50:INC S5

STO: INC BX
LOOP AGAIN

MOV CX,6H
MOV BX,OFFSET S5

DISP:
MOV DL,[BX]
INC BX
MOV AH,02
INT 21H

MOV DL,0 ;在各级人数之间显示空格
MOV AH,02
INT 21H

LOOP DISP

MOV AH,4CH
INT 21H

CODE ENDS
END START

运行结果:

1 2 1 4 1 1
------解决方案--------------------------------------------------------
DATA SEGMENT
GRADE DB 55,65,77,85,98,78,54 ;
NUM EQU 7 ;
STR DB ' $ '
S5 DB 30H
S6 DB 30H
S7 DB 30H
S8 DB 30H
S9 DB 30H
S10 DB 30H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CX,NUM
MOV BX,OFFSET GRADE
NEXT: MOV AL,[BX]
MOV SI,OFFSET S5
MOV AH,0
MOV DL,10
DIV DL
SUB AL,5
MOV AH,0
ADD SI,AX
INC BYTE PTR [SI]

;MOV AH,02H
;MOV DL,AL
;ADD DL,30H
;INT 21H

INC BX
LOOP NEXT

MOV BX,OFFSET S5
MOV CX,6
L: MOV AH,02H
MOV DL,[BX]
INT 21H
MOV AH,09H
MOV DX,OFFSET STR
INT 21H
INC BX
LOOP L
MOV AH,07H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
  相关解决方案