TITLE "times 3 plus 1 problem" ; by Doug Jones USE "hawk.h" USE "monitor.h" ARSIZE = 4 INT MAIN S MAIN MAIN: ; executable code begins here STORES R1,R2 ADDI R2,R2,ARSIZE ; ---- application code starts here ---- LIS R8,27 ; n = 27 -- the starting value LOOP: ; repeat MOVE R3,R8 ; -- parameter 1: n LIS R4,5 ; -- parameter 2: 5 LIL R1,PUTDECU JSRS R1,R1 ; putdecu( n, 5 ) CMPI R8,1 BLEU ENDLOOP ; if (n <= 1) break BITTST R8,0 BBS ELSE ; if (n even) then { SRU R8,1 ; n = n / 2 BR ENDIF ELSE: ; } else { ADD R9,R8,R8 ADD R8,R8,R9 ADDSI R8,1 ; n = 3n + 1 ENDIF: ; } BR LOOP ENDLOOP: ; forever -- until break ; ---- application code ends here ---- ADDI R2,R2,-ARSIZE LOADS R1,R2 JUMPS R1 ; return to the monitor to stop! END