One"s complement machines and C logic

George Rosenberg george at idis.UUCP
Mon Jan 30 05:17:07 AEST 1984


If CSO already has UNIX (and presumably a C compiler) working
on their one's complement machine (Sperry 1100),
then it would seem that the one's complement
arithmetic problem has already been successfully addressed.
Of course you may on occasion be confronted with a non-portable
construct in an existing program, but that problem is not specific
to one's complement arithmetic.

One way of dealing with one's complement hardware
is for the C compiler to normalize the results of
arithmetic expressions (i.e. change "~0" to "0").
Since "~0" can no longer be the result of an arithmetic expression,
the expression "0 == ~0" would evaluate to "0" (i.e. false).
Similarly, "~0" would be true.

Below are arithmetic expressions (in the preceding sense).
	-e	e+e	e+=e
	++e	e-e	e-=e
	--e	e*e	e*=e
	e++	e/e	e/=e
	e--	e%e	e%=e


A second way of dealing with one's complement hardware
is for the C compiler to use a two's complement representation.
It would simulate two's complement behavior
with several one's complement instructions.



		George Rosenberg
		idis!george



More information about the Comp.lang.c mailing list