TITLE "mp3.a by Douglas Jones" ; subroutine to do preorder traversal ; note that this code is deliberately ; written to a fairly low level of ; optimization USE "hawk.h" USE "monitor.h" INT TRAVERSE ; format of one tree node VALUE = 0 CHILD = 4 ; activation record for TRAVERSE ; retad = 0 P = 4 ; the parameter, points to a node I = 8 ; loop counter ARSIZE = 12 TRAVERSE: ; expects, R3 = p STORES R1,R2 STORE R3,R2,P ; -- save parameter LIS R3,0 STORE R3,R2,I ; i = 0 LOAD R3,R2,P LOAD R3,R3,VALUE ; -- parameter ADDI R2,R2,ARSIZE LIL R1,PUTS JSRS R1,R1 ; puts( p->value ) ADDI R2,R2,-ARSIZE LOOP: ; loop { LOAD R3,R2,P LEA R4,R3,CHILD ; -- address of p->child LOAD R5,R2,I SL R5,2 ADD R6,R5,R4 ; -- address of p->child[i] LOADSCC R3,R6 BZS LOOPX ; if (p->child[i] == NULL) break LOAD R3,R2,P LEA R4,R3,CHILD ; -- address of p->child LOAD R5,R2,I SL R5,2 ADD R6,R5,R4 ; -- address of p->child[i] LOADS R3,R6 ; -- parameter ADDI R2,R2,ARSIZE JSR R1,TRAVERSE ; traverse( p->child[i] ) ADDI R2,R2,-ARSIZE LOAD R3,R2,I ADDSI R3,1 STORE R3,R2,I ; i = i + 1 BR LOOP ; } LOOPX: LOADS R1,R2 JUMPS R1 ; return END