📄 programinbood.asm
字号:
BinaryTreeNode: .STRUCT
NodeNumber: .DW 0;
NodeName: .DW 0;
.ENDS
.IRAM
NodeArray:
.BinaryTreeNode [11,''];
.BinaryTreeNode [1,'A'];
.BinaryTreeNode [2,'B'];
.BinaryTreeNode [3,'C'];
.BinaryTreeNode [4,'D'];
.BinaryTreeNode [5,'E'];
.BinaryTreeNode [6,'F'];
.BinaryTreeNode [];
.BinaryTreeNode [7,'G'];
.BinaryTreeNode [8,'H'];
.BinaryTreeNode [9,'I'];
.BinaryTreeNode [];
.BinaryTreeNode [10,'J'];
.BinaryTreeNode [11,'K'];
.BinaryTreeNode [];
.BinaryTreeNode [];
OutputArray:
.DW 16 DUP(0);
.CODE
.CONST C_NODESIZE=2;
.PUBLIC _main;
_main:
sp=0x7FF;
call F_SequentStore_AccessRootLast;//F_SequentStore_AccessRootMid;//F_SequentStore_AccessRootFirst;
r1= NodeArray; //r1=InputBuf
r2= OutputArray; //r2=OutputBuf
r3=[r1]; //r3=Node Number
jz ?L_ExitFunc;
[r2++]=r3; //output the node number
?L_NextNode:
r1+= C_NODESIZE;
r4=[r1]; //Get the Node
jz ?L_NextNode; //Jump the Null Node
[r2++]=r4; //Output the Nonull node
r3-=1; //node Number decrease
jz ?L_ExitFunc;
jmp ?L_NextNode; //get the next node
?L_ExitFunc:
nop;
nop;
nop;
jmp ?L_ExitFunc;
F_SequentStore_AccessRootFirst: .PROC
r2=OutputArray; //r2=OutputBuf
bp=NodeArray; //bp=InputBuf
r3=[bp]; //r3=Node Number
jz ?L_ExitFunc;
[r2++]=r3; //output the node number
r1=1; //point to tree root
call F_FirstRootArithmetic; //gothrough the tree by root first
?L_ExitFunc:
retf;
.ENDP
//======================================================
// Function Name: F_FirstRootArithmetic
// Description: recursive function to access tree.
// Input: r1:current node number
// r2:output pointor
// bp:start address of whole tree
// Output: None
// Destroy: r1,r2,r4;
// Used: r1,r2,r4,bp,sp;
// Stacks: 3*C_TreeDepth;
//======================================================
.CONST C_TreeDepth = 4;
F_FirstRootArithmetic:
_F_FirstRootArithmetic: .PROC
r4=bp;
r4+=r1 lsl 1;
r4=[r4]; //get the root node
jz ?L_ExitFunc; //Null node,exit
[r2++]=r4; //output the node
cmp r1,8; //is leaf node?
jae ?L_ExitFunc; //if leaf node,exit
push r1 to [sp]; //store the current node number
r1=r1 lsl 1; //get the left child number
call F_FirstRootArithmetic; //gothrough the left child tree
pop r1 from [sp]; //get the current node number from stack
r1=r1 lsl 1;
r1+=1; //get the right child number
call F_FirstRootArithmetic; //gothrough the rigth child tree
?L_ExitFunc:
retf;
.ENDP
//======================================================
// Function Name: F_SequentStore_AccessRootMid
// Description: gothrough the tree by RootMiddle,which be stored in sequential RAM.
// Input: InputBuf Address,OutputBuf Address;push the parameter in stack.
// Output: None
// Destroy: r1,r2,r3,r4;
// Used: r1,r2,r3,r4,bp,sp;
// Stacks: 5;
//======================================================
.PUBLIC F_SequentStore_AccessRootMid;
.PUBLIC _F_SequentStore_AccessRootMid;
F_SequentStore_AccessRootMid:
_F_SequentStore_AccessRootMid: .PROC
r2= OutputArray; //r2=OutputBuf
bp=NodeArray; //bp=InputBuf
r3=[bp]; //r3=Node Number
jz ?L_ExitFunc;
[r2++]=r3; //output the node number
r1=1; //point to tree root
call F_MidRootArithmetic; //gothrough the tree by root first
?L_ExitFunc:
retf;
.ENDP
//======================================================
// Function Name: F_MidRootArithmetic
// Description: recursive function to access tree.
// Input: r1:current node number
// r2:output pointor
// bp:start address of whole tree
// Output: None
// Destroy: r1,r2,r4;
// Used: r1,r2,r4,bp,sp;
// Stacks: 3*C_TreeDepth;
//======================================================
F_MidRootArithmetic:
_F_MidRootArithmetic: .PROC
r4=bp;
r4+=r1 lsl 1;
r4=[r4]; //get the root node
jz ?L_ExitFunc; //Null node,exit
cmp r1,8; //is leaf node?
jae ?L_AccessCurrentNode; //if leaf node,exit
push r1 to [sp]; //store the current node number
r1=r1 lsl 1; //get the left child number
call F_MidRootArithmetic; //gothrough the left child tree
pop r1 from [sp]; //get the current node number from stack
?L_AccessCurrentNode:
r4=bp;
r4+=r1 lsl 1;
r4=[r4];
[r2++]=r4; //output the node
cmp r1,8; //is leaf node?
jae ?L_ExitFunc; //if leaf node,exit
r1=r1 lsl 1;
r1+=1; //get the right child number
call F_MidRootArithmetic; //gothrough the rigth child tree
?L_ExitFunc:
retf;
.ENDP
//======================================================
// Function Name: F_SequentStore_AccessRootLast
// Description: gothrough the tree by RootMiddle,which be stored in sequential RAM.
// Input: InputBuf Address,OutputBuf Address;push the parameter in stack.
// Output: None
// Destroy: r1,r2,r3,r4;
// Used: r1,r2,r3,r4,bp,sp;
// Stacks: 5;
//======================================================
.PUBLIC F_SequentStore_AccessRootLast;
.PUBLIC _F_SequentStore_AccessRootLast;
F_SequentStore_AccessRootLast:
_F_SequentStore_AccessRootLast: .PROC
r2= OutputArray; //r2=OutputBuf
bp=NodeArray; //bp=InputBuf
r3=[bp]; //r3=Node Number
jz ?L_ExitFunc;
[r2++]=r3; //output the node number
r1=1; //point to tree root
call F_LastRootArithmetic; //gothrough the tree by root first
?L_ExitFunc:
retf;
.ENDP
//======================================================
// Function Name: F_LastRootArithmetic
// Description: recursive function to access tree.
// Input: r1:current node number
// r2:output pointor
// bp:start address of whole tree
// Output: None
// Destroy: r1,r2,r4;
// Used: r1,r2,r4,bp,sp;
// Stacks: 3*C_TreeDepth;
//======================================================
F_LastRootArithmetic:
_F_LastRootArithmetic: .PROC
r4=bp;
r4+=r1 lsl 1;
r4=[r4]; //get the root node
jz ?L_ExitFunc; //Null node,exit
cmp r1,8; //is leaf node?
jae ?L_AccessCurrentNode; //if leaf node,exit
push r1 to [sp]; //store the current node number
r1=r1 lsl 1; //get the left child number
call F_LastRootArithmetic; //gothrough the left child tree
pop r1 from [sp]; //get the current node number from stack
push r1 to [sp]; //store the current node number
r1=r1 lsl 1;
r1+=1; //get the right child number
call F_LastRootArithmetic; //gothrough the rigth child tree
pop r1 from [sp]; //get the current node number from stack
?L_AccessCurrentNode:
r4=bp;
r4+=r1 lsl 1;
r4=[r4];
[r2++]=r4; //output the node
?L_ExitFunc:
retf;
.ENDP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -