; PUTREE - Output symbol tree in alphabetical order
; Mike Gabrielson   8/10/78
; accepts: HL = contents of ROOT pointer (must not be grounded)
; =============================================================

	EXTRN	PUTNAM	;this is an external routine not
			;defined in this assembly.  PUTNAM
			;outputs the ASCII string addressed
			;by HL (which must be saved) and 
			;terminated by NULL.

PUTREE:	PUSH	D	;save pointer to the pointer when reentered
	PUSH	H	;save address of node
	MOV	D,M	;get pointer to left subtree into DE
	INX	H
	MOV	E,M
	INX	H
	XCHG		;then into HL	
	MOV	A,H	;no left subtree?	
	ORA	L	;(pointer grounded?)	
	CNZ	PUTREE	;subtree exists, traverse it now	
	XCHG		;restore address of original node to HL
	INX	H	;skip right subtree pointer	
	INX	H	;and get address of symbol narae	
	CALL	PUTNAM	;output the ASCII string	
	DCX	H	;get node's right subtree pointer into DE
	MOV	E,M
	DCX	H
	MOV	D,M
	XCHG		;then into HL	
	MOV	A,H	;no right subtree?	
	ORA	L	;(pointer grounded?)	
	CNZ	PUTREE	;subtree exists, traverse it now	
	POP	H 	;restore stack	
	POP	D
	RET

	END

