8
\$\begingroup\$

I've completed the "Sequence Counter" level of TIS-100, but this is horrendously inefficient. My cycle counts are at about twice the minimum possible according to the charts:

enter image description here

I'm not really as concerned about the other metrics.

I struggled to figure this one out. And there's definitely bits of my code which I know look suspicious, but I don't feel strong enough with the language yet to really spot how to make this execute fewer instructions.

Here's the problem description:

SEQUENCES ARE ZERO TERMINATED
READ A SEQUENCE FROM IN
WRITE THE SUM TO OUT.S
WRITE THE LENGTH TO OUT.L

enter image description here

Most of my code are in three nodes:

TOP LEFT (IN)

START: 
 MOV UP, ACC
 MOV ACC, DOWN
 MOV ACC, DOWN

JNZ SEQ
 MOV 0, RIGHT
 MOV 0, RIGHT
 JMP START

SEQ:
 MOV 1, RIGHT
 MOV 1, RIGHT

TOP RIGHT

START: 
 ADD LEFT
 SAV
 MOV 0, ACC
 MOV LEFT, ACC
 JEZ DONE
 SWP
 JMP START

DONE: 
 SWP
 MOV ACC, DOWN
 MOV 0, ACC

MIDDLE LEFT:

START: 
 ADD UP
 SAV
 MOV 0, ACC
 MOV UP, ACC
 JEZ DONE
 SWP
 JMP START

DONE: 
 SWP
 MOV ACC, DOWN
 MOV 0, ACC

MIDDLE RIGHT:

MOV UP, DOWN

BOTTOM LEFT (OUT.S)

MOV UP, DOWN

BOTTOM RIGHT (OUT.L)

MOV UP, DOWN

enter image description here

As I said, this works, but it's horribly inefficient. Cycle count is up to 485... but looks like it could be under 250.

Also, any tips on making this code more readable while still staying within the extreme character limits would be greatly appreciated.

\$\endgroup\$
3
\$\begingroup\$

Can't give you any pointers towards readibility; seems like you're doing all you can for that within the character/space limits.

As for the code: I see you reset the ACC twice. From Middle Left:

MOV 0, ACC
MOV UP, ACC

And again in the top right one. This is wasting precious cycles. You don't have to set ACC to 0 if you're writing in from a port in the next instruction. If I disable those, I get your program down to 407 cycles.

But by far the greatest improvement can be made by leveraging the TIS-100's parallel processing power! Try moving the addidion logic down to the bottom row, make the top-most block send its accumulator down only once and use the middle block to double the signal. This kills 1 cycle on the input pipe and this adds up to 30 cycles over all the input values combined. Doing ths as well with the 1/0 you send down the right path will save 30 c again. I got you down to 264 cycles this way!

Have fun trying this out.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.