-2

I was wondering if anyone can give me some site with lots of practice with these flags, especially the carry and overflow flag.

Anyways my question is this.

I'm looking at lecture notes and I see for a 5-bit comparisons

Cmp $12, $6 becomes

00110 - 01100 which can be changed into

 00110
+10100
-------
 11010

The Carry Flag CF = 1 and Overflow Flag OF = 0

Cmp $-6, $-12 is 10100 - 11010 which becomes

 10100
+00110
-------
 11010

CF =1 , Overflow Flag OF = 0

I believe I understand Overflow flag was set to 0 because these small number subtraction (or addition, depending on how you look at it) results in small numbers that never surpassed 2^5 range of numbers.

What about the carry? I thought it meant the last bit had a 1 carried over from the last column/bit, then that's a carry flag right?

What I mean is if it was something like

  1 (carried over from last column) 
  1100......(random binary for the rest ...) 
+ 0100......
-------------

That's how a carry flag would be set right? The 1 came from 1+1 at the 2nd from the left column.

In my two examples, these are no 1's on top of the leftmost column.

What's going on?

Thanks.

4

1 回答 1

0

如何在内部执行减法并不重要,但请注意,某些处理器包括实际的减法硬件。问题是减法只是意味着减去,而不是否定第二个数字并加法。对于 X86,进位标志是“借位”指示符,将数字视为无符号数,因此 6 - 12 导致“借位”。溢出标志将数字视为有符号,并且 6 - 12 = -6,因此没有溢出。

于 2014-09-17T18:10:58.547 回答