汇编语言实现移动的小蛇

发表于:2014年11月30日 01:10  分类:assembly 981次浏览

移动小蛇
1、实现由几个连续笑脸组成的小蛇,并通过按键“↑”、“↓”、“←”、“→”对小蛇的移动方向进行控制。
2、按键“a”(add)和按键“s”(sub)实现小蛇长度(笑脸个数)的增减。小蛇长度范围自行控制。
3、通过按键“u”和按键“d”实现小蛇移动速率的增减。

she

assume cs:code,ds:data
data segment
        a db 3,1
        b db 13,40,13,41,13,42
          db 160 dup (0)
        c dw 0fffh 
data ends
code segment
start:
        cli
        mov ax,data
        mov ds,ax

        mov ax,0b800h
        mov es,ax

s3:
        call clr
        
        mov cl,a[0]
        mov ch,0
        mov bp,0
s1:
        push cx
        mov al,b[bp]
        mov ah,0
        mov bl,160
        mul bl
        add al,b[bp+1]
        adc ah,0
        add al,b[bp+1]
        adc ah,0
        mov bx,ax
        mov byte ptr es:[bx],1
        pop cx
        add bp,2
        loop s1

        mov cl,a[0]
        sub cl,1
        mov ch,0
        mov bp,0
s2:
        push cx
        mov al,b[bp+2]
        mov b[bp],al
        mov al,b[bp+3]
        mov b[bp+1],al
        pop cx
        add bp,2
        loop s2

        in al,60h
        cmp al,48h
        jne s8
        mov a[1],1
s8:      
        cmp al,50h
        jne s9
        mov a[1],2        
s9:
        cmp al,4bh
        jne s10
        mov a[1],3        
s10:
        cmp al,4dh
        jne s11
        mov a[1],4
s11:
        cmp al,01h
        jne s12
        sti
        jmp s7
s12:
        cmp al,1eh
        jne s13
        add a[0],1
        mov al,b[bp+1]
        mov b[bp+3],al
        mov al,b[bp]
        mov b[bp+2],al
        cmp a[1],1
        jne s15
        sub b[bp+2],1
s15:
        cmp a[1],2
        jne s16
        add b[bp+2],1
s16:
        cmp a[1],3
        jne s17
        sub b[bp+3],1
s17:
        cmp a[1],4
        jne s18
        add b[bp+3],1
s18:
        nop

s13:
        cmp al,1fh
        jne s19
        sub a[0],1
s19:
        cmp al,20h
        jne s20
        add c[0],00ffh
s20:
        cmp al,16h
        jne s21
        sub c[0],00ffh
s21:
        nop

s14:
        cmp a[1],1
        jne s4
        sub b[bp],1
        call delay
        jmp s3        
s4:
        cmp a[1],2
        jne s5
        add b[bp],1
        call delay
        jmp s3                
s5:
        cmp a[1],3
        jne s6
        sub b[bp+1],1
        call delay
        jmp s3                
s6:
        cmp a[1],4
        jne s7
        add b[bp+1],1
        call delay
        jmp s3        
        
s7:
        mov ax,4c00h
        int 21h

clr:
        push ax
        push es
        push cx
        push bp         
        mov ax,0b800h
        mov es,ax
        mov cx,80*25
        mov bp,0
clr1:
        mov al,0
        mov es:[bp],al
        mov al,00000111b
        mov es:[bp+1],al
        add bp,2
        loop clr1
        pop bp
        pop cx
        pop es
        pop ax
        ret

delay:
        push cx
        mov cx,c[0]
delay1:
        push cx
        mov cx,c[0]
delay2:
        nop
        loop delay2
        pop cx
        loop delay1
        pop cx
        ret

code ends
end start

发表评论

电子邮件地址不会被公开。 必填项已用*标注