unsignedmsp430cmpcarryflag

will carry flag be set after CMP?


(MSP430 16 bit)

CLR[.W]   R14 
CMP[.W]   #0x0200, R14 
JC        #1234

How can I know if Carry flag will be set?

Can CMP[.W] #0x0200, R14 make Carry flag be set?


Solution

  • It would help to take a look at the documentation.
    Section 3.4.6.14 of the MSP430x2xx Family User's Guide says:

    Syntax
    CMP src,dst or CMP.W src,dst

    Description
    The source operand is subtracted from the destination operand. […] The two operands are not affected and the result is not stored; only the status bits are affected.

    Status Bits
    […]
    C: Set if there is a carry from the MSB of the result, reset otherwise

    So the carry flag will be set if subtracting 0x200 from zero needs a carry.

    This meaning of the carry flag is made clearer in the documentation of JC/JHS in section 3.4.6.24:

    Description
    […] JC (jump if carry/higher or same) is used for the comparison of unsigned numbers (0 to 65536).

    Example
    R5 is compared to 15. If the content is higher or the same, branch to LABEL.

    CMP #15,R5
    JHS LABEL    ; Jump is taken if R5 >= 15
    ......       ; Continue here if R5 < 15