从键盘输入3个学生的成绩,如果低于60分,则F (Fail),如 果高于或等于90 分则显示 G (good),否则显示 P (Pass)。编写8086汇编语言实现分别显示成绩等级
时间: 2024-02-26 14:58:35 浏览: 102
好的,我理解了你的问题。下面是汇编代码实现:
```
DATA SEGMENT
GRADE1 DB ?
GRADE2 DB ?
GRADE3 DB ?
MSG1 DB 'GRADE 1: $'
MSG2 DB 'GRADE 2: $'
MSG3 DB 'GRADE 3: $'
MSG4 DB 'GRADE 1: ', 2 DUP (' '), '$'
MSG5 DB 'GRADE 2: ', 2 DUP (' '), '$'
MSG6 DB 'GRADE 3: ', 2 DUP (' '), '$'
MSG7 DB 'FINAL GRADE: $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
; input first grade
LEA DX, MSG1
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE1, AL
; input second grade
LEA DX, MSG2
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE2, AL
; input third grade
LEA DX, MSG3
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE3, AL
; display grades
MOV AH, 09H
LEA DX, MSG4
MOV DL, GRADE1
ADD DL, 30H
MOV MSG4+7, DL
INT 21H
MOV AH, 09H
LEA DX, MSG5
MOV DL, GRADE2
ADD DL, 30H
MOV MSG5+7, DL
INT 21H
MOV AH, 09H
LEA DX, MSG6
MOV DL, GRADE3
ADD DL, 30H
MOV MSG6+7, DL
INT 21H
; calculate final grade
MOV AL, GRADE1
ADD AL, GRADE2
ADD AL, GRADE3
MOV BL, 3
DIV BL
; display final grade
MOV AH, 09H
LEA DX, MSG7
CMP AL, 90
JGE GOOD
CMP AL, 60
JL FAIL
MOV DL, 'P'
JMP DISPLAY
GOOD:
MOV DL, 'G'
JMP DISPLAY
FAIL:
MOV DL, 'F'
DISPLAY:
MOV MSG7+12, DL
INT 21H
MOV AH, 4CH
INT 21H
CODE ENDS
END START
```
这段代码会要求用户输入三个学生成绩,并将它们存储在内存中。接着,它会计算这三个成绩的平均值,并根据平均值的大小来显示最终成绩等级(G、P或F)。
阅读全文