![塔](https://img-blog.csdnimg.cn/20191101180229708.png#pic_center,?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzY3MDk0Mw==,size_16,color_FFFFFF,t_70)
运行后若输入: 运行后若输入:
1 3
则结果输出: 则结果输出:
A移1个盘到C A移1个盘到C
A移1个盘到B
运行后若输入: C移1个盘到B
2 A移1个盘到C
则结果输出: B移1个盘到A
A移1个盘到B B移1个盘到C
A移1个盘到C A移1个盘到C
B移1个盘到C
.386
.model flat, stdcall
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib ;引用C库文件
printf PROTO C:ptr sbyte,:vararg ;C语言printf函数原型声明
scanf PROTO C:ptr sbyte,:vararg ;C语言scanf函数原型声明
option casemap :none
;*【*/
.data
a dword 'A'
b dword 'B'
d dword 'C'
N dword ?
infmt byte '%d',0
outfmt byte '%c移1个盘到%c',13,0
.code
F proc n:dword,x:dword,y:dword,z:dword
.if n<=1
invoke printf,addr outfmt,x,z
.else
mov ecx,n
dec ecx
invoke F,ecx,x,z,y
invoke printf,addr outfmt,x,z
mov ecx,n
dec ecx
invoke F,ecx,y,x,z
.endif
ret
F endp
start:
invoke scanf ,addr infmt ,addr N
invoke F,N,a,b,d
invoke ExitProcess,0
end start
;*】*/
![二叉树](https://img-blog.csdnimg.cn/20191101191457343.png#pic_center,?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzY3MDk0Mw==,size_16,color_FFFFFF,t_70)
先序遍历二叉树(树根先输出->左节点->右节点)
若运行后若输入:
ABCDEFG
则运行结果输出:
ABDECFG
.386
.model flat, stdcall
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib ;引用C库文件
printf PROTO C:ptr sbyte,:vararg ;C语言printf函数原型声明
scanf PROTO C:ptr sbyte,:vararg ;C语言scanf函数原型声明
option casemap :none
;*【*/
.data
B byte 80 dup(0)
infmt byte '%s',0
outfmt byte '%c',0
.code
Pre proc i:dword,n:dword
mov eax,i
.if eax<n
mov ebx,i
invoke printf,addr outfmt,dword ptr B[ebx]
mov ebx,i
imul ebx,2
add ebx,1
invoke Pre,ebx,n
mov ebx,i
imul ebx,2
add ebx,2
invoke Pre,ebx,n
.endif
ret
Pre endp
start:
invoke scanf,addr infmt,addr B
mov al,0
lea edi,B
mov ecx,80
repne scasb
lea eax,B+1
sub edi,eax
invoke Pre,0,edi
invoke ExitProcess,0
end start
;*】*/
![二叉树](https://img-blog.csdnimg.cn/20191101200635796.png#pic_center,?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzY3MDk0Mw==,size_16,color_FFFFFF,t_70)
中序遍历二叉树
(LDR 如图字符数组B的值为“ABCDEFGH^JK^MNOP^^^T”,其中“^”表示不存在的结点)
若运行后若输入:
ABCD^^G
则运行结果输出:
DBACG
.386
.model flat, stdcall
option casemap :none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib ;引用C库文件
printf PROTO C:ptr sbyte,:vararg ;C语言printf函数原型声明
scanf PROTO C:ptr sbyte,:vararg ;C语言scanf函数原型声明
;*【*/
.data
B byte 80 dup(0)
infmt byte '%s',0
outfmt byte '%c',0
.code
LDR proc i:dword,n:dword
mov eax,i
.if eax<n
mov ebx,i
imul ebx,2
add ebx,1
invoke LDR,ebx,n
mov ebx,i ;eax之前运行会刷新
.if B[ebx]!='^'
invoke printf,addr outfmt,dword ptr B[ebx]
.endif
mov ebx,i
imul ebx,2
add ebx,2
invoke LDR,ebx,n
.endif
ret
LDR endp
start:
invoke scanf,addr infmt,addr B
mov al,0
lea edi,B
mov ecx,80
repne scasb
lea eax,B+1
sub edi,eax
invoke LDR,0,edi
invoke ExitProcess,0
end start
;*】*/