drbitboy
Lifetime Supporting Member
/gotta burn this into ROMDoes the PLC have a roll left or roll right instruction? If you roll and word 8 bits in either direction it does the same as a swap.
That would require a 16-bit INT shift, and Logix uses 32-bit DINTs for bit shifts.
With BSL/BSR, the roll could possibly be done by specifying the .UL bit as the source bit. That said, BSL/BSR only shift one bit at a time, so there would have to be eight executions of the instruction for each byte pair. COP instructions could be used to move the string .DATA[...] SINTs into and out of INTs.
So in the end, @dmroeder's or my approach would be quicker. Note that my use of the string MID instruction is essentially a shift of eight bits, but needs another LENGTH/2 passes to complete the roll.
I think it could also be done in four instructions:
- CPT halflen ((string.len+1) AND -2)/2;
- COP/CPS string.DATA[0] int_array[0] halflen
- FAL ctl halflen 0 ALL int_array[ctl.POS] (((int_array[ctl.POS] AND -256)/256) AND 255) + (((int_array[ctl.POS] AND 255)*256) AND -256)
- COP/CPS int_array[0] string.DATA[0] string.len