If D0 & gtD2, M0= 1, if D0=D2, M 1= 1, if D0
CMP is used to compare 16 bit data, and the range of comparison data is -32768 to +32767. The comparison data types can be Changshu k, h, data register d, counter c, time relay t, continuous address (such as K 1X0, K2Y0, K3M0, K2S0, etc. ).
Extended data:
CF= 1 means carry or borrow, and cmp is a subtraction operation, so it can be regarded as borrow. Therefore, at this time, OPRD 1 < oprd2.
CF=0 means there is no loan, but pay attention to whether ZF is 0 at this time. If it is 0, it means that the result is not 0, so OPRD1> oprd2
When signed: if SF=0 and OF=0, the value at this time is positive and there is no overflow. It can be seen intuitively that oprd1> Oprd2 If SF= 1 and OF=0 means that the value at this time is negative and there is no overflow, it is OPRD 1
If SF=0 and OF= 1, it means that the value at this time is positive and there is overflow. It can be seen that OPRD 1
The last two reasons of this judgment are the essence of overflow: both numbers are positive, and when added, the value is negative, indicating overflow; Both numbers are negative, and when added, the value is positive, indicating overflow; Therefore, positive overflow and negative overflow, negative overflow and positive overflow.
References:
Baidu encyclopedia -CMP instruction