Search code examples
unsignedmsp430cmpcarryflag

will carry flag be set after cmp[.b] #4, #-1 ? [MSP430 16 bit]


[MSP430 16 bit]

0x437c    mov[.b] #-1, r12 

0x926c    cmp[.b] #4, r12 

0x2801    jlo 0xda36

Could anyone help me calculation (cmp[.b] #4, r12 ) with Binary?

Example : r12-#4= 1111111111111111 - 0100 @@? I dont know how to calculation cmp with Binary in unsigned and signed case.


Solution

  • Nothing changes between signed and unsigned subtraction. What changes is what kind of jump you use: JLO or JL. JL and JGE is used for signed comparison. JLO and JHS are used for unsigned comparison. So, in your case, you are using unsigned comparison and the jlo will not jump to 0xda36 as CMP will set the carry bit. Note that JLO is an alias for JNC (jump if not carry).

    To compute manually the subraction you can traslate it to the sum of the first addend plus the one complement of the second + 1. So in you case you have:

      0xFFFF - 0x0004 = 
      0xFFFF + 0xFFFB + 1 =  //carry is set
      0xFFFB