汇编语言(二十五)之成绩分段统计
已知一个班的成绩,进行60,70,80,90,100分段统计
程序运行:
代码:
datas segment
students_number dw 10
students dw 76,69,84,90,73,88,99,63,100,80
s6 dw 0h
s7 dw 0h
s8 dw 0h
s9 dw 0h
s10 dw 0h
output_s6 db 's6=$'
output_s7 db 0dh,0ah,'s7=$'
output_s8 db 0dh,0ah,'s8=$'
output_s9 db 0dh,0ah,'s9=$'
output_s10 db 0dh,0ah,'s10=$'
datas ends
stacks segment stack
db 100h dup(?)
stacks ends
codes segment
assume cs:codes,ds:datas,ss:stacks
main proc far
start:
push ds
mov ax,0h
push ax
mov ax,datas ;初始化ds
mov ds,ax
mov cx,students_number
cmp cx,0
jz no_student
mov si,0
s:
mov ax,students[si]
cmp ax,100
ja next
jb low100
inc s10 ;为100,计数器s10加一
jmp next
low100:
cmp ax,90
jb low90
inc s9 ;为90-99,计数器s9加一
jmp next
low90:
cmp ax,80
jb low80
inc s8 ;为80-89,计数器s8加一
jmp next
low80:
cmp ax,70
jb low70
inc s7 ;为70-79,计数器s7加一
jmp next
low70:
cmp ax,60
jb next
inc s6 ;为60-69,计数器s6加一
next:
add si,type students
loop s
lea dx,output_s6 ;输出s6
mov ah,9
int 21h
mov ax,s6
call print_decimal
lea dx,output_s7 ;输出s7
mov ah,9
int 21h
mov ax,s7
call print_decimal
lea dx,output_s8 ;输出s8
mov ah,9
int 21h
mov ax,s8
call print_decimal
lea dx,output_s9 ;输出s9
mov ah,9
int 21h
mov ax,s9
call print_decimal
lea dx,output_s10 ;输出s10
mov ah,9
int 21h
mov ax,s10
call print_decimal
jmp exit
no_student:
exit:
ret
main endp
print_decimal proc near uses ax bx cx dx
mov cx,0
mov bx,10
de:
xor dx,dx
div bx
push dx
inc cx
cmp ax,0
jnz de
de1:
pop dx
add dl,30h
mov ah,2
int 21h
loop de1
ret
print_decimal endp
codes ends
end main