汇编语言写的贪吃蛇小游戏源代码Word格式.docx
《汇编语言写的贪吃蛇小游戏源代码Word格式.docx》由会员分享,可在线阅读,更多相关《汇编语言写的贪吃蛇小游戏源代码Word格式.docx(27页珍藏版)》请在冰豆网上搜索。
![汇编语言写的贪吃蛇小游戏源代码Word格式.docx](https://file1.bdocx.com/fileroot1/2022-11/24/bdd9d6c3-b8e6-4e5f-b60f-f825ede1f125/bdd9d6c3-b8e6-4e5f-b60f-f825ede1f1251.gif)
movfrow,10
movfcol,6
movdh,10
movdl,26
movah,2
movbh,0
int10h
movah,9
leadx,msg1
int21h
movdh,11
movdl,7
leadx,way
movdh,12
movdl,20
leadx,msg
movah,0
int16h
movah,6
moval,0
movch,0
movcl,0
movdh,24
movdl,79
movbh,10
movdh,0
movdl,0
leadx,score1
movdl,15
leadx,writer
leadx,email
movscore2,48
pushes:
[9*4];
将原int9入口地址保存
popds:
[0]
[9*4+2]
[2]
movwordptres:
[9*4],offsetint9;
更改中断向量表
moves:
[9*4+2],cs
jmpaa
writemacrorow,col,cnt;
宏定义用于向当前光标处输出字符
pushbx
pushcx
pushdx
movdh,row
movdl,col
movah,2
movbh,0
int10h
movah,9
movbl,11
movcx,1
leadi,cnt;
50
moval,[di]
popdx
popcx
popbx
endm
readhmacrorow,col;
宏定义用于读出当前光标处字符
pushdx
pushax
pushbx
movdh,row
movdl,col
movah,08h
movpst,al
popbx
popax
popdx
wnearmacro;
宏定义只用在readcg宏中当readcg的所有判断都不成立调用此宏
localwnext1
localwnext2
localwnext3
localwnext4
decdh
readhdh,dl
cmppst,1
jnewnext1
writedh,dl,tal2
jmpwnext4
wnext1:
incdh
decdl
jnewnext2
wnext2:
incdl
jnewnext3
wnext3:
jnewnext4
wnext4:
readcgmacrorow,col;
宏定义用于改变判断出来的字符
localtnup,tnup1,tnup2,tnlf,tnlf1,tnlf2,tndn,tndn1,tndn2,tnrt,tnrt1,tnrt2,goout
writedh,dl,tal1
decrow
cmppst,4
jnetnup1
jmptnup2
tnup1:
jmpnearptrtnup
tnup2:
writedh,dl,blk
jnetnup
jmpnearptrgoout
tnup:
deccol
jnetnlf1
jmptnlf2
tnlf1:
jmpnearptrtnlf
tnlf2:
jnetnlf
tnlf:
incrow
jnetndn1
jmptndn2
tndn1:
jmpnearptrtndn
tndn2:
jnetndn
tndn:
inccol
jnetnrt1
jmptnrt2
tnrt1:
jmpnearptrtnrt
tnrt2:
jnetnrt
tnrt:
wnear
goout:
addone:
;
此标号功能是将蛇身增加一
incscore2
movdh,1
movcx,23
cmpad1:
pushcx
movcx,79
cmpad2:
cmppst,2
jnenextad3
jmpnextad4
nextad3:
jmpnearptrnextad
nextad4:
writedh,dl,snk
jnenatup
jmpouto
natup:
jnenatlf
natlf:
jnenatdn
natdn:
jnenatrt
natrt:
outo:
popcx
jmpnearptrendad
nextad:
jmpnextad2
chgad2:
jmpnearptrcmpad2
nextad2:
loopchgad2
subdl,79
jmpnextad1
chgad1:
jmpnearptrcmpad1
nextad1:
loopchgad1
endad:
jmpnearptrcrtf
aa:
从这开始产生最原始的蛇
movaddrs,offsetturnright
movdh,10
movdl,1
movcx,3
wrt:
loopwrt
movlen,6
jmpwrt1
ovflw:
当蛇碰壁或自身转到此游戏结束
movbh,7
movdh,17
movdl,17
leadx,gmov
movax,0;
恢复int9中断
pushds:
popes:
[9*4]
stop:
cmpal,'
r'
jeaa1
jmpaa2
aa1:
jmpnearptrstart
aa2:
q'
jnestop
jmpnearptrexit
wrt1:
此处蛇行走过程的无限循环
calldly
cmpdh,25
jeovflw
cmpdl,80
cmpdh,0
cmpdl,-1
leaax,turnright
cmpaddrs,ax
jnetonxt2
jetonxt1
jmptonxt2
tonxt1:
jmpovflw
tonxt2:
leaax,turnup
jnetonxt4
jetonxt3
jmptonxt4
tonxt3:
tonxt4:
leaax,turndown
jnetonxt6
jetonxt5
jmptonxt6
tonxt5:
tonxt6:
leaax,turnback
jnetonxt8
jetonxt7
jmptonxt8
tonxt7:
tonxt8:
jmpnexta
crtf1:
jmpnearptraddone
crtf:
callrand1
callrand2
incfrow
movah,frow
moval,fcol
check1:
check2:
jenextn
jmpnextnn
nextn:
cmpax,dx
jecrtf
nextnn:
loopcheck2
loopcheck1
writefrow,fcol,food
nexta:
jecrtf12
jmpcrtf13
crtf12:
jmpnearptrcrtf1
crtf13:
cmpscore2,58
jlnormal
movscore2,49
incscore0
normal:
movdl,8
writedh,dl,score2
adddl,score0
writedh,dl,zero
cmpadrs,17
jejmp1
cmpadrs,145
cmpadrs,31
jejmp2
cmpadrs,159
cmpadrs,32
jejmp3
cmpadrs,160
cmpadrs,30
jejmp4
cmpadrs,158
jmpaddrs
jmp1:
leaax,turndown
cmpax,addrs
movaddrs,offsetturnup
jmpnearptrturnup
jmp2:
movaddrs,offsetturndown
jmpnearptrturndown
jmp3:
jmpnearptrturnright
jmp4:
movaddrs,offsetturnback
jmpnearptrturnback
turnright:
此处实现蛇向左走
cmpr1:
cmpr2:
jenextr4
jmpnearptrnextr
nextr4:
readcgdh,dl
jmpnearptrendr
nextr:
jmpnextr2
chgr2:
jmpnearptrcmpr2
nextr2:
loopchgr2
jmpnextr1
chgr1:
jmpnearptrcmpr1
nextr1:
loopchgr1
endr:
jmpnearptrwrt1
turnup:
此处实现蛇向上走
cmpu1:
cmpu2:
jnenextu3
jmpnextu4
nextu3:
jmpnearptrnextu
nextu4:
jmpnearptrendu
nextu:
jmpnextu2
chgu2:
jmpnearptrcmpu2
nextu2:
loopchgu2
jmpnextu1
chgu1:
jmpnearptrcmpu1
nextu1:
loopchgu1
endu:
turndown:
此处实现蛇向下走
cmpd1:
cmpd2:
jnenextd3
jmpnextd4
nextd3:
jmpnearptrnextd
nextd4:
jmpnearptrendd
nextd:
jmpnextd2
chgd2:
jmpnearptrcmpd2
nextd2:
loopchgd2
jmpnextd1
chgd1:
jmpnearptrcmpd1
nextd1:
loopchgd1
endd:
turnback:
此处实现蛇向右走
cmpb1:
cmpb2:
jnenextb3
jmpnextb4
nextb3:
jmpnearptrnextb
nextb4:
jmpnearptrendb
nextb:
jmpnextb2
chgb2:
jmpnearptrcmpb2
nextb2:
loopchgb2
jmpnextb1
chgb1:
jmpnearptrcmpb1
nextb1:
loopchgb1
endb:
exit:
movah,4ch
int9:
更改后的中断服务程序
inal,60h
movadrs,al
moval,20h
out20h,al
iret
DLYPROCnear;
延时子程序
PUSHCX
PUSHDX
MOVDX,10000
DL1:
MOVCX,9801
DL2:
LOOPDL2
DECDX
JNZDL1
POPDX
POPCX
RET
DLYENDP
RAND1PROC
PUSHAX
STI
MOVAH,0;
读时钟计数器值
INT1AH
MOVAX,DX;
清高6位
ANDAH,3
MOVDL,23;
除23,产生0~23余数
DIVDL
MOVfrow,AH;
余数存frow,作随机行数
POPAX
RAND1ENDP
RAND2PROC
MOVDL,79;
除79,产生0~79余数
MOVfcol,AH;
余数存fcol,作随机列数
RAND2ENDP
CODEENDS
ENDstart