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!watmath!clyde!burl!ulysses!ucbvax!decvax!decwrl!turtlevax!ken From: ken@turtlevax.UUCP (Ken Turkowski) Newsgroups: net.lang.c Subject: Re: Re: Numeric comparisons Message-ID: <918@turtlevax.UUCP> Date: Wed, 2-Oct-85 14:31:43 EDT Article-I.D.: turtleva.918 Posted: Wed Oct 2 14:31:43 1985 Date-Received: Sat, 5-Oct-85 02:33:36 EDT References: <657@astrovax.UUCP> <30000015@ISM780.UUCP> Reply-To: ken@turtlevax.UUCP (Ken Turkowski) Organization: CADLINC, Inc. @ Menlo Park, CA Lines: 46 In article <30000015@ISM780.UUCP> marv@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@DECWRL.ARPA