Numeric comparisons

marv at ISM780.UUCP marv at ISM780.UUCP
Sat Sep 28 07:02:00 AEST 1985


>What a bunch of BS!  A compare is simply a subtract with the result
>thrown away.  You imply that a compare does an exclusive-OR, which will
>compare only for equality, but not for ordering.

Not true for all machines!  There is a rather famous machine made by that
Itty Bitty Machine manufacturer that produces a condition code that is a
number in the range 0..2 (excuse a Pascal idiom in this form).

Quoting from the Princples of Operation for the machine:

     Compare

	Resulting condition code
	--------- --------- ----
	 0     Operands are equal
	 1     First operand is low
	 2     First operand is high
	 3     --


     Subtract

	Resulting condition code
	--------- --------- ----
	 0     Operands are equal
	 1     First operand is low
	 2     First operand is high
	 3     Overflow

The important point is that the compiler for this machine must generate more
code to compare two numbers if is uses a Subract instead of a Compare. Because
if (a-b) overflows the information about which operand is larger is not
preserved in the resulting condition code.

I just had to fix a bug in our C complier because it generated a Subtract
followed by a Branch Low (in the implementation of unsigned divide).  And in
a rather obscure case the subtraction caused an overflow.

	Marv Rubinstein -- Interactive Systems



More information about the Comp.lang.c mailing list