On 15 Nov, 10:29,
torb...@diku.dk (Torben Ægidius Mogensen) wrote:
>
torb...@diku.dk (Torben Ægidius Mogensen) writes:
>
> > Luca Forlizzi <
luca.forli...@gmail.com> writes:
>
> >> How unsigned addition is implemented in one's complement CPUs?
>
> > I can't find unsigned addition in the Univac 1100 instruction set (which
> > uses one's complement as default and supports sign+magnitude as well).
>
> > So I suspect the answer is "It isn't".
>
> However, if you don't overflow, ones-complement addition works fine for
> unsigned addition. The difference between ones-complement addition and
> unsigned addition is that, if the addition has a carry out, this is
> added back in to the lsb. So if this never happens, you are O.K.
>
> Torben
you are right, thanks for pointing it out. This indeed solve the
problem in some cases. However not in the case I have in mind, i.e.,
how to implement C language unsigned arithmetic in one's complement
CPUs.
As you probably know, in C unsigned arithmetic is modular. This is
easily implemented in two's complement by ignoring the carry out of
addition.
So, either a one's complement CPU also has an add instruction that
does not add back the carry out, or the unsigned add operation has to
be implemented by a sequence of operation. In the latter case, I would
expect signed arithmetic in C to be faster than the unsigned one.