Hello everyone. Recently, I've been trying to add some inline assembly to one of my classes in MS Visual C++. For example, say I have a header like so...




class SomeClass
{
private:
LONGLONG bigNum;
int littleNum;

public:
void SomeFunct(void);

};




When I try to use Inline Asm in the definition for SomeFunct(), it always complains (sorry, at work and don't know the exact error). I am trying to use it like this...





void SomeFunct(void)
{
_asm
{
mov eax, dword ptr bigNum
mov edx, littleNum
}
}



Is there something special I need to do to access class variables? I have a really bad work around, but I'd prefer to do things the correct way. Thanks for any help. Cheers.
Posted on 2002-10-01 22:43:15 by AlexEiffel
It's a little counter-intuitive but here's the "correct" way you would do it according to MSDN.

[size=12]void SomeClass::SomeFunct(void)

{
__asm
{
lea eax, [this]SomeClass.bigNum
mov eax, dword ptr [eax]
lea edx, [this]SomeClass.littleNum
mov edx, dword ptr [edx]
}
}[/size]



Keep in mind that anytime you use .datamember you're loading the address and not the variable, whether you use mov, lea, or whatever. Also you can omit the class prefix but if you have a matching label in another class the compiler will get confused, so make a habit of using it.
Posted on 2002-10-02 09:41:19 by iblis
Thanks a lot for the help. Much appreciated. :grin:
Posted on 2002-10-02 13:32:45 by AlexEiffel
If you want to know how a compiler do this thing or another the trick is to generate the assembly listing (build options)...
It shows the C or C++ HLL code as comment and the assembly code corresponding to it under...
Posted on 2002-10-02 16:32:31 by JCP