📄 040630418.asm
字号:
;4.30.asm
.model small
.stack
.data
string db 5 dup(30h) ;存储每个分数段学生的数量
string1 db 'Please enter a number:',0dh,0ah,'$'
string2 db 'Please enter scores:',0dh,0ah,'$'
string3 db 'You have entered a wrong score!',0dh,0ah,'$'
string4 db 'Here are the result:',0dh,0ah,'$'
string5 db 0dh,0ah,' ','$'
string6 db 0dh,0ah,' ','$'
string7 db 0dh,0ah,' ','$'
score db 50 dup('$')
.code
.startup
mov si,offset score
mov di,offset string
mov bh,00h
mov ah,09h
mov dx,offset string5
int 21h
mov dx,offset string1
int 21h
mov dx,offset string7
int 21h
call read ;设置输入的数的个数cx
mov cx,ax
mov ah,02h
mov dl,0ah
int 21h
mov ah,09h
mov dx,offset string5
int 21h
mov dx,offset string2
int 21h
mov dx,offset string5
int 21h
again: cmp cx,00h
jz final
call read ;调用子程序read
push ax
push dx
mov ah,02h
mov dx,' '
int 21h
pop dx
pop ax
cmp ax,'-'
jz next
cmp ax,0 ;判断输入数的范围,如果小于0或者大于100,将显示出错信息,并重新输入(即调用next)
jb next
cmp ax,100
ja next
call count ;调用count,返回该数字所在区域,以01h、02h等返回
cmp dl,01h
jz score1
cmp dl,02h
jz score2
cmp dl,03h
jz score3
cmp dl,04h
jz score4
cmp dl,05h
jz score5
next: push dx
push ax
mov ah,09h
mov dx,offset string5
int 21h
mov dx,offset string3
int 21h
mov dx,offset string5
int 21h
pop ax
pop dx
jmp again
score1: add [di],01h ;为相应的内存的数加1,并储存该数字
mov [si],al
inc si
dec cx
jmp again
score2: add [di+01h],01h
mov [si],al
inc si
dec cx
jmp again
score3: add [di+02h],01h
mov [si],al
inc si
dec cx
jmp again
score4: add [di+03h],01h
mov [si],al
inc si
dec cx
jmp again
score5: add [di+04h],01h
mov [si],al
inc si
dec cx
jmp again
final: xor cx,cx
mov di,offset string
mov ah,02h
mov dl,0dh
int 21h
mov dl,0ah
int 21h
mov ah,09h
mov dx,offset string5
int 21h
mov dx,offset string4 ;说明将输出结果
int 21h
mov dx,offset string6
int 21h
mov ah,02h
mov dl,'E'
int 21h
mov dl,' '
int 21h
mov dl,'D'
int 21h
mov dl,' '
int 21h
mov dl,'C'
int 21h
mov dl,' '
int 21h
mov dl,'B'
int 21h
mov dl,' '
int 21h
mov dl,'A'
int 21h
mov dl,0dh
int 21h
mov dl,0ah
int 21h
mov ah,09h
mov dx,offset string6
int 21h
go: mov ah,02h ;逐个输出结果
mov dl,[di]
int 21h
mov dl,' '
int 21h
inc cx
inc di
cmp cx,4
jbe go
.exit 0
;
read proc
push bx
push cx
push dx
xor bx,bx
xor cx,cx
read1: mov ah,01h ;每次读一位,并转化为相应的二进制数,以非0-9的数结束
int 21h
cmp al,'-'
jz read3
cmp al,'0' ;判断输入的一位数是否在0-9
jb read2
cmp al,'9'
ja read2
sub al,30h
shl bx,1
mov dx,bx
shl bx,1
shl bx,1
add bx,dx
mov ah,0
add bx,ax
jmp read1
read2: mov ax,bx
pop dx
pop cx
pop bx
ret
read3: pop bx
pop cx
pop dx
ret
read endp
count proc
push si
push di
cmp al,59
jbe cs1
cmp al,69
jbe cs2
cmp al,79
jbe cs3
cmp al,89
jbe cs4
mov dl,05h
pop di
pop si
ret
cs1: mov dl,01h
pop di
pop si
ret
cs2: mov dl,02h
pop di
pop si
ret
cs3: mov dl,03h
pop di
pop si
ret
cs4: mov dl,04h
pop di
pop si
ret
count endp
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -