TITLE "mp1.a by Douglas Jones -- logical operator version" ; Note: Thi is a literal translation of the original C solution ; to MP1, except it is linked to a separately assembled source file ; for MP1DATA instead of having the data come from an included ; header file USE "hawk.h" USE "stdio.h" EXT MP1DATA INT MAIN ; activation record for printit ;RETAD = 0 R8SAVE = 4 ARSIZE = 8 PRINTIT: ; expects R3: s, the null terminated string to print ; returns nothing ; uses R8: s during the code STORES R1,R2 STORE R8,R2,R8SAVE ADDSI R2,ARSIZE MOVE R8,R3 ; -- move s to permanent home LOOP: LOADS R3,R8 EXTB R3,R3,R8 ; char ch = *s BZS QUIT ; if (ch == '\0') break BITTST R3,7 ; -- note, R3 is still ch BBR ELSE ; if (ch & (1 << 7)) { -- high bit set ; -- ch is a relative substring pointer TRUNC R3,7 SUB R3,R8,R3 ; -- param JSR R1,PRINTIT ; printit( s - (ch & 0x7F) ) BR ENDIF ELSE: ; } else { -- high bit reset ; -- note, R3 is still ch which is ASCII LIL R1,PUTCHAR JSRS R1,R1 ; putchar( *s ); ENDIF: ; } ADDSI R8,1 ; s++; BR LOOP QUIT: ; } ADDSI R2,-ARSIZE LOAD R8,R2,R8SAVE LOADS PC,R2 ; activation record for main ;RETAD = 0 ARSIZE = 4 MAIN: STORES R1,R2 ADDSI R2,ARSIZE LIL R3,MP1DATA ; -- parameter JSR R1,PRINTIT ; printit( mp1data ) ADDSI R2,-ARSIZE LOADS PC,R2 END