键盘分别输入3个学生的成绩,如果低于60分,则F (Fail),如 果高于或等于90 分则显示 G (good),否则显示 P (Pass)。编写8086汇编语言实现每个学生成绩等级
时间: 2024-02-26 17:58:42 浏览: 149
好的,下面是汇编代码实现:
```
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 OF STUDENT 1: $'
MSG8 DB 'FINAL GRADE OF STUDENT 2: $'
MSG9 DB 'FINAL GRADE OF STUDENT 3: $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
; input first student's grades
LEA DX, MSG1
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE1, AL
LEA DX, MSG2
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE2, AL
LEA DX, MSG3
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE3, AL
; display first student's 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 first student's final grade
MOV AL, GRADE1
ADD AL, GRADE2
ADD AL, GRADE3
MOV BL, 3
DIV BL
; display first student's final grade
MOV AH, 09H
LEA DX, MSG7
CMP AL, 90
JGE GOOD1
CMP AL, 60
JL FAIL1
MOV DL, 'P'
JMP DISPLAY1
GOOD1:
MOV DL, 'G'
JMP DISPLAY1
FAIL1:
MOV DL, 'F'
DISPLAY1:
MOV MSG7+26, DL
INT 21H
; input second student's grades
LEA DX, MSG1
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE1, AL
LEA DX, MSG2
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE2, AL
LEA DX, MSG3
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE3, AL
; display second student's 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 second student's final grade
MOV AL, GRADE1
ADD AL, GRADE2
ADD AL, GRADE3
MOV BL, 3
DIV BL
; display second student's final grade
MOV AH, 09H
LEA DX, MSG8
CMP AL, 90
JGE GOOD2
CMP AL, 60
JL FAIL2
MOV DL, 'P'
JMP DISPLAY2
GOOD2:
MOV DL, 'G'
JMP DISPLAY2
FAIL2:
MOV DL, 'F'
DISPLAY2:
MOV MSG8+26, DL
INT 21H
; input third student's grades
LEA DX, MSG1
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE1, AL
LEA DX, MSG2
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE2, AL
LEA DX, MSG3
MOV AH, 09H
INT 21H
MOV AH, 01H
INT 21H
SUB AL, 30H
MOV GRADE3, AL
; display third student's 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 third student's final grade
MOV AL, GRADE1
ADD AL, GRADE2
ADD AL, GRADE3
MOV BL, 3
DIV BL
; display third student's final grade
MOV AH, 09H
LEA DX, MSG9
CMP AL, 90
JGE GOOD3
CMP AL, 60
JL FAIL3
MOV DL, 'P'
JMP DISPLAY3
GOOD3:
MOV DL, 'G'
JMP DISPLAY3
FAIL3:
MOV DL, 'F'
DISPLAY3:
MOV MSG9+26, DL
INT 21H
MOV AH, 4CH
INT 21H
CODE ENDS
END START
```
这段代码会要求用户分别输入三个学生的成绩,并将它们存储在内存中。接着,它会计算每个学生的平均成绩,并根据平均成绩的大小来显示每个学生的成绩等级(G、P或F)。
阅读全文