//MACRO Avl.find Anchor, Node, Key, CompMacro, NullLbl, WReg[], FieldDispl= 0 //-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- // // // Get load/store MIs and word length // eval(DVASM.getEnv()[4]); var ld= "L" + abiWID; var st= "S" + abiWID; var wl= abiWLen; var goRight= DVASM.getNewLabel(); var matchLbl= DVASM.getNewLabel(); var leftField= FieldDispl; var rightField= wl*2 + "+" + FieldDispl; if (WReg.length < 1) return DVASM.putError("Number of working registers for macro [AVL.FIND] is " + WReg.length + " bu it must be at lease 1") // // Set up registers and addresses // var pFld= WReg[0]; var next= WReg[0]; // // Generate code // \#Label #ld #Node, #Anchor // Load root node addr \ IF ( #Node == 0 ), GOTO, ID= #NullLbl // Check if tree is empty \ DO \ #CompMacro #Key, #Node, #goRight, #matchLbl, [#WReg] // Compare keys \ #ld #Node, #leftField[#Node] // Search left subtree \ IF ( #Node != 0 ), CONTINUE // CHeck new node if it exists \ GOTO #NullLbl // Done otherwise \#goRight #ld #Node, #rightField[#Node] // Search right subtree \ IF ( #Node != 0 ), CONTINUE // CHeck new node if it exists \ GOTO #NullLbl // Done otherwise \ ENDDO \#matchLbl BYTE 0[0]