89C51 Have the folowing "comparasion"instructions or in other words a "if" something hapens do something
JZ / JNZ / JC / JNC / JB / JNB / JBC / CJNE
I "beat"that CJNE is the one that will help you
The CJNE instruction compares the first two operands and branches to the specified destination if their values are not equal. If the values are the same, execution continues with the next instruction.
Take a look on this link
https://www.keil.com/support/man/docs/is51/is51_cjne.htm