输入成绩 输出所属成绩等级

规定成绩为三位数:000~100
080~100:优秀
060~079:良好
000~059:不及格

stack segment
stack ends

data segment
string db 'please input your grades: $'
result_1 db 0ah,0dh,'bu ji ge ! $'
result_2 db 0ah,0dh,'liang hao ! $'
result_3 db 0ah,0dh,'you xiu ! $'
grades db 0,0,0
data ends

code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax

lea dx,string
mov ah,09h
int 21h

mov cx,3
mov bx,offset grades
input:
mov ah,01h
int 21h
mov [bx],al
inc bx
loop input


mov bx,offset grades
cmp [bx], byte ptr '1'
je youxiu
inc bx
cmp [bx], byte ptr '8'
jae youxiu
cmp [bx],byte ptr '6'
jae lianghao

bujiege:
mov dx,offset result_1
mov ah,09h
int 21h
jmp jieshu

youxiu:
mov dx,offset result_3
mov ah,09h
int 21h
jmp jieshu

lianghao:
mov dx,offset result_2
mov ah,09h
int 21h
jmp jieshu

jieshu:
mov ax,4c00h
int 21h

code ends
end start

结果

汇编语言--输入成绩 输出所属成绩等级_偏移量


总结

  • 比较字符 cmp [bx], byte ptr ‘8’ byte ptr不可以少
  • 在这里,对于三位成绩,采用的方法是:先申请三个db单元,再循环三次输入,利用偏移量对其进行一系列操作