Jump to content
  • Advertisement
Sign in to follow this  
w00

[C++ / (inline)ASM]

This topic is 3048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just a quick question, how can i change a value with inline ASM in C++?? Suppose i have the following:
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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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:

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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!