CPY                  CPY Compare memory and index Y                   CPY
  Operation:  Y - M                                     N V - B D I Z C
                                                        / . . . . . / /
  +----------------+-----------------------+---------+---------+----------+
  | Addressing Mode| Assembly Language Form| OP CODE |No. Bytes|No. Cycles|
  +----------------+-----------------------+---------+---------+----------+
  |  Immediate     |   CPY #$FF            |   $C0   |    2    |    2     |
  |  ZeroPage      |   CPY $FF             |   $C4   |    2    |    3     |
  |  Absolute      |   CPY $FFFF           |   $CC   |    3    |    4     |
  +----------------+-----------------------+---------+---------+----------+
  For penalty cycles on the 65816, check the desired addressing mode.
What it does: Compares the byte in memory to the byte in the Y Register. Three flags are affected, but the bytes in memory and in the Y Register are undisturbed. A CPX is actually a subtraction of the byte in memory from the byte in the Y Register. Therefore, if you LDA #15: CPY #15-the result (of the subtraction) will be zero, and BEQ would be triggered since the CPY would have set the Z flag.
Major uses: Y is the most popular index, the most heavily used counter within loops since it can serve two purposes: It permits the very useful Indirect Y addressing mode (LDA (15),Y) and can simultaneously maintain a count of loop events.
See CMP for a detailed discussion of the various branch comparisons which CPY can implement.