Binary Tree in Assembly Language

phingphing's Avatar, Join Date: Nov 2008
Newbie Member
I tried looking high and low for a sample of writing a code for a Binary Tree, there isnt one or i must have missed it somewhere.

This is what i would need in assembly language.

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                               
;   insert  Insert a new node in a binary search tree       
;                                                                               
;                                                                               
;   Entry   0(r14)= ->Pointer to the root of a binary tree  
;             4(r14)= Number to be added to the tree           
;             jal insert                                                        
;                                                                                
;   Result  r1 = ->Pointer to the root of the binary tree   
;                                                           
;   Uses    r1,r2                                      
;                                                           
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
i manage to come out with something in java, but i have no idea how to translate it into assembly (DLX assembly) language.


Code:
bst insert(bst tree, int n)      // add n to the tree
{
	if ( tree == 0 )         // an empty tree is replaced by a new node
	{
		tree = newNode(n) ;
	} else
	{
		if (n > tree.value)    // if n is > node, add n to the left sub-tree
		{
			tree.left = insert(tree.left,n) ;
		} else
		{                        // otherwise add n to the right sub-tree
			tree.right = insert(tree.right,n) ;
		}
	}
	return tree ;            // return a pointer to the tree
}
Can anyone give me a rough idea or let me know how can i find an assembly equivalent on the internet please? Thanks alot in advance.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
One way to convert it would be to get a Java to C translator, which will generate C for you, and you can then use a C compiler to generate assembly code. Compilers will in general produce object code, but if you dig through the manual you'll find the option that will produce an assembly language listing.

A quick Google finds http://www.soe.ucsc.edu/~elm/Software/Dlxos/dlxcc.shtml which describes the DLX Compiler & Assembler and its -l option to generate assembly. Another ("java to c") finds a number of Java to C translators which could be up to the job.