Stupid question that's been annoying me
On Sun, Sep 30, 2001 at 02:00:14AM -0500, Jeffrey S. Sharp wrote:
> On Sat, 29 Sep 2001, Gordon Zaft wrote:
>
> > You do realize that in signed arithmetic anything with the leading bit
> > set is a negative number?
>
> Yes, of course. I don't understand how highlighting that fact sheds any
> light on my problem. I want to know why I'm getting different C and V
> from supposedly equivalent operations.
If I understand Gordon, he's saying that you can't confuse signed arithmetic
with unsigned arithmetic. You've really created two number systems:
bits 00 01 10 11
unsigned 0 +1 +2 +3
signed 0 +1 -2 -1
The shortcut of two's-complement subtraction only relies on the bits in the
numbers, so it works with both systems. But the rules for setting the flags
depend on the number system and the operation, so:
keeping the bits and operation the same, but changing the system,
might change the flags;
with the signed system, switching between addition and subtraction,
and of course complementing the bits, might also change the flags!
Subtraction Equivalent Addition
AA-BB=CC CZSV AA+BB=CC CZSV
01 10 11 x.xx 01 10 11 ..x.
Using my table above:
1--2= 3 1+-2=-1
And the 3 really is an overflow (since there is no 3 in the signed system)
and the -1 really isn't.
It may actually be less confusing to use more bits (you'll be able to see
more answers that are in range).
-- Derek
Received on Sun Sep 30 2001 - 06:01:41 BST
This archive was generated by hypermail 2.3.0
: Fri Oct 10 2014 - 23:34:26 BST