Behaviour of unsigned cast

David B. Held dheld at codelogicconsulting.com
Tue Apr 10 08:48:36 PDT 2007


Frits van Bommel wrote:
> Dan wrote:
>> Somehow I don't see how cmp EAX, EBX knows what sign the operands are.
> 
> It doesn't.
> "cmp" sets several flags, among others the carry (CF) and overflow (OF) 
> flags. CF being 1 means that if the operands were unsigned there was an 
> overflow condition. OF being 1 means that if they were signed there was 
> an overflow condition. (Note that "cmp" is basically a non-modifying 
> "sub", so "overflow" here means that EAX < EBX)
> If the program wants to know whether an overflow occurred it needs to 
> check the value of the appropriate flag, typically using an appropriate 
> conditional instruction (often a jump).
> Note that there is no such flag intended for mixed-signedness comparisons.

So what do you guys think of mixed-sign arithmetic?  +, - , *, /, etc? 
Does it cause you problems, or too convenient to give up?

Dave



More information about the Digitalmars-d mailing list