home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Double checking re: twos complement & and signed types ??

  • Subject: Re: [OCLUG-Tech] Double checking re: twos complement & and signed types ??
  • From: "Brenda J. Butler" <bjb [ at ] linuxbutler [ dot ] ca>
  • Date: Sat, 15 Sep 2007 13:03:37 -0400
On Sat, Sep 15, 2007 at 12:23:04PM -0400, William Case wrote:
> Hi;
> 
> Just double checking because the manuals I have are somewhat ambiguous
> -- trying to be all things to all people.
> 
> Given that I am using an AMD Athalon 64 x2 CPU:
> 
> (N.B. I do not need an explanation of twos complement.  I thing I got
> it.)
> 
> 1) All the texts I read say something like "If you are using a two's
> complement system" and go on to leave other explanatory statements open
> ended.  I have no choice do I ?  Twos complement is part of the
> architecture of the ALU is it not? 

Yes.

> 2) This as been answered for me before, but so much is written about
> signed numbers, I would like to re-check.  Using C programming, my
> system would not need or use signed numbers (integer and floating point)
> would it?  The concern over signed/unsigned numbers is only if there
> exists the possibility that the C program might be later used on a
> system that requires signed/unsigned numbers -- right?

A signed integer and an unsigned integer are not treated differently
by the machine.  When they get added together, or subtracted
or whatever, they have exactly the same effect upon the accumulator
and the status register (NCZV).

It is what the C compiler does with the contents of the accumulator and
the status register that makes it signed or unsigned.

> 3) Using an operator is a distinct instruction -- isn't it?  I.e 
> int num1 = 23
> int num2 = -11
> int result = num1 - num2 
> printf("%d",result)
> $ 34
> 
> int result = num1 + num2
> printf("%d",result)
> $ 12
> 
> Writing and viewing the above code is trivial.  I am trying to confirm
> that subtracting a negatively signed integer (or floating point) is
> *always* a double negative resulting in addition.

Yes.

cheerio,
bjb