[Update: this is the same thing that Keith suggested, and he got it up here first]
I am trying to find a better (cleaner) way to code this...Any suggestions?
Hi Mike,
The image (below) is cleaner.
Caveat: clean to
me anyway, but then I'm a bitboy and breathe this stuff; not everyone would consider this anything less than obfuscation
.
Possibly also slightly better from a CPU standpoint
My last two rungs replace your first four now, and with straightforward modifications* will replace your sixteen rungs later.
More ideas below; let us know what you come up with, and don't be concerned about choosing one of "us" over the other: I for one, and I am sure many others here, appreciate you project.
* The MVM mask in rung 0001 (ffffh); twelve more NEQs in rung 0002 (blecch, but better than twelve more NEQs in each of sixteen rungs, eh?).
Alternatives
The XICs on rungs 0011 through 0014 could be ORed via branches, so all that resides on one rung, and then there is only one [NEQ N7:36 0] and one [MOV 37 N7:49], but that is not much better.
Better than multiple branches on one rung, move whatever logic you end up into a separate routine that gets called from the main routine, which reduces the use of vertical real estate in the main routine.
It could also be done with a loop (e.g. Lary's bitsum approach), in which case you would not need to MVM (or CPW) B3:45 to an INT, and the code can be modified from handling four bits to sixteen by changing only one INT (i.e. the loop counter). A loop would be a close second, but that's my own bias: I have never seen any mishaps caused by a loop.
You could do some fun stuff in the loop, like
- XIC bit 0 (INT 1) and ANDing with -2 (65534 = 65535-1);
- XIC bit 1 (INT 2) AND with -3 (65533 = 65535 - 2;
- ...;
- XIC bit 15 (UINT 32768) and 32767 (= 65535 - 32768)
- The ANDed value would be generated on the fly (e.g. XOR -1 bit];
- If the XIC is true, the AND result should be 0;
- This is almost certainly obfuscatory though.