Question

I have this code:

__asm jno no_oflow
overflow = 1;
__asm no_oflow:

It produces this nice warning:

error C4235: nonstandard extension used : '__asm' keyword not supported on this architecture

What would be an equivalent/acceptable replacement for this code to check the overflow of a subtraction operation that happened before it?

Was it helpful?

Solution

First define the following:

#ifdef _M_IX86
typedef unsigned int READETYPE;
#else
typedef unsigned __int64 READETYPE;
#endif

extern "C"
{
READETYPE __readeflags();
}

#pragma intrinsic(__readeflags)

You can then check the eflags register as follows:

if ( (__readeflags() & 0x800))
{
    overflow = 1;
}

OTHER TIPS

I assume that the code above is trying to catch some sort of integer overflow/underflow? Maybe the answers to this question will help: How to detect integer overflow?

Here's a list of intrinsics available on all platforms. Looks there's nothing suitable there. I guess the most portable way would be to check before the subtraction whether it will lead to an overflow.

I'm not sure why Microsoft disallowed inline assembly in 64-bit. but you can still write assembly in a separate .asm file, and link your program against it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top