+ Post New Thread
Results 1 to 4 of 4

15th August 2019, 06:51 #1
 Join Date
 Jul 2014
 Posts
 5
 Helped
 0 / 0
 Points
 976
 Level
 7
Error in subtraction with 2's comp method
Consider 3_bit wide number system. Then range is between 4 to +3. We
are going to perform subtraction +3(4). We know that result is +7
that does not fit range. So something is wrong. We expect that
hardware will alarm there is mistake because of overflow. Hardware
uses XOR operation between carry to/from MSB. If XOR=1 there is
overflow. In my example hardware cannot detect overflow. Where is the
mistake?? +3 and 4 are true operands since they are in the range.
Hardware only gets 2's complement of subtrahend when operation is
subtraction and add it to the minuend. Finally XOR determines if there
is overflow or not! In Moris Manos's Computer Architecture book there
is a ripple adder that performs proper operation based on control
mode. When we need to do subtraction, Subtrahend passes through XOR
gates and a '1' bit enters LSB of ripple adder to realize 2's
complement. I think problem arises when hardware negates 4. because
its 2's complement yields again 4, not +4. In fact +4 is not in the
range. But hardware how can find that subtrahend is 4.

Advertisement

15th August 2019, 07:26 #2
Awards:
 Join Date
 Apr 2014
 Posts
 15,606
 Helped
 3556 / 3556
 Points
 77,026
 Level
 67
Re: Error in subtraction with 2's comp method
Hi,
So something is wrong.
We expect that hardware will alarm there is mistake because of overflow.
Hardware only gets 2's complement of subtrahend when operation is
subtraction and add it to the minuend.
What is the result of "2's complement of subtrahend"?
What is the result of the "add"?
I think problem arises when hardware negates 4. because
its 2's complement yields again 4, not +4. In fact +4 is not in the
range. But hardware how can find that subtrahend is 4.
But who is the designer if the hardware? He should tell you how to handle it...and where the limitations of the adders are.
If you are the designer you have a couple of options:
* do true subtraction (not 2's complement and the add)
* don't allow the subtrahend to be '4'
* use 4 bits arithmetics (3 bits plus sign)
* correct your hardware to care for "2's complement overflow"
* or find another solution..
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.

Advertisement

15th August 2019, 16:15 #3
 Join Date
 Aug 2019
 Posts
 2
 Helped
 0 / 0
 Points
 16
 Level
 1
Re: Error in subtraction with 2's comp method
The rules are there for the designer:
to add/subtract n bits with n bits: result needs n+1 bits
to multiply n bits x m bits: results needs n+m bits

Advertisement

15th August 2019, 17:14 #4
 Join Date
 Sep 2013
 Location
 USA
 Posts
 7,231
 Helped
 1710 / 1710
 Points
 31,313
 Level
 43
Re: Error in subtraction with 2's comp method
To perform subtraction in 2's complement the subtrahend of 4 is in binary:
100
011  invert
100  +1 (hmm result is 4)
011  minuend
111  add 2s comp subtrahend and minuend (no carry)
The subtrahend of the subtraction is adding a +4 which can't even be represented in the range of values allowed in the 3bit vector. Of course computing overflow will result in incorrect results.
If we restrict the subtrahend to 3
101  3
010  invert
011  +1
011  minuend
110  add minuend to 2s comp subtrahend (we have a carry, so overflow occurred)
If instead we use 4bits
3  4
1100
0011  invert
0100  +1 (2s comp of 4)
0011  add minuend and subtrahend
0111  +7 (no carry, correct result)
+ Post New Thread
Please login