Duo jia
Duo jia

Reputation: 13

Carry flag in MSP430 is confused

  "mov #10,r5\n"
  "sub #1,r5\n" //test value

I run in hardware, when 'sub' exec, the Carry flag is set. why?

enter image description here

Upvotes: 1

Views: 174

Answers (1)

Lindydancer
Lindydancer

Reputation: 26094

When it comes to subtraction, the carry flag is reversed compared to addition. If the value wraps around, carry is set to 0. If it doesn't (as in your example) it is set to 1.

Unfortunately, this is not 100% clear when reading the processor manual. However, this behavior is consistent with other processors, e.g. 6502.

Upvotes: 3

Related Questions