Carry Flag

Hello dev-archives.

I am reading "Assembly Language for Intel-Based Computers" by Kip R. Irvine. Section 4.2.6.2 is about the Carry Flag (CF). It says if we subtract an integer from a smaller integer, the CF will be set. This is true when I run, for example...

.data
val1 BYTE 1
val2 BYTE 2

.code
mov al, val1
sub al, val2 ; CF = 1 SF = 1

But when I do the arithmetic on paper...

Carry
0000 0001 1
1111 1110 -2

1111 1111 which is -1 in 2's complement form.

Where is the carry out? It says earlier in the book that the CF is set when the result of an unsigned arithmetic operation is too large to fit into the destination operand. But -1 fits into AL.

Thanks,
Dave
[799 byte] By [_Dave_] at [2007-11-19 2:27:30]
# 1 Re: Carry Flag
Hi, Dave.

Your doing a 1+ ( NEG 2 ) operation on 'paper' which will only set the sign flag in computer flags terms, even though you get the exact same result as SUB 1, 2

I have written a little utility which gives you a visual look at what happens to registers and flags during logical and arithmatic operations.

If you're interested, take a look at my cCalc program, attached.

-Sevag K.
kahlinor at 2007-11-10 3:55:56 >
# 2 Re: Carry Flag
Let me clarify the previous post a little bit.

Rules for Binary Subtraction:

0 - 0 = 0
1 - 0 = 1
1 - 1 = 0
0 - 1 = 1 w/borrow

0000 0001
0000 0010
-----
1111 1111
kahlinor at 2007-11-10 3:56:55 >