Skip to main content

COMPARE

Compare the two operands and set the flags.

OpcodeBytesCyclesFormExample
$9532COMPARE B:_, {BYTE}COMPARE B:1, 123
$9632COMPARE P:_, {S_BYTE}COMPARE P:2, 123
$D742COMPARE P:_, {PAIR}COMPARE P:2, 12345
$9732COMPARE I:_, {S_BYTE}COMPARE I:4, 123
$D842COMPARE I:_, {S_PAIR}COMPARE I:4, 12345
$9832COMPARE I:_, XHEX {XINT}COMPARE I:4, XHEX $D000_0000
$9932COMPARE B:_, B:_COMPARE B:1, B:2
$9A32COMPARE P:_, P:_COMPARE P:2, P:4
$9B32COMPARE I:_, I:_COMPARE I:4, I:8
Condition flagOutput
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 SUBTRACT instruction, including the effects of the WITH CARRY instruction.

  • COMPARE is typically followed by IF which acts according to the flags.