views:

203

answers:

4

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?

A: 

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.

sharptooth
A: 

I assume that the code above is trying to catch some sort of integer overflow/underflow? Maybe the answers to this question will help: http://stackoverflow.com/questions/199333/best-way-to-detect-integer-overflow-in-c-c

Timo Geusch
+2  A: 

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;
}
Goz
Thanks - this solves it and leaves the functionality basically identical! - I think it's enough to just include <intrin.h> and use readeflags - also I'll change 0x800 to ( 1 << 11 ) to make it a bit more readable
RnR
Good links for future reference: http://msdn.microsoft.com/en-us/library/aa983406%28VS.80%29.aspx, http://en.wikipedia.org/wiki/FLAGS_register_%28computing%29
RnR
A: 

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.

jalf