Terry Woods
Member
- Join Date
- Apr 2002
- Posts
- 3,170
Oh yeah... my old friend Move with Mask...
AB's Move with Mask is nothing more than a bit-wise "pass-gate".
It simply allows certain, specified bits in one value to overwrite the corresponding bits in another value.
The Mask determines which bits in the source (Value_A) are allowed to "paint" the corresponding bits in the destination (Value_B).
Regardless of what the original value of Value_B is, Value_B has a value of some kind... even if that value is 0000.
These examples show that Value_B already has a value of 1 1 1 1. However, bear in mind that 0 0 0 0 is also a valid value!
So... in Case-1, the Mask indicates that NONE of the source bits are allowed to "paint" the corresponding destination bits. A "0" in the Mask means "Paint is Not-Permitted" while a "1" in the Mask means "Paint is Permitted". After the operation the value of Value_B remains the same.
In Case-2, the Mask indicates that ALL of the source bits are allowed to "paint" the corresponding destination bits. After the operation the value of Value_B is the same as Value_A.
In Case-3, the Mask indicates that bits 1 and 3 are allowed to "Paint" the corresponding bits in the destination. After the operation the value of Value_B becomes 0 1 0 1.
In Case-4, the Mask indicates that bits 2 and 4 are allowed to "Paint" the corresponding bits in the destination. After the operation the value of Value_B remains the same, 1 1 1 1.
I find it very sad indeed when I see an AB programmer working on a non-AB PLC and he is beside himself because, when needed, he finds there is no Move with Mask instruction available in the particular PLC. So sad.
Especially since, if they were to look in the AB Manual to see how AB executes the function in Statement List they would see that AB Statement List does it like so...
Value_B := (Value_B AND NOT_MASK) OR (Value_A AND MASK)
Having a particular tool to do a particular job is nice... but how do you do the job if you don't have the particular tool?
Going back to Tim's post about the hammer... If you need a hammer and you have a hammer, fine. However, if you need a hammer and you don't have a hammer... what now?
Anybody that says they have NEVER used anything but a hammer when a hammer was called for is a bald-faced liar.
It is far more beneficial for programmers to understand the nature of DIGITAL LOGIC than it is to only understand the AB-way of using logic. After all, even AB has to work with the fundamental rules of logic and logic manipulation to produce particular results. If they build a function to handle a particular set of operations, fine. But a programmer NEEDS to understand how that result is really developed!
It reminds me of some kids these days that can't multiply or divide because they don't have their calculator or the batteries are dead or whatever.
I used to say, "If you can program any PLC you can program all PLCs."
These days, regarding some programmers, I realize that is not necessarily true... DAMN! That's sad... Who is going to develop the future calculators?
AB's Move with Mask is nothing more than a bit-wise "pass-gate".
It simply allows certain, specified bits in one value to overwrite the corresponding bits in another value.
Case-1 Case-2 Case-3 Case-4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
Value_A 0 1 0 1 | 0 1 0 1 | 0 1 0 1 | 0 1 0 1
Mask 0 0 0 0 | 1 1 1 1 | 1 0 1 0 | 0 1 0 1
Original Value_B 1 1 1 1 | 1 1 1 1 | 1 1 1 1 | 1 1 1 1
Resulting Value_B 1 1 1 1 | 0 1 0 1 | 0 1 0 1 | 1 1 1 1
The Mask determines which bits in the source (Value_A) are allowed to "paint" the corresponding bits in the destination (Value_B).
Regardless of what the original value of Value_B is, Value_B has a value of some kind... even if that value is 0000.
These examples show that Value_B already has a value of 1 1 1 1. However, bear in mind that 0 0 0 0 is also a valid value!
So... in Case-1, the Mask indicates that NONE of the source bits are allowed to "paint" the corresponding destination bits. A "0" in the Mask means "Paint is Not-Permitted" while a "1" in the Mask means "Paint is Permitted". After the operation the value of Value_B remains the same.
In Case-2, the Mask indicates that ALL of the source bits are allowed to "paint" the corresponding destination bits. After the operation the value of Value_B is the same as Value_A.
In Case-3, the Mask indicates that bits 1 and 3 are allowed to "Paint" the corresponding bits in the destination. After the operation the value of Value_B becomes 0 1 0 1.
In Case-4, the Mask indicates that bits 2 and 4 are allowed to "Paint" the corresponding bits in the destination. After the operation the value of Value_B remains the same, 1 1 1 1.
I find it very sad indeed when I see an AB programmer working on a non-AB PLC and he is beside himself because, when needed, he finds there is no Move with Mask instruction available in the particular PLC. So sad.
Especially since, if they were to look in the AB Manual to see how AB executes the function in Statement List they would see that AB Statement List does it like so...
Value_B := (Value_B AND NOT_MASK) OR (Value_A AND MASK)
Having a particular tool to do a particular job is nice... but how do you do the job if you don't have the particular tool?
Going back to Tim's post about the hammer... If you need a hammer and you have a hammer, fine. However, if you need a hammer and you don't have a hammer... what now?
Anybody that says they have NEVER used anything but a hammer when a hammer was called for is a bald-faced liar.
It is far more beneficial for programmers to understand the nature of DIGITAL LOGIC than it is to only understand the AB-way of using logic. After all, even AB has to work with the fundamental rules of logic and logic manipulation to produce particular results. If they build a function to handle a particular set of operations, fine. But a programmer NEEDS to understand how that result is really developed!
It reminds me of some kids these days that can't multiply or divide because they don't have their calculator or the batteries are dead or whatever.
I used to say, "If you can program any PLC you can program all PLCs."
These days, regarding some programmers, I realize that is not necessarily true... DAMN! That's sad... Who is going to develop the future calculators?