Numeric comparisons
Chris Torek
chris at umcp-cs.UUCP
Sat Sep 21 17:36:53 AEST 1985
>> I disagree. A comparison is a subtract with the result thrown away. The
>> trick is to select the correct conditional branch instruction afterwards,
>> depending on whether a signed or unsigned comparison was done.
> Watch my lips! A signed comparison is *not* a subtract with the result
> thrown away. Write that down so you don't forget it.
> I offer another example... take an 8-bit machine, both for simplicity
> and because the 8080A/Z80/6502 all did compares via subtraction.
Watch my fingers! A signed comparison is a subtract with the result
thrown away.
I offer another example. Take a 32 bit machine---the Vax---both for
simplicity and because the Vax does compares via subtraction. But I
will use a byte instruction:
cmpb r1,$40
blss label # branch if less than
If you wish to do an unsigned comparison:
cmpb r1,$40
blssu label # branch if less than unsigned
Can we lay this to rest? How the compiler implements comparison
is machine dependent.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP: seismo!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at maryland
More information about the Comp.lang.c
mailing list