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.