Test Under Mask is used to examine the bits of a single byte in memory and set the condition code based on the contents of the selected bytes.  Operand 1 is the address of the byte in memory that is to be examined.  Operand 2 is an immediate constant which is treated as an 8-bit binary mask (pattern).  The bits in the mask correspond one for one with the bits in the Operand 1 byte.  A mask bit of 1 indicates that we are interested in testing the corresponding bit in memory and we will call this bit a “selected” bit.  A mask bit of 0 indicates that we are not interested in testing the corresponding bit in memory.  The condition code is set based on the contents of the selected bits. 

 

   This instruction sets the condition code as follows:

 

   Condition Code               Meaning                                    Test With

 

            0              All selected bits are set to 0,                      BZ or BNZ.  (Zeros, Not Zeros)

                           or all mask bits were 0

            1             Selected bits mixed (0’s and 1’s)                BM or BNM ( Mixed, Not Mixed)

)

            3             Selected bits were all 1’s                            BO    BNO  (Ones, Not Ones)            

 

   Consider the following example.

 

                         TM   AFIELD,B’11110000’

                         BO   ALLONES

                         BM   MIXED

                         ...

                 AFIELD  DC   C’A’        AFIELD = B’11000001’

 

The immediate constant in the TM instruction is coded as B’11110000’, indicating that we are interested in testing the first four bits in AFIELD, and that we are not interested in the last four bits.  Since AFIELD contains a character “A” which is equivalent to a binary 11000001, the condition code is set to 1 indicating that some of the bits we selected are 1’s and some are 0’s.  As a result, a branch will occur to MIXED when we execute the BO instruction.

 

   Since the TM instruction works at the bit level, it makes sense to code the immediate constant in a binary format, although any format may be used.  For example, the following instruction is equivalent to the TM in the example above.

 

                      TM   AFIELD,X’F0’

 

 

 

 

 

 

        Some Unrelated TM’s

 

              BYTE1  DC   X’00’

              BYTE2  DC   X’FF’

              BYTE3  DC   X’C3’

 

       TM    BYTE1,B’11000000’   Condition Code = 0 (all zeros)

       TM    BYTE2,B’11000000’   Condition Code = 1 (mixed)

       TM    BYTE3,B’11000000’   Condition Code = 3 (all ones)

 

1)  Make your code easier to read by representing the immediate constant in a binary form.