Numeric comparisons

Ken Turkowski ken at turtlevax.UUCP
Thu Oct 3 04:31:43 AEST 1985


In article <30000015 at ISM780.UUCP> marv at ISM780.UUCP writes:
>
>>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

This implies that the compare instruction should be used for unsigned
comparisons, and that the subtract as well as a conditional compare
is needed for signed numbers.

>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.

It is not an arbitrary  choice between using one or the other for this
machine.  You must use the appropriate method of comparison, depending
on the type of the instruction.
-- 
Ken Turkowski @ CADLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken at DECWRL.ARPA



More information about the Comp.lang.c mailing list