Numeric comparisons

William L. Sebok wls at astrovax.UUCP
Thu Sep 12 03:50:05 AEST 1985


>> Compiler users note -- if your compiler gives the wrong results, the
>> compiler writer might not be completely at fault.  Many early CPU
>> chips (8080A, Z80, 6502, etc.) did comparison by subtraction, and a
>> compiler would have had to generate extra code to test for Overflow
>> in order to get the correct result.
>
>Most chips that I know of handle compare by doing a subtraction, setting the
>bits, and throwing away the results. Since most chips also allow a single
>instruction to test any number of flags no extra code need be generated to
>differentiate between the two. Maybe you're thinking of FORTH which generally
>does what you just described...

Some FORTH implementations used to (or still do) implement the integer compare
operations this way.  However those FORTH's are buggy as it is possible to do
it right.  In both the FORTH-79 and FORTH-83 standards it is demanded that the
comparison work even in the presence of overflow. Unfortunately they specify
overflow of a 16 bit word, but that is another matter.
-- 
Bill Sebok			Princeton University, Astrophysics
{allegra,akgua,cbosgd,decvax,ihnp4,noao,philabs,princeton,vax135}!astrovax!wls



More information about the Comp.lang.c mailing list