Behaviour of unsigned cast

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Apr 10 08:04:37 PDT 2007


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.



More information about the Digitalmars-d mailing list