tags:

views:

41

answers:

2

I wonder how can I get eflags register content using only c, without any _asm insertions. Is it possible?

+4  A: 

No, it is not possible in standard C without _asm, unless you have a C compiler with some very compiler specific way to do it.

Michael Goldshteyn
A: 

No way. But you can fool yourself with a nice macro. I can't test this right now, but something along the lines of:

#define GET_FLAGS(X) asm volatile ("pushfl;\
                                    popl %%eax;       \
                                    movl %%eax, %0;"  \
                                    :"=m" (X)         \
                                    ); 

uint32_t getFlags() {
    uint32_t flags;
    GET_FLAGS(flags);

    return flags;
}

Of course, it's highly architecture dependent. Very reduced portability here.

Santiago Lezica