简体   繁体   中英

CMP and carry flag

Processor: MSP430 16 bit RISC

Can someone explain the CMP instruction in terms of when the carry flag is actually set below. From the manual it says,

CMP(.B) src,dst ..... dst - src

If src is not equal to dst, will the carry flag be set?

cmp    r15, r11
jnc    #1234

The User's Guide says:

Description
The source operand is subtracted from the destination operand. This is made by adding the 1s complement of the source + 1 to the destination. The result affects only the status bits in SR.
[…]
Status Bits
C: Set if there is a carry from the MSB, reset otherwise

In other words, C is set if there is an unsigned overflow.

This can also be seen in the jump instructions: JC (jump if carry) and JHS (jump if higher or same) are the same instruction, as are JNC (jump if no carry) and JLO (jump if lower).

Example If R5 ≥ R6 (unsigned), the program continues at Label2.

 CMP R6,R5 ; Is R5 >= R6? Info to C JHS Label2 ; Yes, C = 1 ... ; No, R5 < R6. Continue 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM