COMPARE
Compare the two operands and set the flags.
| Opcode | Bytes | Cycles | Form | Example |
|---|---|---|---|---|
| $95 | 3 | 2 | compare b:_, {byte} | compare b:1, 123 |
| $96 | 3 | 2 | compare p:_, {s_byte} | compare p:2, 123 |
| $d7 | 4 | 2 | compare p:_, {pair} | compare p:2, 12345 |
| $97 | 3 | 2 | compare i:_, {s_byte} | compare i:4, 123 |
| $d8 | 4 | 2 | compare i:_, {s_pair} | compare i:4, 12345 |
| $98 | 3 | 2 | compare i:_, xhex {xint} | compare i:4, xhex $d000_0000 |
| $99 | 3 | 2 | compare b:_, b:_ | compare b:1, b:2 |
| $9a | 3 | 2 | compare p:_, p:_ | compare p:2, p:4 |
| $9b | 3 | 2 | compare i:_, i:_ | compare i:4, i:8 |
| Condition flag | Output |
|---|---|
| zero (ZF) | If the difference is zero, this flag is 1; otherwise it is 0. |
| negative (NF) | If the signed difference is a negative number, this flag is 1; otherwise it is 0. |
| overflow (OF) | If the difference exceeds the register's signed range, this flag is 1; otherwise it is 0. |
| carry (CF) | If the difference exceeds the register's unsigned range, this flag is 1; otherwise it is 0. |
Notes
-
The flag outputs are calculated exactly the same as for the
subtractinstruction, including the effects of thewith carryinstruction. -
compareis typically followed byifwhich acts according to the flags.