📄 me5.asm
字号:
disp macro nnn
mov ax,0900h
mov dx,offset nnn
int 21h
endm
disp1 macro nn
mov ah,0eh
mov al,nn
int 10h
endm
.model small
.stack 64
.data
binary db 63 dup (' ')
hey1 db 'Please input the node value of the binary tree:',0dh,0ah,'$'
hey2 db 0dh,0ah,'$'
hey3 db 0dh,0ah,'Pree anykey to continue,ESC to finish...',0dh,0ah,'$'
hey4 db 'The first travelling of the binary-tree is :',0dh,0ah,'$'
hey5 db ' ******************************************************',0dh,0ah,'$'
hey6 db' * *',0dh,0ah,'$'
hey7 db' * welcome to !!!! *',0dh,0ah,'$'
hey8 db' * *',0dh,0ah,'$'
hey9 db '* The function of the program is *',0dh,0ah,'$'
hey10db'* *',0dh,0ah,'$'
hey11 db'* the firsttravelling of a binary tree ! ! ! *',0dh,0ah,'$'
hey12 db'* *',0dh,0ah,'$'
hey13 db' * *',0dh,0ah,'$'
hey14 db' ******************************************************',0dh,0ah,'$'
.code
main proc far ;the main procedure
mov ax,seg hey1
mov ds,ax
disp hey5
disp hey6
disp hey7
disp hey8
disp hey9
disp hey10
disp hey11
disp hey12
disp hey13
disp hey14
e:
call puttree
disp hey2
cbw
and bx,00ffh
disp hey4
call put
disp hey2
disp hey14
disp hey3
mov ax,0100h
int 21h
cmp al,1bh
jnz e
mov ax, 4c00h
int 21h
main endp
puttree proc near ;建立一棵树
mov si,offset binary ;将binary的有效地址放在si寄存器中
sub cl,cl
mov cl,0 ; cx置零用来记数
disp hey2
disp hey1
start1: inc cl
cbw
mov si,offset binary
add si,cx
mov ah,01h
int 21h
cmp al,0dh
jz exit1
cmp cx, 0ffh
jz exit1
mov [si],al
jmp start1
exit1: ret
puttree endp
put proc near ;输出树
mov bl,1 ;dh用来保存入栈的元素个数
mov dh,0
mov ch,0
a:
inc ch
and bx,00ffh
mov si,offset binary
add si,bx
mov dl,[si]
cmp dl,' ' ;结点不为空的时候输出该结点,偏移地址
jz b 进栈
disp1 dl
push bx
inc dh
inc ch
mov al,2
mul bl
mov bl,al ;将bx的值乘2寻找孩子结点
jmp a ;直接 跳转到a,判断该结点时候有左孩子,如果有的话则打印该该结点并偏移地址进栈
b:
cmp dh,0 ;找右孩子
jz c
pop bx
dec dh
dec ch
mov al,2
mul bl
mov bl,al
add bl,1
c:
cmp ch,0ffh
je quit
jmp a
quit:
ret
put endp
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -