Re: two's complement done before storage or on the fly while computing
- From: Lawrence Kirby <lknews@xxxxxxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 15:07:38 +0100
On Fri, 26 Aug 2005 07:33:09 -0700, Greenhorn wrote:
> Hi,
> yes you are correct that two's complement was used to reduce to the
> costs involved in putting another circuit for performing a subtraction
> operation.
If you have an add instruction then it is about as easy to adapt to to
support subtraction using 1's complement. It is even easier with
sign-magnitude since all you have to do is flip the sign bit of the value
you are subtracting.
The reasons for using 2's complement are different. For example when the
result is represented using the same width as the operands 2's complement
addition and subtraction use the same bit manipulations as unsigned
addition and subtraction, just with different conditions for overflow.
This means that the hardware doesn't have to support different
instructions for signed and unsigned arithmetic.
> I had to switch to the hardware level as the answer by
> 'lawrence' says that today there are machines which do support
> subtraction , i wasn't sure if he meant that with those machines there
> is no need of something like two's complement notation.
Numbers have to be represented in one form or another. Compilers
for machines that support a subtraction instruction will generally use
that instead of some sequence of negation and addition, because it is
likely to be more efficient. OTOH the compiler could generate negation and
addition if it wants to, as long as the code works it doesn't matter as
far as C is concerned.
Lawrence
.
- References:
- two's complement done before storage or on the fly while computing
- From: Greenhorn
- Re: two's complement done before storage or on the fly while computing
- From: Lawrence Kirby
- Re: two's complement done before storage or on the fly while computing
- From: Greenhorn
- Re: two's complement done before storage or on the fly while computing
- From: Nick Keighley
- Re: two's complement done before storage or on the fly while computing
- From: Greenhorn
- two's complement done before storage or on the fly while computing
- Prev by Date: Re: Why C/C++ errors are SO obscure/devious??
- Next by Date: Re: object code from which compiler
- Previous by thread: Re: two's complement done before storage or on the fly while computing
- Next by thread: Re: two's complement done before storage or on the fly while computing
- Index(es):
Relevant Pages
|