4-66 Series 90-30/20/Micro Programmable Controllers Reference Manual September 1998 GFK-0467K
4
MSKCMP (WORD, DWORD)
The Masked Compare (MSKCMP) function (available for Release 4.41 or later CPUs) is used to
compare the contents of two separate bit strings with the ability to mask selected bits. The length of
the bit strings to be compared is specified by the LEN parameter (where the value of LEN specifies
the number of 16-bit words for the MSKCMPW function and 32-bit words for the MSKCMPD
function).
When the logic controlling the enable input to the function passes power flow to the enable (EN)
input, the function begins comparing the bits in the first string with the corresponding bits in the
second string. Comparison continues until a miscompare is found, or until the end of the string is
reached.
The BIT input is used to store the bit number where the next comparison should start (where a 0
indicates the first bit in the string). The BN output is used to store the bit number where the last
comparison occurred (where a 1 indicates the first bit in the string). Using the same reference for
BIT and BN causes the compare to start at the next bit position after a miscompare; or, if all bits
compared successfully upon the next invocation of the function block, the compare starts at the
beginning.
If you want to start the next comparison at some other location in the string, you can enter different
references for BIT and BN. If the value of BIT is a location that is beyond the end of the string,
BIT is reset to 0 before starting the next comparison.

If All Bits in I1 and I2 are the Same

If all corresponding bits in strings I1 and I2 match, the function sets the “miscompare” output MC
to 0 and BN to the highest bit number in the input strings. The comparison then stops. On the next
invocation of MSKCMPW, it will be reset to 0.

If a Miscompare is Found

When the two bits currently being compared are not the same, the function checks the
correspondingly numbered bit in string M (the mask). If the mask bit is a 1, the comparison
continues until it reaches another miscompare or the end of the input strings.
If a miscompare is detected and the corresponding mask bit is a 0, the function does the following:
1. Sets the corresponding mask bit in M to 1.
2. Sets the miscompare (MC) output to 1.
3. Updates the output bit string Q to match the new content of mask string M.
4. Sets the bit number output (BN) to the number of the miscompared bit.
5. Stops the comparison.