汇编程序自动跳出问题,是内存原因吗?
这个是在网上找的高射炮打飞机的代码,自己改了改,能运行,就是会突然自动跳出,估计是内存不足的原因(哪个地方没有释放),找了好久,没找到问题,求高人赐教,不胜感激~~~~ DATA SEGMENT
FACE DB 1,0AH,4,0
FACE1 DB 1,01H,4,0
DB 2,71H,1,-1
DB 4,7CH,1,0
DB 2,71H,1,1
FACE2 DB 1,03H,4,0
TANK DB 0B1H,70H,0,0
DB 2,71H,1,-1
DB 4,7CH,1,0
DB 2,71H,1,1
BALL DB 4,0AH,0,0
COUNT DB 0
X DB 0
Y DB 0
TANK_X DB 10
TANK_Y DB 23
BALL_X DB 10
BALL_Y DB 23
FACE_X DB 11
FACE_Y DB 3
FACE1_X DB 10
FACE1_Y DB 1
FACE2_X DB 16
FACE2_Y DB 2
C_BOOR DB 1
C1_BOOR DB 1
C2_BOOR DB 1
FLAGE DB 1
KEYSPACE DB 1
KEYLEFT DB 1
KEYRIGHT DB 1
KEYQUIT DB 1
OLDSEG DW ?
OLDOFFSET DW ?
SCORE DW 0
FLAG DB 0
MSGSCORE DB 'SCORE: ','$'
MSGVER DB 'PLEASE PRESS "q" TO QUIT','$'
MSGEND DB 'YOUR SCORE IS ','$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
XOR AX,AX
CALL GAMEINIT
A:
MOV AH,FACE_X ;笑脸
MOV AL,FACE_Y
MOV X,AH
MOV Y,AL
LEA SI,FACE
MOV CX,1
CALL DRAW
MOV AH,FACE1_X ;笑脸1
MOV AL,FACE1_Y
MOV X,AH
MOV Y,AL
LEA SI,FACE1
MOV CX,1
CALL DRAW
MOV AH,FACE2_X;笑脸2
MOV AL,FACE2_Y
MOV X,AH
MOV Y,AL
LEA SI,FACE2
MOV CX,1
CALL DRAW
CALL GAMESTART
MOV DH,BALL_X ;判断是否击中
CMP DH,FACE_X
JNE AA
MOV DL,BALL_Y
CMP DL,FACE_Y
JNE AA ;击中
ADD SCORE,10
CALL SOUND
AA:
MOV DH,BALL_X;判断是否击中1
CMP DH,FACE1_X
JNE CC
MOV DL,BALL_Y
CMP DL,FACE1_Y
JNE CC
ADD SCORE,50
CALL SOUND
CC:
MOV DH,BALL_X;判断是否击中2
CMP DH,FACE2_X
JNE BB
MOV DL,BALL_Y
CMP DL,FACE2_Y
JNE BB
ADD SCORE,50
CALL SOUND
BB:
;call delay
MOV FLAGE,0
MOV AH,FACE_X
MOV AL,FACE_Y
MOV X,AH
MOV Y,AL
LEA SI,FACE
MOV CX,1
CALL DRAW
MOV FLAGE,0
MOV AH,FACE1_X
MOV AL,FACE1_Y
MOV X,AH
MOV Y,AL
LEA SI,FACE1
MOV CX,1
CALL DRAW
MOV FLAGE,0
MOV AH,FACE2_X
MOV AL,FACE2_Y
MOV X,AH
MOV Y,AL
LEA SI,FACE2
MOV CX,1
CALL DRAW
CALL SHOWVER
CALL SHOWSCORE
CALL RAND ;产生飞行高度参数,0-2的随机数
MOV C_BOOR,BL
SUB C_BOOR,1
MOV BL,C_BOOR
ADD FACE_Y,BL
CALL RAND ;产生飞行1高度参数,0-2的随机数
MOV C1_BOOR,BL
SUB C1_BOOR,1
MOV BL,C_BOOR
ADD FACE1_Y,BL
CALL RAND ;产生飞行2高度参数,0-2的随机数
MOV C2_BOOR,BL
SUB C2_BOOR,1
MOV BL,C_BOOR
ADD FACE2_Y,BL
CMP COUNT,17
JB B
ADD FACE_X,1
ADD FACE1_X,2 ;笑脸走速度
ADD FACE2_X,-1
B:
CMP FACE_X,100
JB AA1
MOV FACE_X,1
AA1:
CMP FACE1_X,100
JB AA2
MOV FACE1_X,1
AA2:
CMP FACE2_X,1
JA AA3
MOV FACE2_X,100
AA3:
MOV FLAGE,1
CMP KEYQUIT,0
JE EN
JMP A
EN:
CALL GAMEEND
MOV AH,04CH
INT 21H
;游戏初始化
GAMEINIT PROC
PUSH AX
MOV AH,0
MOV AL,3
INT 10H
MOV AL,1CH
MOV AH,35H
INT 21H
MOV OLDSEG,ES
MOV OLDOFFSET, BX
PUSH DS
MOV DX,OFFSET FUN
MOV AX,SEG FUN
MOV DS,AX
MOV AH,25H
MOV AL,1CH
INT 21H
POP DS
POP AX
RET
GAMEINIT ENDP
;游戏开始
GAMESTART PROC
PUSH AX
CALL TESTKEY
CMP KEYLEFT,0
JA A2
ADD TANK_X,-1
A2:
CMP KEYRIGHT,0
JA A3
ADD TANK_X,1
A3:
CALL DRAW_TANK
CMP BALL_Y,0
JA A1
CMP KEYSPACE,0
JA A4
MOV AL,TANK_X
MOV BALL_X,AL
MOV AL,TANK_Y
MOV BALL_Y,AL
A4:
MOV KEYSPACE,1
A1:
MOV KEYLEFT,1
MOV KEYRIGHT,1
POP AX
RET
GAMESTART ENDP
RAND PROC ;产生随机数
PUSH CX
PUSH DX
PUSH AX
;STI
MOV AH,0 ;读时钟计数器值
INT 1AH
MOV AX,DX ;清高6位
AND AH,3
MOV DL,3 ;除3,产生0~2余数
DIV DL
MOV BL,AH ;余数存BX,作随机数
POP AX
POP DX
POP CX
RET
RAND ENDP
SHOWSCORE PROC
PUSH AX
PUSH DX
MOV BH,0
MOV AH,2
MOV DH,0
MOV DL,1
INT 10H
LEA DX,MSGSCORE
CALL MSG
MOV AX,SCORE
CALL HEX2DEC
POP DX
POP AX
RET
SHOWSCORE ENDP
SHOWVER PROC
PUSH AX
PUSH DX
MOV BH,0
MOV AH,2
MOV DH,0
MOV DL,25
INT 10H
LEA DX,MSGVER
CALL MSG
POP DX
POP AX
RET
SHOWVER ENDP
MSG PROC
PUSH AX
PUSH DX
MOV AH,9
INT 21H
POP DX
POP AX
RET
MSG ENDP
DIVDEC PROC
PUSH BX
XOR DX,DX
DIV CX
MOV BX,DX
XOR CX,CX
CMP FLAG,CL
JE DL1
DL2:
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
JMP DLE
DL1:
CMP AL,0
JE DLE
MOV FLAG,1
JMP DL2
DLE:
MOV AX,BX
POP BX
RET
DIVDEC ENDP
;ax=inputnumber
HEX2DEC PROC
PUSH AX
PUSH CX
PUSH DX
MOV CX,10000
CALL DIVDEC
MOV CX,1000
CALL DIVDEC
MOV CX,100
CALL DIVDEC
MOV CX,10
CALL DIVDEC
MOV FLAG,1
MOV CX,1
CALL DIVDEC
MOV FLAG,0
POP DX
POP CX
POP AX
RET
HEX2DEC ENDP
FUN PROC NEAR
PUSH AX
PUSH CX
PUSH DS
MOV AX,DATA
MOV DS,AX
STI
INC COUNT
CMP COUNT,18
JB F1
MOV COUNT,0
F1:
CLI
POP DS
POP CX
POP AX
IRET
FUN ENDP
TESTKEY PROC
PUSH AX
PUSH DX
MOV AH,6
MOV DL,0FFH
INT 21H
CMP AL,20H
JNE T1
MOV KEYSPACE,0
T1:
CMP AL,'a'
JNE T2
MOV KEYLEFT,0
T2:
CMP AL,'d'
JNE T3
MOV KEYRIGHT,0
T3:
CMP AL,'q'
JNE T4
MOV KEYQUIT,0
T4:
MOV AH,0CH
MOV AL,6
INT 21H
POP DX
POP AX
RET
TESTKEY ENDP
SOUND PROC
PUSH AX
PUSH DX
MOV AH,2
MOV DL,07H
INT 21H
POP DX
POP AX
RET
SOUND ENDP
DRAW_BALL PROC
MOV AH,BALL_X
MOV AL,BALL_Y
MOV X,AH
MOV Y,AL
LEA SI,BALL
MOV CX,1
CMP KEYSPACE,1
JE DB1
CALL DRAW
CALL DELAY
MOV FLAGE,0
MOV AH,BALL_X
MOV AL,BALL_Y
MOV X,AH
MOV Y,AL
LEA SI,BALL
MOV CX,1
CALL DRAW
MOV FLAGE,1
ADD BALL_X,0
ADD BALL_Y,-1
DB1:
RET
DRAW_BALL ENDP
DRAW_TANK PROC
MOV AH,TANK_X
MOV AL,TANK_Y
MOV X,AH
MOV Y,AL
LEA SI,TANK
MOV CX,4
CALL DRAW
CALL DRAW_BALL
CALL DELAY
MOV FLAGE,0
MOV AH,TANK_X
MOV AL,TANK_Y
MOV X,AH
MOV Y,AL
LEA SI,TANK
MOV CX,4
CALL DRAW
MOV FLAGE,1
;add tank_x,1
;add tank_y,0
RET
DRAW_TANK ENDP
;si=aray x=dh,y=dl,count ,flage
DRAW PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
D1:
;push dx
MOV DH,Y
MOV DL,X
CMP CX,0
JZ DE
ADD DH,[SI+2]
ADD DL,[SI+3]
MOV AH,2
MOV BH,0
INT 10H
PUSH CX
MOV CX,1
MOV AH,9
MOV AL,[SI]
MOV BH,0
MOV BL,[SI+1]
CMP FLAGE,0
JNE D2
MOV BL,00H
D2:
INT 10H
POP CX
ADD SI,4
DEC CX
;pop dx
JMP D1
DE:
POP DX
POP BX
POP CX
POP AX
RET
DRAW ENDP
DELAY PROC
PUSH CX
PUSH DX
MOV CX,1000
DE1:
MOV DX,32767
DE2:
DEC DX
CMP DX,0
JNZ DE2
LOOP DE1
POP DX
POP CX
RET
DELAY ENDP
;游戏结束
GAMEEND PROC
MOV BH,0
MOV AH,2
MOV DH,10
MOV DL,25
INT 10H
LEA DX,MSGEND
CALL MSG
MOV AX,SCORE
CALL HEX2DEC
MOV AH,1
INT 21H
MOV DX,OLDOFFSET
MOV AX,OLDSEG
MOV DS,AX
MOV AL,1CH
MOV AH,25H
INT 21H
RET
GAMEEND ENDP
CODE ENDS
END START