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

移动小蛇

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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