TITLE "MP2 alternate solution by Douglas Jones" ; a program to traverse a binary tree and print the strings in it. USE "hawk.h" USE "stdio.h" ; record structure for binary tree nodes ; LEFT ; DATA -- all 3 fields are defined by the header file included at the end ; RIGHT ; root of the binary tree ; ROOT -- an address defined by the header file included at the end ; activation record for TRAVERS ;RETAD = 0 P = 4 ; the parameter p points to this subtree ARSIZE = 8 TRAVERS:; expects R3 = p STORES R1,R2 ; -- deferred receiving sequence STORE R3,R2,P ; -- save p in AR ; returns nothing ; void travers( node * p ) { TESTR R3 ; -- note that p is still in R3 BZS TRAVQT ; if (p != NULL) { LOAD R3,R3,LEFT ; -- param (p is still in R3) ADDSI R2,ARSIZE JSR R1,TRAVERS ; travers( p->left ) ADDSI R2,-ARSIZE LOAD R3,R2,P ; -- recover p from AR LOAD R3,R3,DATA ; -- param ADDSI R2,ARSIZE LIL R1,PUTSTR JSRS R1,R1 ; putstr( p->data ) ADDSI R2,-ARSIZE LOAD R3,R2,P ; -- recover p from AR LOAD R3,R3,RIGHT ; -- param ADDSI R2,ARSIZE JSR R1,TRAVERS ; travers( p->right ) ADDSI R2,-ARSIZE TRAVQT: ; } -- end of if LOADS R1,R2 ; -- return sequence JUMPS R1 ; } -- end of travers ; activation record for MAIN ;RETAD = 0 ARSIZE = 4 S MAIN INT MAIN MAIN: ; void main() { STORES R1,R2 ADDSI R2,ARSIZE ; -- normal receiving sequence LIL R3,ROOT ; --parameter JSR R1,TRAVERS ; travers( root ) ADDSI R2,-ARSIZE ; -- normal return sequence LOADS R1,R2 JUMPS R1 ; } ; the assignment said to put the following at the very end USE "/mnt/nfs/clasnetappvm/fs3/dwjones/2630mp2.h" END