How to get eflags using only c
I wonder how can I get eflags register开发者_C百科 content using only c, without any _asm insertions. Is it possible?
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.
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.
精彩评论