Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅使用c获得eflags_C - Fatal编程技术网

如何仅使用c获得eflags

如何仅使用c获得eflags,c,C,我想知道如何只使用c,而不使用任何asm插入来获取eflags寄存器内容。这可能吗?不,在没有asm的标准C中是不可能的,除非你有一个C编译器,它有一些非常特定的编译器方法来实现它。不可能。但是你可以用一个漂亮的宏来愚弄自己。我现在无法对此进行测试,但大致如下: #define GET_FLAGS(X) asm volatile ("pushfl;\ popl %%eax; \

我想知道如何只使用c,而不使用任何asm插入来获取eflags寄存器内容。这可能吗?

不,在没有asm的标准C中是不可能的,除非你有一个C编译器,它有一些非常特定的编译器方法来实现它。

不可能。但是你可以用一个漂亮的宏来愚弄自己。我现在无法对此进行测试,但大致如下:

#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;
}

当然,它高度依赖于体系结构。这里的可移植性非常低。

根据编译器的不同,您可能会有一个头
,其中包含一些用于访问CPU特定功能的特殊函数。