Trivia: make this PASM snippet more efficient/elegant
ags
Posts: 386
In PASM I'd like to stop all cogs other than the one the code is executing in ("me"). I have this:
Surely there's a more elegant way to handle the 7-to-0 index loop without separately testing after exit. I must have some mental block because I don't see it. I see I can index 8-to-1, and subtract 1 in the loop. Or I can not use djnz but roll my own loop (with index 7-to-0) and stop the cog at the current index, then decrement separately (wz) and then "if_nz jmp". But these actually take more instructions to complete.
Offered as an exercise to the motivated reader.
mov idx, #7 cogid cog :loop cmp cog, idx wz if_nz cogstop idx djnz idx, #:loop cmp cog, #0 wz if_nz cogstop idx
Surely there's a more elegant way to handle the 7-to-0 index loop without separately testing after exit. I must have some mental block because I don't see it. I see I can index 8-to-1, and subtract 1 in the loop. Or I can not use djnz but roll my own loop (with index 7-to-0) and stop the cog at the current index, then decrement separately (wz) and then "if_nz jmp". But these actually take more instructions to complete.
Offered as an exercise to the motivated reader.
Comments
The cogstop will only use the 3 least significant bits.
Example:
Code is running in cog 3
After adding 1 your cogstop will first stop cog 4
The loop then stops cog 5-7
After the next add the variable contains 8 which will lead to a cogstop 0 effectively
So the rest of the loop will then stop cogs 0-2
I really need to do a better job of reading all those footnotes.
Thanks for a nice solution.