//MACRO Avl.insert Anchor, Node, CompMacro, DuplLbl, WReg[8-32], 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 leftField= FieldDispl; var parentField= wl + "+" + FieldDispl; var rightField= wl*2 + "+" + FieldDispl; if (WReg.length < 8) return DVASM.putError("Number of working registers for macro [AVL.INSERT] is " + WReg.length + " bu it must be at lease 8") // // Set up registers and addresses // var pFld= WReg[0]; var next= WReg[0]; var aNode= WReg[1]; var balWReg= "[" + WReg.slice(1, 8) + "]"; var compareWReg= "[" + WReg.slice(2) + "]"; // // Generate code // \#Label #ld #next, #Anchor // Load root node addr \ IF ( #next == 0 ), THEN // Check if tree is empty \ #st 0, #leftField[#Node] // Set left child to zero \ AVL.__SETPA #Node, #pFld, 0,, EVEN,, NOCLEAR, #parentField // Set root node balance to zero \ #st 0, #rightField[#Node] // Set right child to zero \ #st #Node, #Anchor // Set node as root \