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

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

  • Subject: Re: [OCLUG-Tech] Double checking re: twos complement & signed types ??
  • From: Stephen Gregory <oclug [ at ] kernelpanic [ dot ] ca>
  • Date: Fri, 21 Sep 2007 10:05:58 -0400
On Fri, Sep 21, 2007 at 12:57:56AM -0400, William Case wrote:


> Even if a
> variable value is the result of some earlier calculation, the
> instruction code (op code) for the program has to contain instruction on
> altering that data so that it can be used?

The program will determine if a number is negative or positive while
it runs. The cpu does not alter a value to or from twos complement.

unsinged 8bit int a = 15 will be stored as 1111 binary (0xf hex).
singed 8bit int b = -1 will be stored as 1111 binary.

Only the running program knows if 0xf is 15 or -1. The CPU does not know
and does not care. The CPU does not need to know. When two values are added or
substracted the CPU will set the status bits. The program (op codes)
will test the appropriate status bits based on whether the program
wishes to treat a particular value as signed or unsigned.


-- 
sg