Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site turtlevax.UUCP
Path: utzoo!linus!philabs!prls!amdimage!amdcad!amd!turtlevax!ken
From: ken@turtlevax.UUCP (Ken Turkowski)
Newsgroups: net.lang.c
Subject: Re: Numeric comparisons
Message-ID: <908@turtlevax.UUCP>
Date: Tue, 24-Sep-85 21:27:50 EDT
Article-I.D.: turtleva.908
Posted: Tue Sep 24 21:27:50 1985
Date-Received: Fri, 27-Sep-85 07:28:14 EDT
References: <797@dataio.UUCP> <726@terak.UUCP>
Reply-To: ken@turtlevax.UUCP (Ken Turkowski)
Organization: CADLINC, Inc. @ Menlo Park, CA
Lines: 33

In article <726@terak.UUCP> doug@terak.UUCP (Doug Pardee) writes:
> ...
>Fortunately, the more modern CPU chips are designed with a proper
>compare instruction which does bit-wise comparison instead of
>subtraction.

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.

The conditions used for the branch will determine how the operands are
to be compared:  whether as signed integers or unsigned integers.  A
subtraction sets 4 bits:  negative (N), zero (Z), carry (C), and
overflow (V).  They are combined to indicate ordering relationships as
follows:

signed <		N ^ V
signed <=		(N ^ V) | Z
signed >		!(N ^ V) & !Z
signed >=		!(N ^ V)
unsigned <		!C
unsigned <=		!C | Z
unsigned >		C & !Z
unsigned >=		C
==			Z
!=			!Z

Note that some machines generate a borrow (B) rather than a carry after
subtraction.  Just substitute a !B for C above.
-- 
Ken Turkowski @ CADLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken@DECWRL.ARPA