请教汇编问题!
这是一个接数字的游戏,但是有些问题。就是有时候接到数字但是不加分。这是为什么呢?希望达人帮忙看一下谢谢啦.model small
.stack 64
.data
MSG_GRADE DB 'score:',0ah,0dh,'$'
MSG_LINE DB '___','$'
MSG_INFO DB 'left:a right:d exit:q',0ah,0dh,'$'
MSG_O DB 'O','$'
MSG_RESULT DB '00000','$'
line_col DB 39
en_score DB 0
column_cursor db 0
DELAYTIME DB 08h ; 延时时间
Array1 DB 1600 DUP(' '),'$'
Array2 DB 1600 DUP(' '),'$'
.code
;======================================================================
main proc far
mov ax,@data
mov ds,ax
mov es,ax
sub cx,cx ;cx清零
call clr_screen ;清屏
call set_score ;打印输出"score:"
call set_info ;打印输出游戏信息
call under_line ;输出下划线过程
produce_loop:
call produce ;调用产生过程
call drop_down ;调用下落过程
mov ah,01h ;读取键盘状态 ZF=1,无字符输入
int 16h
jnz check
call delay ;调用延时过程
jmp produce_loop
check:
mov ah,00h ;从键盘读入字符,AL=输入字符ASCII码
int 16h
cmp al,'q' ;判断键盘输入的字符是否为'q',若为'q'则退出;否则,调用下划线移动过程
je exit
call move_line ;移动下划线
call score
jmp produce_loop
exit:
mov ax,4c00h
int 21h
main endp
;======================================================================
;清屏
clr_screen proc near
mov ax,0600h
mov bh,58h
mov cx,0000h
mov dx,184fh
int 10h
ret
clr_screen endp
;======================================================================
;设置光标到0000位置,并打印输出提示信息
set_score proc near
mov ah,02h
mov bh,00
mov dh,00
mov dl,00
int 10h
mov ah,09h ;打印输出:“score:”
lea dx,MSG_GRADE
int 21h
ret
set_score endp
;======================================================================
;设置光标到第二行,并打印输出游戏信息
set_info proc near
mov ah,02h
mov bh,00
mov dh,1
mov dl,26
int 10h
mov ah,09h ;打印输出游戏提示信息
lea dx,MSG_INFO
int 21h
ret
set_info endp
;======================================================================
;输出下划线过程
under_line proc near
mov ah,02h ;设置下划线位置
mov bh,00
mov dh,22
mov dl,39
int 10h
mov ah,09h ;打印输出下划线
lea dx,MSG_LINE
int 21h
ret
under_line endp
;======================================================================
;调用产生过程
produce proc near
call rand ;产生随机数
mov ah,02h ;设置光标到第三行第一列
mov bh,00
mov dh,2
mov dl,0
int 10h
add bh,00h
lea si,Array1 ;si指向Array1的首地址
add si,bx ;si加上随即数,跳到数组这个位置
mov byte ptr[si],'O' ;把这个单元的内容置'O'
mov ah,09h ;输出Array1数组中的内容
lea dx,Array1
int 21h
call delay ;延时
ret
produce endp
;======================================================================
;产生随机数
rand proc near
push cx
push dx
push ax
mov ah,0h ;读时钟计数器的值
int 1ah
mov ax,dx
and ah,0
mov dl,77 ;除77,产生0到76的余数
div dl
mov bl,ah ;余数存bl,作随机数
pop ax
pop dx
pop cx
ret
rand endp
;======================================================================
;延时过程
delay proc near
mov ah,0
int 1ah
mov bx,dx
mov ax,0
mov al,DELAYTIME
add bx,ax
delay_loop:
mov ah,0
int 1ah
cmp dx,bx
je delay_end
jmp delay_loop
delay_end:
ret
delay endp
;======================================================================
;调用下落过程
drop_down proc near
call next_column ;'O'向下移动一行
call load_Array1 ;把Array2数组中的内容加载到Array1中
call print_Array1 ;打印输出Array1中的内容
ret
drop_down endp
;======================================================================
;'O'向下移动一行
next_column proc near
lea si,Array1
lea di,Array2
mov cx,1
column_loop:
cmp byte ptr[si],'O' ;判断si的内容是否为'O'
jnz move_si
cmp cx,1520
jnb space
mov bx,di ;bx指向di的位置
add bx,80 ;bx位置加80
mov byte ptr[bx],'O' ;在Array2数组中,对应的bx位置添置'O'
mov byte ptr[si],20h
space:
mov byte ptr[si],20h ;若cx大于或等于1520且si的内容为'O',则直接将其内容置为空格
move_si:
cmp cx,1600 ;判断cx的值,若cx=1600,则数组扫描完毕,返回
jz next_column_end
inc si ;否则,si加1
inc di ;di加1
inc cx ;cx加1
jmp column_loop
next_column_end:
ret
next_column endp
;======================================================================
;把Array2数组中的内容加载到Array1中
load_Array1 proc near
lea si,Array1
lea di,Array2
mov cx,1
load_loop:
cmp byte ptr[di],'O' ;判断di的内容是否为'O',若为'O',则si的相应位置置'O',di的内容置空格
jnz move_di
mov byte ptr[si],'O'
mov byte ptr[di],20h
move_di:
cmp cx,1600 ;判断cx的值,若cx=1600,则数组扫描完毕,返回
jz load_Array1_end
inc di
inc si
inc cx
jmp load_loop
load_Array1_end:
ret
load_Array1 endp
;======================================================================
;打印输出Array1中的内容
print_Array1 proc near
mov ah,02h ;设置光标到第三行第一列
mov bh,00
mov dh,2
mov dl,0
int 10h
mov ah,09h ;打印输出Array1的内容
lea dx,Array1
int 21h
ret
print_Array1 endp
;======================================================================
;移动下划线
move_line proc near
cmp al,'a'
je left ;输入字符为a,下划线左移
cmp al,'d'
je right ;输入字符为d,下划线右移
jmp move_line_end
left:
cmp line_col,0 ;判断下划线是否到最左端,若到最左端则原地踏步
jz end_left
mov dl,line_col ;左移列数减一
dec dl
mov line_col,dl
jmp move_line_end
right:
cmp line_col,79 ;判断下划线是否到最右端,若到最右端则原地踏步
jz end_right
mov dl,line_col ;右移列数加一
inc dl
mov line_col,dl
jmp move_line_end
end_left:
mov ah,02h
mov bh,00
mov dh,22
mov dl,00
int 10h
jmp move_line_end
end_right:
mov ah,02h
mov bh,00
mov dh,22
mov dl,79
int 10h
move_line_end:
mov ah,02h ;设置光标到22行line_col列
mov bh,00
mov dh,22
mov dl,line_col
int 10h
mov ax,0601h ;对22行进行清屏
mov bh,58h
mov cx,1600h
mov dx,164fh
int 10h
mov ah,09h ;输出下划线
lea dx,MSG_LINE
int 21h
ret
move_line endp
;======================================================================
;计算得分
score proc near
score_begin:
mov ah,02h ;设置光标在第22行,第0列
mov bh,00
mov dh,21d
mov dl,column_cursor
int 10h
mov ah,08h ;读取光标处的字符
int 10h
cmp al,'O' ;判断字符是否为O,若为O,跳到score_second
je score_second
mov dl,column_cursor
inc dl ;列数加1
mov column_cursor,dl
cmp dl,80 ;判断列数是否为80,若不为80则继续循环,否则返回
jne score_begin
jmp score_end
score_second:
mov dl,column_cursor
cmp dl,line_col ;判断字母O的列数与下划线的列数是否相等,若相等则加分;否则,返回
je score_add
jmp score_end
score_add:
mov al,en_score ;分数加一
inc al
mov en_score,al
mov ah,0 ;将分数转化成字符串,存到MSG_RESULT中
mov al,en_score
mov bx,10
lea di,MSG_RESULT
add di,4
tostring:
mov dx,0
div bx
add dl,30h ;加30H,转化成字符
mov [di],dl
dec di
cmp ax,0
jne tostring ;若商不为0,则继续循环
lea di,MSG_RESULT
move0:
cmp byte ptr[di],'0'
jnz output_score
inc di
jmp move0
output_score:
mov ah,02h ;设置光标到第一行第八列,输出分数
mov bh,00
mov dh,0
mov dl,7
int 10h
mov ah,09h
mov dx,di
int 21h
score_end:
ret
score endp
;======================================================================
end main