Mystery Code

PhilipW

Member
Join Date
Dec 2002
Location
Wellington, New Zealand. Islands on the edge of th
Posts
923
What does this do? And why?

XIC B3:0/0 BST XOR N7:0 N7:1 N7:0 NXB XOR N7:0 N7:1 N7:1 NXB XOR N7:0 N7:1 N7:0 NXB OTU B3:0/0 BND

One for the bag of tricks!!!

(SLC500 logic...copy and paste onto a blank rung. B3/0 is just an easy way to trigger the rung so as it doesn't run continuously.)
 
In my brief test, the bit patterns stored in N7:0 and N7:1 ended up swapped.

Don't know why you would do this this way, but that is what my test came out with.

OG
 
Mystery?

The only reason a mystery exists is that the truth about the subject is not known or understood. In PLC code, I have seen some really strange looking stuff, but that was from my perspective only. The person who wrote the code had a good and valid reason for writing it. I am sure some have looked at my programs and wondered, "what is he trying to do?" Life is kinda like that!
 
Agree. The words in N7:0 and N7:1 are swapped. The swap should continue without break after the trigger B3:0 has been set TRUE once. What I'm not sure of is what use this would be. Any ideas?

___________________________
There are 10 kinds of people, those who understand binary and those who don't.
 
XOR'ing words is a common programming trick used to swap the values without having to declare a temporary register. In most modern processors, this means that the operands can be loaded in one or two fetches, and be swapped without having to wait for slow memory access.

It's also a useful technique (and one you see probably every day) for highlighting text, or putting a semi-transparent overlay on a display, then non-destructively setting things back to normal.
 
However in the AB PLCs the only advantage gained is not using a temporary register. If we were programming in C or assembly we could load the values into processor registers, perform the swap, and then write, making one memory fetch and one memory write. However in ladder we make 6 memory fetches and three memory writes. If however you were to do this in a CPT instruction or ST then you could avoid doing the memory write that comes with each XOR instruction.
 

Similar Topics

Hi all, Working on a system with a CompactLogix 43 processor, Kinetix 6000 servo drives, and a sercos interface between them. The 6000 is using...
Replies
1
Views
1,025
I recently installed 4 PoE security cameras at my church. Since part of the cable run was outdoors, I searched for outdoor cat5e cable. I found...
Replies
5
Views
2,450
Factory Talk ME station V10.01 Studio is v32 Below is a pallet with password visibility. I have rendered this before in other applications but it...
Replies
3
Views
2,091
I get pack of these in every Micro expansion module... I still haven't found a use for them..?
Replies
9
Views
1,946
Hello, I've taken on yet another basket case old machine running an 7 slot SLC 5/03 PLC.... I have run into a situation where I see the same 4...
Replies
3
Views
5,634
Back
Top Bottom