📄 create_tree.asm
字号:
%include "asm_header.h" ; get the same maccro and define ; get_node function return the new node in eax register; node->data = [eax] data is byte; node->leftChild = [eax+4]; node->rightChild = [eax+8]extern get_node global create_tree segment .data number_of_stack_element dw 0 ; this is keep the how many element in stacksegment .text create_tree: ;This function make a tree; call get_node function from c module which is get new node and push it eax;EAX : use for keeping node;EBX : use for poping element from stack it keep this element;EDX : use for temporary for setting parameter top of tree;ESI : use for keeping string parameter;EDI : use for keep the lenght of string ;BL : use for keep byte in [eax] register;Function parameter are first top pointer of tree secand string in prefix notation third is lenght of string;First time stack is like this; |lenght of string |; |-----------------| ; |string prefix |; |-----------------| ; |top ptr of tree |; |-----------------|; |Return address |; |-----------------|; |lEBP , ESP |; |-----------------|; psueodocode :; 1 get the parameter esi is string edi is lenght of string; 2 dec edi becaouse array is begin 0; 3 while edi is 0; 4 get the char reverse order in esi; 5 if it is operand or stack have less than 2 element ; 6 go to 12; 7 else it is operator and stack have more than 2 element; 8 pop first element from stack to ebx; 9 set first element to left child; 10 pop secand element from stack to ebx; 11 set ebx to right child; 12 push ebx to stack; 13 jmp 3; 14 leave; 15 ret ;set up the ebp and esp register.Crate tree have not got any local variable so first integer is 0 enter 0,0 pusha ; save all GP registers and the flags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;INITILIZE the program get the program argument and set the string lengt show last element in string ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov esi , secand_param ; get the evaluation string from parameter mov edi , third_param ; get the evaluation string length from parameter dec edi ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;END INITILIZE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;make_node: cmp edi , 0 ; compare edi is equal zero jl finish ; if it is less than zero no new char so finish the program push dword[ esi + edi ] ; get the char which indice is edi and push it for get_node function dec edi ; decrease edi call get_node ;get the char and make tree node add esp , 4 ; add esp 4 for eraseing char understand_only_or_setchild_than_push: cmp byte data , '0' ; compare it '0' jge push_node ; if it is greater than 0 it means this is operand cmp word[number_of_stack_element] , 2 ; compare number of stack with2 jl push_node ;if it is less than it.No get node from stack only push it to stack ;element is operand and stack have more than two element so; set left and right child this operand and push it set_node_child: pop ebx ;get the first element from stak dec word[number_of_stack_element] ;after getting element stack element number decrease mov left_child , ebx ;set it to left child pop ebx ;pop the secand element dec word[number_of_stack_element] ;after getting element stack element number decrease mov right_child , ebx ;set it to right child ;push the new node to stack push_node: push dword eax ; push it to stack inc word[number_of_stack_element] ;after pushing element stack element number increase jmp make_node ;jump make_node finish: mov edx , first_param ;parameter call by referans so set it mov [edx] , eax ;eax is the top of the stack leave ; clean the stack and set the ebp and esp ret ; return to system startup routines;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END OF CREATE_TREE FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -