TITLE "MP3 -- by Douglas Jones, unoptimized version" USE "hawk.h" USE "stdio.h" EXT MP3DATA INT MAIN S MAIN ; AR for PUTMSG, the recursive routine to traverse the message tree ;RETAD = 0 N = 4 ; pointer used to index through a tree node P = 8 ; pointer fetched from tree node ARSIZE = 12 PUTMSG: ; expects R3 = n, a pointer to a tree node ; returns nothing ; uses R3 for various purposes STORES R1,R2 STORE R3,R2,N ; -- move n to activation record PUTLOOP: ; for (;;) { LOAD R3,R2,N LOADS R3,R3 STORE R3,R2,P ; int p = *n LOAD R3,R2,P CMPI R3,0 BZS PUTQUIT ; if (p == NULL) break LOAD R3,R2,P LIS R4,1 AND R3,R4 BZR ODDADDR ; if ((p & 1) == 0) { -- p is even LOAD R3,R2,P ; -- parameter p ADDI R2,R2,ARSIZE JSR R1,PUTMSG ADDI R2,R2,-ARSIZE ; putmsg( p ) -- traverse a subtree BR ENDIF ODDADDR: ; } else { -- p is odd LOAD R3,R2,P ; -- parameter p ADDI R2,R2,ARSIZE LIL R1,PUTSTR JSRS R1,R1 ADDI R2,R2,-ARSIZE ; putstr( p ) -- output a leaf string ENDIF: ; } LOAD R3,R2,N ADDSI R3,4 STORE R3,R2,N ; n++ BR PUTLOOP PUTQUIT: ; } LOADS R1,R2 JUMPS R1 ; return ; AR for MAIN ;RETAD = 0 ARSIZE = 4 MAIN: ; expects nothing ; returns nothing ; uses R3 STORES R1,R2 ADDSI R2,4 LOAD R3,MP3D ; -- parameter *mp3d == mp3data JSR R1,PUTMSG ADDSI R2,-4 ; putmsg( mp3data ) LOADS PC,R2 ; return ALIGN 4 MP3D: W MP3DATA ; -- whole word holding address of data END