patternMinor
Assembling a Sequence
Viewed 0 times
assemblingsequencestackoverflow
Problem
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:
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:
Most of my code are in three nodes:
TOP LEFT (IN)
TOP RIGHT
MIDDLE LEFT:
MIDDLE RIGHT:
BOTTOM LEFT (OUT.S)
BOTTOM RIGHT (OUT.L)
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.
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.LMost 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, RIGHTTOP RIGHT
START:
ADD LEFT
SAV
MOV 0, ACC
MOV LEFT, ACC
JEZ DONE
SWP
JMP START
DONE:
SWP
MOV ACC, DOWN
MOV 0, ACCMIDDLE LEFT:
START:
ADD UP
SAV
MOV 0, ACC
MOV UP, ACC
JEZ DONE
SWP
JMP START
DONE:
SWP
MOV ACC, DOWN
MOV 0, ACCMIDDLE RIGHT:
MOV UP, DOWNBOTTOM LEFT (OUT.S)
MOV UP, DOWNBOTTOM RIGHT (OUT.L)
MOV UP, DOWNAs 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.
Solution
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:
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.
As for the code: I see you reset the ACC twice. From Middle Left:
MOV 0, ACC
MOV UP, ACCAnd 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.
Code Snippets
MOV 0, ACC
MOV UP, ACCContext
StackExchange Code Review Q#98856, answer score: 3
Revisions (0)
No revisions yet.