Quite simple, really. I tried to use EAX[31:26] in my code, and was presented with the following error:
error C2400: inline assembler syntax error in 'second operand'; found ':'
And here’s my code:
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;
Is it possible to select bits in the way shown above in MSVC’s inline assembler? Am I missing something?
Assuming you’re using 0-based bit numbers with 0 being the least significant bit, you can get those top six bits simply by right-shifting
eax26 bits.That gives you the upper six bits in the lower bit positions. If you want the result in the same bit positions, simply
andit with0xfc000000.If I’ve misunderstood your bit positions, you can still use shifts and the bitwise operators to get what you want, though the values (that you want to
andwith or shift by) may differ.Based on your comment:
The way you would get the number of cores is as follows: