📄 inorder.asm
字号:
%include "asm_header.h" ; get the same maccro and define global inordersegment .data indice dd 0 ;is use control first time running or elsesegment .txtinorder:;This function is use for walk on tree by using inorder recursively and put character to given string;Get to parameters one is pointer of top of tree other is string which's context is write in program;For understand proram execute first time use indice variable if this is first time indice 0 .Than we increase it;but for secand call we do not change it so we decrease it too and in the program left bracet and right braket number;is equal so we increase and decrease it when adding left and right braket;return nothing but string is pass by reference so it is change;EAX : use for keeping node;ESI : use for keeping string parameter;EDI : use for indice of string after puting one character string increase it;BL : use for keep byte in [eax] register;Stack frame for one calling recursive function; |string infix |; |-----------------| ; |top ptr of tree |; |-----------------|; |Return address |; |-----------------|; |EBP |; |-----------------|; |string infix |; |-----------------| ; |top ptr of tree | ESP;pseudocode; 1 reverse 8 byte for local variable which is string infix and child of node; 2 get the parameter eax node , esi string; 3 if it is the start of program; 3.1 edi = 0; 4 if node in eax is null jump the finish; 5 else if it is operator put a left bracet to string; 6 push the left child of node in eax and string; 7 call inorder for left child; 8 get the node in eax; 9 copy the node 's byte to bl ; 10 put it to string and increase the string indice edi; 11 put the right child and string ; 12 call inorder for right child; 13 if node in eax is null jump the finish; 14 else if it is operator put a right bracet to string; 15 put the end of string to end of string; 16 leave and ret enter 8,0 ;save 8 byte for local varible ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;INITILIZE the program get the program argument which is top of tree and string ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov eax , first_param ; get the top pointer of tree mov esi , secand_param ; get the secand param which is evaluation string cmp dword[indice] ,0 ;compare indice is 0 jne start ;if it is not 0 it mean this is not the first time running of program xor edi , edi ;at first time edi is 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;END INITILIZE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start: compare_null_jmp_je_finish eax ; if eax (node) is null jmp the finish cmp byte[eax] , '0' ; compare it 0 for learning is it operand or operator jge not_add_left_braket ; if it is operand jmp the not_add_left_blank inc dword[indice] ; after first time running increase the indice mov byte[ esi + edi ] , '(' ;it is operand and for every operand we add one left bracet inc edi ;edi is string indice so increase it after adding new charnot_add_left_braket: push_string_and_child dword left_child ;push the string and left child to stack for recursive call call inorder ;call inorder for left child mov eax , first_param ;get the node from stack mov bl , byte data ;copy node data bl which is for char mov byte[esi + edi ] , bl ;copy char to string inc edi ;after copying char increase the string indice add esp , 8 ;add esp 8 for removeing 8 byte which is string and node compare_null_jmp_je_finish eax ;if eax (node) is null jump the finish push_string_and_child dword right_child ;add the right child to stack call inorder ; call inorder for right child mov eax , first_param ;get the node from stack compare_null_jmp_je_finish eax ;if eax (node) is null jump the finish cmp byte data , '0' ;compare 0 for is it operand or operator jge finish ;if it is operand jump the exit dec dword[indice] ; after first time running increase the indice mov byte[ esi + edi ] , ')' ;else addright braket for operator add edi,1 ;after pushing new element increase the string indicefinish: mov dword[esi + edi ] , 0 ;put the end of string to end of string leave ; clean the stack and set the ebp and esp ret ; return to system startup routines;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END OF INORDER FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -