twos complement and the CF (carry flag)



I am a newbie ... self-studying Kip Irvine's 4th edition assembly
book. I may have mistyped an example program into my compiler - but
assuming not ...

I've got a basic handle on binary numbers and twos complement notation
- but I have a question about the CARRY FLAG.

Since the CF is really only relevant for unsigned operations ??? I
assume it looks at each transaction as though it were being carried
out on unsigned values.

So, since "sub" is implemented as adding the twos complement, why does
the CF=1 (carry flag get set to 1) when subtracting 90h from 80h and
not when adding 70h to 80h?

Aren't they the same from an unsigned perspective? Nothing gets
carried ... what is the CPU doing when subtracting 90h from 80h that
it knows to mark the CF=1?



80h + 70h = F0h, CF=0
that is
1000 0000 + 0111 0000 = 1111 0000

but

80h - 90h = F0h, CF=1
that is
90h => 1001 0000 => 0110 1111 + 0000 0001 => 0111 0000
so
80h - 90h = 80h + 70h = F0h.

Why does the CARRY FLAG = 1?


Thanks in advance,

-Luher

.



Relevant Pages

  • Re: About volatile qualifier
    ... In an article about volatile qualifier there is a small code by which the ... void Wakeup{flag = true;} ... compiler optimizes access to that variable by caching it in a register. ... Thread-1 will never get the actual value of the flag and loop forever." ...
    (microsoft.public.vc.language)
  • Re: thread synchronization of flag
    ... a flag until this flag changed from one, ... from using a certain kind of low-level synchronization ... or fetchAndAdd() operations imply at least some synchronization), ... There are, of course, severe implications on the compiler anyway. ...
    (comp.programming.threads)
  • Segmentation Fault
    ... subroutine, reporting a segmentation fault as it does so. ... If I compile the code with the Portland Group compiler with the -g flag ... crashes soon after entering a subroutine. ...
    (comp.lang.fortran)
  • Re: floating point flag msg upon execution???
    ... I have this f77 program that runs on our SUN sparc machine ... Note: IEEE floating-point exception flags raised: ... Check your compiler docs for which flag it is to rebuild. ...
    (comp.lang.fortran)
  • Re: automatic variables are not initialized correctly?
    ... Is this below really a Fortran thing or a compiler bug? ... The next call to the same subroutine finds that the variable to be .FALSE., ... IF(flag .EQV. ... and assigned a value by an assignment statement ...
    (comp.lang.fortran)