# copy to iter counter REPEAT X TIMES ( INCREASE L ) PRINT X # while x > 0 REPEAT L TIMES ( CLEAR S REPEAT X TIMES ( CLEAR S INCREASE S ) REPEAT S TIMES ( # a: even # b: odd CLEAR A INCREASE A CLEAR B REPEAT X TIMES ( CLEAR T # copy t <= b REPEAT B TIMES ( INCREASE T ) # flip-flop a/b # if a, if b REPEAT A TIMES ( CLEAR A INCREASE B ) REPEAT T TIMES ( CLEAR B INCREASE A ) ) # if a REPEAT A TIMES ( # x = x / 2 CLEAR O # OUT CLEAR C INCREASE C CLEAR D REPEAT X TIMES ( CLEAR T # copy t <= d REPEAT D TIMES ( INCREASE T ) # flip-flop a/b, increase only half # if a, if b REPEAT C TIMES ( CLEAR C INCREASE D ) REPEAT T TIMES ( CLEAR D INCREASE C INCREASE O ) ) # copy x <= out CLEAR X REPEAT O TIMES ( INCREASE X ) ) # else (if b) REPEAT B TIMES ( # out = x / 2 CLEAR O # OUT CLEAR C INCREASE C CLEAR D REPEAT X TIMES ( CLEAR T # copy t <= d REPEAT D TIMES ( INCREASE T ) # flip-flop a/b, increase only half # if a, if b REPEAT C TIMES ( CLEAR C INCREASE D ) REPEAT T TIMES ( CLEAR D INCREASE C INCREASE O ) ) # add x <= o REPEAT O TIMES ( INCREASE X ) # x *= 2 REPEAT X TIMES ( INCREASE X ) # x += 1 INCREASE X ) PRINT X ) )