-
inline assembly
Hi,
Need urgent help with the following problem
trying to call a class member function from a class using inline assembly
is this possible at all?
Code:
__asm {
__asm push edx
__asm push eax
__asm call MyFunction
__asm pop ecx
__asm pop ecx
}
MyFunction is the memberfunction
the error is:
error C2420: 'MyFunction' : illegal symbol in first operand
error C2415: improper operand type
I'm using MSVC++6.0
I guess this has something to do with the name mangling of the member function, or?
-
Code:
__asm {
__asm push edx
//...
}
I don't think you need those __asm's in there.
-
Oh, I know . . . in C I think it would be
-
it is technicall possible, but you have to know an awful lot about how your compiler mangles function names. Set you compiler to generate an assembly listing of your program then look to see how the compiler did it. It's a lot easier (and safer) to just let your compiler generate the assembly instructions to call class methods.
Here is a simple sample where CMyClass::foo() is calling a class function is_int() with one parameter.
Code:
push 252 ; 000000fcH
mov ecx, DWORD PTR _this$[ebp]
call ?is_int@CMyClass@@QAE_NH@Z ; CMyClass::is_int
mov BYTE PTR _b$[ebp], al
-
I get a whole lot of errors when doing this. I fetch the mangled name from the map file. But when i use this, I get:
error C2018: unknown character '0x40'
Maybe there's someway of escaping these characters?
according to msdn:
An __asm block can call only global C++ functions that are not overloaded. If you call an overloaded global C++ function or a C++ member function, the compiler issues an error.
You can also call any functions declared with extern "C" linkage. This allows an __asm block within a C++ program to call the C library functions, because all the standard header files declare the library functions to have extern "C" linkage.
(couldn't send a link to the page so....)
/S
-
What a waste of time. Just use C++.
-
> trying to call a class member function from a class using inline assembly
Why?
Just to see if you can?
I can't see any practical reason for this - nevermind the complete loss of portability in the process.
-
it's an interpreter for a certain instruction set, which has already been implemented in inline assembly. I want to use this in another work using classes, but I don't want to rewrite the all those instructions again
-
Code:
#include <cstdio>
class Foobar
{
public:
void CallMe(int x)
{
printf("%d\n",x);
}
};
int main(int argc, char* argv[])
{
Foobar foo;
__asm
{
MOV EAX,10
PUSH EAX
MOV ECX, DWORD PTR [foo]
CALL Foobar::CallMe
}
}