贪食蛇帮忙看看改改,新手刚学汇编
;****************************************************这是贪食蛇游戏程序*************************************************;passMaster关数控制子程序
;randomMaster"食物"产生控制子程序
;rulelMaster规则控制子程序
;operatMaster操作控制子程序
;printMaster输出控制子程序
;diePrint游戏结束
assume cs:codesg
datasg segment
db '*','#','you die!'
datasg ends
stacksg segment
dw 50 dup(0)
stacksg ends
codesg segment
start: mov ax,datasg
mov ds,ax
mov ax,stacksg
mov ss,ax
mov ax,0b872h
mov es,ax ;起始位置为屏幕中间
jmp p1 ;第一关开始
e: mov ax,4c00h
int 21h
passMaster: push ax ;关数控制子程序
push bx
push cx
push di
mov ax,14h ;蛇的长度为20后就进入下一关,参数bx: 蛇的长度,di:记录关数
cmp bx,ax
je s0
pop di
pop cx
pop bx
pop ax
ret
s0: mov ax,3h
cmp di,ax
pop di
pop cx
pop bx
pop ax
je p3
jmp p2
randomMaster:push ax ;“食物”产生控制子程序
push bx
push cx
push si
push dx
push es
mov ah,0h ;依靠时钟产生一个随机数
int 1ah
mov dh,0h
mov cx,7h
n1: adc ax,dx
loop n1
mov dx,ax
mov ax,0b8000h
mov es,ax
mov bx,dx
mov al,ds:
mov es:,al
pop es
pop dx
pop si
pop cx
pop bx
pop ax
ret
ruleMaster: push ax ;规则控制子程序
push bx
push cx
push si
push di
push dx
push es
mov cx,50h
mov bx,si
mov di,0h
;上下边缘
k0: mov ax,di
cmp ax,bx
je die
adc di,0f00h ;下边缘
mov ax,di
cmp ax,bx
je die
sbb di,0f00h
inc di
inc di
loop k0
mov cx,17h
mov bx,si
mov di,0a0h
;左右边缘
k1: mov ax,di
cmp ax,bx
je die
adc di,0a0h ;右边缘
mov ax,di
cmp ax,bx
je die
sbb di,0a0h
inc di
inc di
loop k1
jmp m
die:call diePrint
jmp e
m: mov al,es:
mov bl,ds:
cmp al,bl
je die
mov bx,0h
cmp ax,bx
jne pr
pop es
pop dx
pop di
pop si
pop cx
pop bx
pop ax
ret
pr: pop es
pop dx
pop di
pop si
pop cx
pop bx
pop ax
push si
inc bx
ret
operatMaster:push ax ;操作控制子程序
push bx
push cx
push es
mov ah,0h
int 16h
mov bh,48h
cmp ah,bh
je up
mov bh,50h
cmp ah,bh
je down
mov bh,4bh
cmp ah,bh
je left
mov bh,4dh
cmp ah,bh
je right
mov bh,1h
cmp ah,bh
je e
jmp w
up: sbb si,0a0h
jmp w
down:adc si,0a0h
jmp w
left:sbb si,1h
jmp w
right:adc si,1h
w: pop es
pop cx
pop bx
pop ax
ret
printMaster:push ax ;输出控制子程序
push cx
r1: call yanshi
mov al,ds:
mov es:,al
loop r1
pop cx
pop ax
pop si
ret
p1: nop
a0: mov cx,0fffeh ;第一关
call randomMaster
a1: call yanshi
call ruleMaster
call operatMaster
call printMaster
call passMaster
loop a1
loop a0
p2: nop ;第二关
p3: nop ;第三关
dieprint: push ax
push bx
push si
push es
push cx
mov si,0h
mov bx,2h
mov cx,8h
ko: mov al,ds:
mov es:,al
inc bx
loop ko
pop cx
pop es
pop si
pop bx
pop ax
ret
yanshi:
push ax
push bx
push cx
mov bl,4
loop2: mov cx,33144
call WAITP
dec bl
jnz loop2
WAITP PROC
XOR AX,AX
LOOP1: IN AL,61H
AND AL,10H
CMP AL,AH
JELOOP1
MOV AH,AL
LOOP LOOP1
WAITP ENDP
pop cx
pop bx
pop ax
ret
codesg ends
end start
页:
[1]