汇编语言编写贪吃蛇游戏.doc

上传人:数据九部 文档编号:10238171 上传时间:2021-05-02 格式:DOC 页数:20 大小:90KB
返回 下载 相关 举报
汇编语言编写贪吃蛇游戏.doc_第1页
第1页 / 共20页
汇编语言编写贪吃蛇游戏.doc_第2页
第2页 / 共20页
汇编语言编写贪吃蛇游戏.doc_第3页
第3页 / 共20页
汇编语言编写贪吃蛇游戏.doc_第4页
第4页 / 共20页
汇编语言编写贪吃蛇游戏.doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《汇编语言编写贪吃蛇游戏.doc》由会员分享,可在线阅读,更多相关《汇编语言编写贪吃蛇游戏.doc(20页珍藏版)》请在三一文库上搜索。

1、DATA SEGMENT dw 0,0 snk db 1 blk db 32 food db 3 tal1 db 4 tal2 db 2 adrs db 5 len db ? pst db ? addrs dw ? frow db ? fcol db ? hwrt db ? gmov db game over press r to restart press q to quit $ score1 db score :$ score2 db ? score0 db 1 zero db 48 writer db Developer: Geniusdot $ email db e-mail: $ m

2、sg1 db The way to play the game:$ way db press w to up ,press s to down,press a to left,press d to right$ msg db Press any key(except a,s,d,w) to start$ DATA ENDS STACK SEGMENT stack db 200 dup(0) STACK ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK start: mov ax,data mov ds,ax mov ax,0 mov es,ax

3、 mov frow,10 mov fcol,6 mov dh,10 mov dl,26 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,msg1 int 21h mov dh,11 mov dl,7 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,way int 21h mov dh,12 mov dl,20 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,msg int 21h mov ah,0 int 16h mov ah,6 mov al,0 mov ch,0 mov cl,0 m

4、ov dh,24 mov dl,79 mov bh,10 int 10h mov dh,0 mov dl,0 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,score1 int 21h mov dl,15 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,writer int 21h mov ah,9 lea dx,email int 21h mov score2,48 push es:9*4 ;将原int9入口地址保存 pop ds:0 push es:9*4+2 pop ds:2 mov word ptr es:9*4

5、,offset int9 ;更改中断向量表 mov es:9*4+2,cs jmp aa write macro row,col,cnt ;宏定义用于向当前光标处输出字符 push bx push cx push dx mov dh,row mov dl,col mov ah,2 mov bh,0 int 10h mov ah,9 mov bl,11 mov cx,1 lea di,cnt ;50 mov al,di int 10h pop dx pop cx pop bx endm readh macro row,col ;宏定义用于读出当前光标处字符 push dx push ax pus

6、h bx mov dh,row mov dl,col mov ah,2 mov bh,0 int 10h mov ah,08h int 10h mov pst,al pop bx pop ax pop dx endm wnear macro ;宏定义只用在readcg宏中当readcg的所有判断都不成立调用此宏 local wnext1 local wnext2 local wnext3 local wnext4 push dx dec dh readh dh,dl cmp pst,1 jne wnext1 write dh,dl,tal2 jmp wnext4 wnext1: inc dh

7、dec dl readh dh,dl cmp pst,1 jne wnext2 write dh,dl,tal2 jmp wnext4 wnext2: inc dh inc dl readh dh,dl cmp pst,1 jne wnext3 write dh,dl,tal2 jmp wnext4 wnext3: dec dh inc dl readh dh,dl cmp pst,1 jne wnext4 write dh,dl,tal2 wnext4: pop dx endm readcg macro row,col ;宏定义用于改变判断出来的字符 local tnup,tnup1,tnu

8、p2,tnlf,tnlf1,tnlf2,tndn,tndn1,tndn2,tnrt,tnrt1,tnrt2,goout push bx push ax push dx write dh,dl,tal1 dec row readh dh,dl cmp pst,4 jne tnup1 jmp tnup2 tnup1: jmp near ptr tnup tnup2: write dh,dl,blk inc dh inc dh readh dh,dl cmp pst,1 jne tnup write dh,dl,tal2 jmp near ptr goout tnup: pop dx push dx

9、 dec col readh dh,dl cmp pst,4 jne tnlf1 jmp tnlf2 tnlf1: jmp near ptr tnlf tnlf2: write dh,dl,blk inc dl inc dl readh dh,dl cmp pst,1 jne tnlf write dh,dl,tal2 jmp near ptr goout tnlf: pop dx push dx inc row readh dh,dl cmp pst,4 jne tndn1 jmp tndn2 tndn1: jmp near ptr tndn tndn2: write dh,dl,blk d

10、ec dh dec dh readh dh,dl cmp pst,1 jne tndn write dh,dl,tal2 jmp near ptr goout tndn: pop dx push dx inc col readh dh,dl cmp pst,4 jne tnrt1 jmp tnrt2 tnrt1: jmp near ptr tnrt tnrt2: write dh,dl,blk dec dl dec dl readh dh,dl cmp pst,1 jne tnrt write dh,dl,tal2 jmp near ptr goout tnrt: pop dx push dx

11、 wnear goout: pop dx pop ax pop bx endm addone: ;此标号功能是将蛇身增加一 push dx inc score2 mov dh,1 mov dl,0 mov cx,23 cmpad1: push cx mov cx,79 cmpad2: readh dh,dl cmp pst,2 jne nextad3 jmp nextad4 nextad3: jmp near ptr nextad nextad4: write dh,dl,snk dec dh readh dh,dl cmp pst,4 jne natup write dh,dl,tal2 d

12、ec dh write dh,dl,tal1 jmp outo natup: inc dh dec dl readh dh,dl cmp pst,4 jne natlf write dh,dl,tal2 dec dl write dh,dl,tal1 jmp outo natlf: inc dh inc dl readh dh,dl cmp pst,4 jne natdn write dh,dl,tal2 inc dh write dh,dl,tal1 jmp outo natdn: dec dh inc dl readh dh,dl cmp pst,4 jne natrt write dh,

13、dl,tal2 inc dl write dh,dl,tal1 natrt: outo: pop cx jmp near ptr endad nextad: inc dl jmp nextad2 chgad2: jmp near ptr cmpad2 nextad2: loop chgad2 sub dl,79 inc dh pop cx jmp nextad1 chgad1: jmp near ptr cmpad1 nextad1: loop chgad1 endad: pop dx jmp near ptr crtf aa: ;从这开始产生最原始的蛇 mov addrs,offset tu

14、rnright mov dh,10 mov dl,1 mov cx,3 write dh,dl,tal1 inc dl write dh,dl,tal2 wrt: inc dl write dh,dl,snk loop wrt mov len,6 mov ax,0 jmp wrt1 ovflw: ;当蛇碰壁或自身转到此游戏结束 mov ah,6 mov al,0 mov ch,0 mov cl,0 mov dh,24 mov dl,79 mov bh,7 int 10h mov dh,17 mov dl,17 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,

15、gmov int 21h mov ax,0 ;恢复int9中断 mov es,ax push ds:0 pop es:9*4 push ds:2 pop es:9*4+2 stop: mov ah,0 int 16h cmp al,r je aa1 jmp aa2 aa1: jmp near ptr start aa2: cmp al,q jne stop jmp near ptr exit wrt1: ;此处蛇行走过程的无限循环 call dly push dx inc dh cmp dh,25 je ovflw inc dl cmp dl,80 je ovflw pop dx push d

16、x dec dh cmp dh,0 je ovflw dec dl cmp dl,-1 je ovflw pop dx push dx lea ax,turnright cmp addrs,ax jne tonxt2 inc dl readh dh,dl cmp pst,1 je tonxt1 cmp pst,2 je tonxt1 cmp pst,4 je tonxt1 jmp tonxt2 tonxt1: jmp ovflw tonxt2: pop dx push dx lea ax,turnup cmp addrs,ax jne tonxt4 dec dh readh dh,dl cmp

17、 pst,1 je tonxt3 cmp pst,2 je tonxt3 cmp pst,4 je tonxt3 jmp tonxt4 tonxt3: jmp ovflw tonxt4: pop dx push dx lea ax,turndown cmp addrs,ax jne tonxt6 inc dh readh dh,dl cmp pst,1 je tonxt5 cmp pst,2 je tonxt5 cmp pst,4 je tonxt5 jmp tonxt6 tonxt5: jmp ovflw tonxt6: pop dx push dx lea ax,turnback cmp

18、addrs,ax jne tonxt8 dec dl readh dh,dl cmp pst,1 je tonxt7 cmp pst,2 je tonxt7 cmp pst,4 je tonxt7 jmp tonxt8 tonxt7: jmp ovflw tonxt8: pop dx jmp nexta crtf1: jmp near ptr addone crtf: call rand1 call rand2 inc frow mov ah,frow mov al,fcol push dx mov dh,1 mov dl,0 push cx mov cx,23 check1: push cx

19、 mov cx,79 check2: readh dh,dl cmp pst,1 je nextn cmp pst,2 je nextn cmp pst,4 je nextn jmp nextnn nextn: cmp ax,dx je crtf nextnn: inc dl loop check2 inc dh sub dl,79 pop cx loop check1 pop cx pop dx write frow,fcol,food nexta: mov ah,frow mov al,fcol cmp ax,dx je crtf12 jmp crtf13 crtf12: jmp near

20、 ptr crtf1 crtf13: push dx cmp score2,58 jl normal mov score2,49 inc score0 normal: mov dh,0 mov dl,8 write dh,dl,score2 add dl,score0 write dh,dl,zero pop dx cmp adrs,17 je jmp1 cmp adrs,145 je jmp1 cmp adrs,31 je jmp2 cmp adrs,159 je jmp2 cmp adrs,32 je jmp3 cmp adrs,160 je jmp3 cmp adrs,30 je jmp

21、4 cmp adrs,158 je jmp4 jmp addrs jmp1: lea ax, turndown cmp ax,addrs je jmp2 mov addrs,offset turnup jmp near ptr turnup jmp2: lea ax,turnup cmp ax,addrs je jmp1 mov addrs,offset turndown jmp near ptr turndown jmp3: lea ax,turnback cmp ax,addrs je jmp4 mov addrs,offset turnright jmp near ptr turnrig

22、ht jmp4: lea ax,turnright cmp ax,addrs je jmp3 mov addrs,offset turnback jmp near ptr turnback turnright: ;此处实现蛇向左走 push dx mov dh,1 mov dl,0 mov cx,23 cmpr1: push cx mov cx,79 cmpr2: readh dh,dl cmp pst,2 je nextr4 jmp near ptr nextr nextr4: readcg dh,dl pop cx jmp near ptr endr nextr: inc dl jmp n

23、extr2 chgr2: jmp near ptr cmpr2 nextr2: loop chgr2 sub dl,79 inc dh pop cx jmp nextr1 chgr1: jmp near ptr cmpr1 nextr1: loop chgr1 endr: pop dx inc dl write dh,dl,snk jmp near ptr wrt1 turnup: ;此处实现蛇向上走 push dx mov dh,1 mov dl,0 mov cx,23 cmpu1: push cx mov cx,79 cmpu2: readh dh,dl cmp pst,2 jne nex

24、tu3 jmp nextu4 nextu3: jmp near ptr nextu nextu4: readcg dh,dl pop cx jmp near ptr endu nextu: inc dl jmp nextu2 chgu2: jmp near ptr cmpu2 nextu2: loop chgu2 sub dl,79 inc dh pop cx jmp nextu1 chgu1: jmp near ptr cmpu1 nextu1: loop chgu1 endu: pop dx dec dh write dh,dl,snk jmp near ptr wrt1 turndown

25、: ;此处实现蛇向下走 push dx mov dh,1 mov dl,0 mov cx,23 cmpd1: push cx mov cx,79 cmpd2: readh dh,dl cmp pst,2 jne nextd3 jmp nextd4 nextd3: jmp near ptr nextd nextd4: readcg dh,dl pop cx jmp near ptr endd nextd: inc dl jmp nextd2 chgd2: jmp near ptr cmpd2 nextd2: loop chgd2 sub dl,79 inc dh pop cx jmp nextd

26、1 chgd1: jmp near ptr cmpd1 nextd1: loop chgd1 endd: pop dx inc dh write dh,dl,snk jmp near ptr wrt1 turnback: ;此处实现蛇向右走 push dx mov dh,1 mov dl,0 mov cx,23 cmpb1: push cx mov cx,79 cmpb2: readh dh,dl cmp pst,2 jne nextb3 jmp nextb4 nextb3: jmp near ptr nextb nextb4: readcg dh,dl pop cx jmp near ptr

27、 endb nextb: inc dl jmp nextb2 chgb2: jmp near ptr cmpb2 nextb2: loop chgb2 sub dl,79 inc dh pop cx jmp nextb1 chgb1: jmp near ptr cmpb1 nextb1: loop chgb1 endb: pop dx dec dl write dh,dl,snk jmp near ptr wrt1 exit: mov ax,0 ;恢复int9中断 mov es,ax push ds:0 pop es:9*4 push ds:2 pop es:9*4+2 mov ah,4ch

28、int 21h int9: ;更改后的中断服务程序 push ax in al,60h mov adrs,al mov al,20h out 20h,al pop ax iret DLY PROC near ;延时子程序 PUSH CX PUSH DX MOV DX,10000 DL1: MOV CX,9801 DL2: LOOP DL2 DEC DX JNZ DL1 POP DX POP CX RET DLY ENDP RAND1 PROC PUSH CX PUSH DX PUSH AX STI MOV AH,0 ;读时钟计数器值 INT 1AH MOV AX,DX ;清高6位 AND AH,3 MOV DL,23 ;除23,产生023余数 DIV DL MOV frow,AH ;余数存frow,作随机行数 POP AX POP DX POP CX RET RAND1 ENDP RAND2 PROC PUSH CX PUSH DX PUSH AX STI MOV AH,0 ;读时钟计数器值 INT 1AH MOV AX,DX ;清高6位 AND AH,3 MOV DL,79 ;除79,产生079余数 DIV DL MOV fcol,AH ;余数存fcol,作随机列数 POP AX POP DX POP CX RET RAND2 ENDP CODE ENDS END start

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1