gpt4 book ai didi

c++ - 无法在 Microsoft VC++ Inline ASM 中选择位

转载 作者:行者123 更新时间:2023-11-30 02:58:57 25 4
gpt4 key购买 nike

很简单,真的。我尝试在我的代码中使用 EAX[31:26],但出现以下错误:

错误 C2400:“第二个操作数”中的内联汇编程序语法错误;找到 ':'

这是我的代码:

unsigned _EAX, _EBX, _ECX, _EDX ;
//LoadCPUID(EAX_CACHECONFIG, _EAX, _EBX, _ECX, _EDX);

__asm {
mov EAX, EAX_CACHECONFIG ;
mov ECX, 0x00000001 ;
cpuid ;
mov _EAX, EAX[31:26] ;
}

return _EAX;

是否可以在 MSVC 的内联汇编程序中以上述方式选择位?我错过了什么吗?

最佳答案

假设您使用基于 0 的位数,其中 0 是最低有效位,您只需将 eax 右移 26 位即可获得前六位。

这为您提供了低位位置的高六位。如果您希望结果位于相同 位位置,只需 使用0xfc000000 即可。

如果我误解了你的位位置,你仍然可以使用移位和按位运算符来得到你想要的,尽管值(你想要 and with or shift by)可能不同.

根据您的评论:

After executing the CPUID instruction, (EAX[31:26] + 1) contains the number of cores.

获取核心数的方法如下:

...                  ; load up cpuid registers first
cpuid
shr eax, 26 ; move bits 31:26 down to 5:0
inc eax
... ; eax now contains the core count (1 thru 64).

关于c++ - 无法在 Microsoft VC++ Inline ASM 中选择位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13352881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com