《汇编语言编写贪吃蛇游戏》由会员分享,可在线阅读,更多相关《汇编语言编写贪吃蛇游戏(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,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: