Why was the carry flag set here?
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.
How subtract is performed internally doesn't matter, but note that some processors include actual subtract hardware. The issue is that subtract means just that, subtract, not negate the second number and add. For X86, the carry flag is a "borrow" indicator, treating the numbers as unsigned numbers, so 6 - 12 results in a "borrow". The overflow flag treats the numbers as signed, and 6 - 12 = -6, so there wasn't an overflow.
链接地址: http://www.djcxy.com/p/72554.html上一篇: ARM到C调用约定,注册保存
下一篇: 为什么在这里设置进位标志?
