struct blaat
{
char name[128];
bool bWoot;
} BLA;
int main()
{
BLA bla;
__asm
{
mov [bla.bWoot], 1 //<-- this doesn't do the trick
mov [bla.name], edx //<-- suppose edx contains a string, then this also doesn't work
}
return 0;
}
I can't change the values of my struct that way with asm. Anyone any idea how i can do it?
[C++ / (inline)ASM]
Just a quick question, how can i change a value with inline ASM in C++??
Suppose i have the following:
Just mov bla.bWoot, 1 should work.
And I don't know what you mean with edx contains a string. It could contain the address of a string, but then that code won't put it into name. Perhaps you want char *name as an address to a string, if you want to use it that way. You can do mov bla.name, 'c' however.
And I don't know what you mean with edx contains a string. It could contain the address of a string, but then that code won't put it into name. Perhaps you want char *name as an address to a string, if you want to use it that way. You can do mov bla.name, 'c' however.
I'm actually not sure what edx contains, but it must be some sort of string. I'll try to explain it a bit more.
I'm trying to find out if the CPU supports the SSE (SIMD technology).
When i call CPUID it automatically checks what number is stored in eax, then it returns new data about the CPU which is stored in other registers.
If you check my code below you'll see that i'm getting the vendorname of the CPU first. The name of the vendor is always 12 letters long. So this means it's stored in three different registers; ebx, edx and ecx.
I already knew how to put the result back into my struct. I'm declaring a char* which points to the char in my struct. But i was hoping that there was a direct way to set the value.
But that part isn't important right now, cause it does work.
What doesn't is setting the boolean. When i print out the boolean value i get '204' in console... Any idea why that is??
This is my code:
I'm trying to find out if the CPU supports the SSE (SIMD technology).
When i call CPUID it automatically checks what number is stored in eax, then it returns new data about the CPU which is stored in other registers.
If you check my code below you'll see that i'm getting the vendorname of the CPU first. The name of the vendor is always 12 letters long. So this means it's stored in three different registers; ebx, edx and ecx.
I already knew how to put the result back into my struct. I'm declaring a char* which points to the char in my struct. But i was hoping that there was a direct way to set the value.
But that part isn't important right now, cause it does work.
What doesn't is setting the boolean. When i print out the boolean value i get '204' in console... Any idea why that is??
This is my code:
typedef struct CPUINFO_TYP{ char cpuName[48]; bool bSSE;} CPUINFO;CPUINFO GetCPUInfo ( ) { CPUINFO info; char* pStr = info.cpuName; //address to vendor name __asm { xor eax, eax mov eax, 0 CPUID //Get vendor name mov esi, pStr mov [esi], ebx mov [esi+4], edx mov [esi+8], ecx //Check if the CPU supports SSE mov eax, 1 test edx, 02000000h jz __NOSSE //if negative jump mov info.bSSE, 0 //else, set bool in struct to TRUE__NOSSE: } pStr[12] = '\0'; return info;}int main (){ CPUINFO info = GetCPUInfo ( ); cout << info.cpuName << endl; if ( info.bSSE ) cout << info.bSSE << endl; system("pause"); return 0;}
My assembly is rusty, but I think it sees the '1' as an address. Try to move the value into a register first and see if that clears it up.
Quote:Original post by w00
I'm trying to find out if the CPU supports the SSE (SIMD technology).
If that is all, would an intrinsic help?
Quote:When i print out the boolean value i get '204' in console... Any idea why that is??
The SSE support are single bits somewhere in there which need to be extracted. bool type is something else, so it cannot be used directly. See the example.
hmm, i don't get it. Because i'm using ASM to set the boolean, not SSE...
Also, putting the value 1 in a register doesn't work either. Then i get an error 'operand size conflict'
xor esi, esi
mov esi, 1
mov [info.bSSE], esi
Also, putting the value 1 in a register doesn't work either. Then i get an error 'operand size conflict'
xor esi, esi
mov esi, 1
mov [info.bSSE], esi
As already linked, use the cpuid intrinsic and not raw assembly. There's no reason to use raw assembly to do what you're doing, since the intrinsic provides the behavior required already (and in a much cleaner package).
I don't think i can set a bool in my struct with SSE. I use the instrinct to check if SSE is availible, but to set a boolean value in my struct i really think i need ASM for that.
But fortunately i already have the answer. To set the contents of ebx, edx and ecx directly in my char i have to use lea instead of mov.
lea esi, [info.cpuName]
and for the boolean i have to use byte ptr.
mov byte ptr [info.bSSE], 1
This works perfectly.
But fortunately i already have the answer. To set the contents of ebx, edx and ecx directly in my char i have to use lea instead of mov.
lea esi, [info.cpuName]
and for the boolean i have to use byte ptr.
mov byte ptr [info.bSSE], 1
This works perfectly.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement