Teen Programmers Unite  
 

 

Return to forum top

vc++ inline assembly

Posted by CViper [send private reply] at August 16, 2002, 05:58:52 AM

Does anyone know how to call/jmp to a class member function in vc++ inline assemly?

eg __asm {
<do some stuff>
jmp class::function
}

the problem is that i get an error, saying "class::function" is invalid (actually a few about it).
Anyone got an idea what the correct label for a member function is?

Posted by Psion [send private reply] at August 16, 2002, 10:01:40 AM

Why on earth are you doing this? I don't know how to do this (I'd prefer not even touch C/C++, let alone assembly), but keep in mind that you need to pass the object on which you are calling the function, if the function is not static.

Posted by diegoeskryptic [send private reply] at August 16, 2002, 11:34:42 AM

psion... what programming language do you prefer?

Posted by CViper [send private reply] at August 16, 2002, 02:21:26 PM

psion: that's the <do some stuff> part :)

it's quite simple: you have an active object (some global); otherwise the arguments are already the same. You only have to put the pointer of the global object on the stack between the other arguments and the return address.

The compiler produces - even with full optimation on - pretty bad code (like another call and all arguments are pushed one more time)

It's part of a litte wrapper around some stuff that's pretty nasty to use otherwise :/

Posted by gian [send private reply] at August 16, 2002, 04:11:11 PM

I think he's an ML whore now, but who can really be sure!

Posted by DragonWolf [send private reply] at August 21, 2002, 05:17:38 AM

Have you tried instantiating your class and calling it that way?

Posted by CViper [send private reply] at August 21, 2002, 11:55:31 AM

yeah - that is if i understand correctly and you mean something like

 c c1;
__asm { jmp/call c1.func }

or
 c* cptr;
__asm { jmp/call [cptr].func }


Won't work either; don't remeber the error returned, but i think it's something about '.func' beeing an invalid member/no data member.
Posted by Psion [send private reply] at August 21, 2002, 12:30:18 PM

If your compiler is bad enough that you need inline assembly to make function calls fast enough, then it's time to get a new compiler, not to use inline assembly.

Posted by gian [send private reply] at August 21, 2002, 09:06:34 PM

And my guess would be that the complexity and time required in order to call that function within the class would take more time that either redoing everything in well-coded C++ or redoing everything in assembly.

Posted by CViper [send private reply] at August 22, 2002, 11:08:37 AM

hmm... the compiler isn't bad; it was just more or less a single instance where a jmp would have done the work, instead of a lot of pushing arguments, the calling something and then cleaning the stack :P

whatever; it was also out of general interest the question was asked - at some point it might be handy to know how to do that...

Posted by Magna [send private reply] at August 30, 2002, 11:08:14 PM

Just a guess, but you might be able to move the function into a pointer and jmp/call it from there.

Like this, (I forget the exact way to do class member pointers, sorry if it's wrong).

void (CClass::*pFunc) ();
pFunc = &CClass::MyFunc;
__asm
{
push this
call pFunc
}

I think that should work, pFunc is just a 32-bit address so you should be able to call it like a normal function.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.