Carry flag

Dear Du Qiu,
This is a good question, but let me correct your initial question.
  1. CMP #0x002, #0x001 sets the carry bit.
  2. CMP #0x000, #0x001 sets the negative bit.
How is the comparison done? And why carry out a comparison? Let’s say you write a C program, and has a conditional loop as follows
if (A==B)
else
Obviously, a comparison CMP is made. To compare, the first operand may be subtracted from the second. The result of the operation could result in positive number (carry bit is set), zero (zero bit is set) or negative number (negative bit is set). If you look at slide 9 of Computer Arithmetic 1, you’ll understand better.
Best regards,
Jason
 
Dear Prof Jason,
recently I’m reviewing the 1st part of this course, and I test some code that the carrying flag confuse me very much. I attach the 2 different code picture as attachment. Why using CMP to compare #0x0FF and #0x001 SET the carry, but using CMP to compare #0x001 and #0x0FF the carry flag is 0?? What I think the result should be reversed.
Im very appreciate if you can solve my confusion.
Yours sincerely,
Du Qiu