-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path15-1.asm
215 lines (207 loc) · 3.89 KB
/
15-1.asm
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
;数据段的定义
;--------------------------------------------------
datarea segment
;主页菜单显示
mess db ' **************************************************************************',0ah,0dh
db ' * welcome you! *',0ah,0dh
db ' * this is hanoi game *',0ah,0dh
db ' * you can know how many times when you play this game *',0ah,0dh
db ' * the case by HE RUIRUI *',0ah,0dh
db ' * XueHao is 41012186 *',0ah,0dh
db ' **************************************************************************','$';
bin dw 0 ;将bin初始化为0
chnum db 10 dup('0'),'$';给chnum分配存储空间
one dw 'A' ;三个塔座
two dw 'B'
three dw 'C'
strshow db '-->$' ;连接符号
chline db 0dh,0ah,'$'
prompt db 'Please input the plate number(1-99):$';提示语句
chtimes1 db 0dh,0ah,'You have moved $';提示语句
chtimes2 db 'times',0dh,0ah,'$'
inputlist label byte
maxlen db 3
actlen db 0
chinput db 3 dup ('0'),'$'
multfact dw 1
datarea ends
;-----------------------------------------------------
;代码段的定义
code segment
main proc far ;主函数
assume cs:code,ds:datarea
start:
mov ax,datarea ;将数据段送到dx
mov ds,ax
lea dx, mess ;输出mess
mov ah,09h
int 21h
loopagain:
mov dl,0dh ;换行指令
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
lea dx,prompt ;输出prompt
mov ah,09h
int 21h
lea dx,inputlist ;输出inputlist
mov ah,0ah
int 21h
call asctobin ;调用asctobin
mov ax,1 ;把一送到ax
cmp ax,bin ;比较bin与ax
ja loopagain ;如果大于跳转到loopagain
mov ax,99 ;把99送到ax
cmp bin,ax ;比较ax与bin
ja loopagain ;如果大于跳转到loopagain
push bin ;压栈操作
push one
push two
push three
lea dx,chline ;将chline送入dx
mov ah,09h ;输出指令
int 21h
call hanoi ;调用Hanoi
lea dx,chtimes1 ;送chtimes并输出
mov ah,09h
int 21h
mov cx,0010 ;把10送到cx
lea si,chnum ;把chnum送到si
shownum: ;输入
cmp byte ptr [si],'0'
je notadd
add byte ptr [si],48
notadd:
inc si
loop shownum
lea dx,chnum
mov ah,09h
int 21h
lea dx,chtimes2
mov ah,09h
int 21h
mov bin,0
mov actlen,0
mov [chinput],'0'
mov [chinput+1],'0'
mov cx,0010
lea si,chnum
put0:
mov byte ptr [si],'0'
inc si
loop put0
jmp loopagain
loopend:
mov ah,4ch
int 21h
main endp
asctobin proc near ;子程序
push ax
push cx
cmp actlen,0
je loopend
cmp actlen,1
je l2
jmp l3
l2: ;若一个数执行
xor ah,ah
mov al,[chinput]
sub al,48
add bin,ax
jmp out1
l3: ;若输入俩个数执行
xor ah,ah
mov al,[chinput+1]
sub al,48
add bin,ax
mov al,[chinput]
sub al,48
mov cl,10
mul cl
add bin,ax
out1:
pop cx
pop ax
ret
asctobin endp
hanoi proc near ;汉诺塔
push ax
push dx
push bp
mov bp,sp
mov ax,1
cmp ax,word ptr [bp+14]
je equal
jmp unequal
equal:
lea si,chnum+10
loopnum0: ;输出过程的程序
xor ah,ah
dec si
mov al,[si]
add al,1
aaa
mov [si],al
cmp ah,1
je loopnum0
mov dx,word ptr[bp+12]
mov ah,2
int 21h
lea dx,strshow
mov ah,09h
int 21h
mov dx,word ptr [bp+8]
mov ah,02h
int 21h
lea dx,chline
mov ah,09h
int 21h
jmp exit
unequal: ;若不相等执行
mov ax,[bp+14]
sub ax,1
push ax
push [bp+12]
push [bp+8]
push [bp+10]
call hanoi
lea si,chnum+10
loopnum1: ;输入俩位数时执行
xor ah,ah
dec si
mov al,[si]
add al,1
aaa
mov [si],al
cmp ah,1
je loopnum1
mov dx,word ptr [bp+12]
mov ah,2
int 21h
lea dx,strshow
mov ah,09h
int 21h
mov dx,word ptr [bp+8]
mov ah,02h
int 21h
lea dx,chline
mov ah,09h
int 21h
mov ax,[bp+14]
sub ax,1
push ax
push [bp+10]
push [bp+12]
push [bp+8]
call hanoi
exit:
pop bp
pop dx
pop ax
ret 8
hanoi endp
code ends
;---------------------------------------
end start