What is the difference between test and cmp in compilation? Extra points for getting it right!!

Updated on technology 2024-02-28
3 answers
  1. Anonymous users2024-02-06

    The friend on the first floor said that it was a bit troublesome, but it was actually easier to explain.

    1.Difference in meaning:

    CMP belongs to the category of addition and subtraction operations, while Test belongs to the category of logical operations.

    2.Conceptual differences.

    CMP is similar to SUB, that is, the source operand is subtracted from the destination operand, but SUB will send the result to the destination operand, while CMP will not send the destination operand;

    Test is similar to AND in that it performs a bitwise "AND" operation on two operands, but AND sends the result to the destination operand, while test does not.

    3.Differences in usage.

    CMP is mainly used to compare the relationship between two numbers, and can be compared between signed and unsigned numbers. Equal numbers affect the ZF flag, unsigned numbers affect the CF flag, and signed numbers affect the SF and OF signs. Generally, program jumps are set according to the influence of flags, that is, the corresponding program fragments are completed according to different conditions, similar to the if-else structure of high-level languages.

    All conditional transfer orders can be used after this order.

    test is usually used to check if certain bits are 1, but you don't want to change the operand. For example, to check whether there is one bit of 1 in bit 6 and bit 2 in al, you can use the following command:

    test al, 01000100b, if all two bits are 0If the value of zf is 1, otherwise it is clear, then the jump set according to the flag can only be jz or jnz

    The similarity between these two instructions is that neither of them affects the operand, but only reflects the result of the operation through some bits of the flag register.

  2. Anonymous users2024-02-05

    text x,y

    The main function is that x and y are combined, and the result is not sent back, but affects the flag bit.

    cmp x,y

    The function is x-y, does not send back the result, and also affects the flag bit....

  3. Anonymous users2024-02-04

    The most liked downstairs said that it was very good, but I personally feel that it is a bit too much for beginners The subject asks test and cmp

    What's the difference, I'll start with that.

    The function of CMP: to determine whether two numbers are equal Example: cmp ax ax is equal, zf is 1, if it is unequal, zf is 0

    The (common) function of test: to determine whether the register content is zero Example: test ah ah if ah is o then zf is 1 if ah is not 0 zf is 0

    If it's the subject's question, the above is enough. Then the next thing is for the students who want to read the above and want to read the following.

    zf (zero flag) Chinese: zero flager Function: reflect the operation result When the operation result is zero, zf is 1, and when the operation result is 1, zf is 0 (this is easy to understand, because it is a zero flagor, it means that there is zero as 1).

    CMP Instruction Principle (two operands are subtracted, but no value is returned, only the flag is modified): e.g. cmp ax bx

    If ax-bx is equal to 0, then zf is 1

    The principle of the test directive (two operands are operated with, but the value is not returned, only the flag bit is modified): e.g. test ah ah

    Then in this instruction, the result is always 0 and zf is 1

Related questions
9 answers2024-02-28

Twisted pair and signal transmission through differential current, but with the increase of data volume, if the rate exceeds 100Mbps, the attenuation of twisted pair will become larger and larger, in other words, if you want to carry out data transmission of more than 1km of 500Mbps, twisted pair is not competent, and you must use optical fiber for communication; >>>More

11 answers2024-02-28

The essentials of jumping must remember to land with both feet at the same time, so that after landing, you can use any foot as the pivot foot, so that the cohesion action after jumping has more room for choice and more diversification. The jump step is actually a stop action, jumping in the dribble, and completing the process from dribbling to holding the ball in the jump step. There are two kinds of jump stops, the difference between landing with both feet successively and landing at the same time. >>>More

8 answers2024-02-28

The Jingkou and Zhongshan Mountains in the Guazhou are separated by several mountains. >>>More

4 answers2024-02-28

Past tense sumPast participleThe difference: >>>More

18 answers2024-02-28

In fact, everyone fantasizes about what their love story is like. When we are young and ignorant, after knowing what love is, we may fantasize about what our love looks like. And our ideal love is just like the one deduced in the TV series, there must be a thrilling beginning and a vigorous love story. >>>More