![]() |
Implement C++ functions using MASM
I have a class with a member function that I wish to implement using MASM.
:
class Foo:
;ASM source:
extern "C" int __stdcall adder(int, int);:
int main()/Thanks for your help! /Klarre |
Try declaring it right after including headers.
|
Tried this
:
#include "foo.h":
error C2039: 'adder' : is not a member of 'Foo' |
Where are you doing anything to associate the definition with the class? :confused:
|
This is a bit tough and won't be portable, but its not impossible. First you need to understand what exactly a member function is compiled to, then you emulate that with your ASM function. Important things to know are how the name mangling works or not forgetting that VC passes an implicit this pointer to member functions.
I think your best bet is to write the function in C++, compile into debug code, open that up in a debugger to see what exactly VC expects the function to be called and copy that together with the calling convention in your ASM code. Also check out the Agner Fog's Manuals. |
Quote:
|
Are you laughing at the fact that Assembly is not portable? If so, very fair point :) . I ment though that a solution wouldn't be portable across different C++ compilers, even on identical architectures.
Actually Klarre, forgot to ask you an important question, why do you want to be able to write meber functions in ASM? Its easier to write stdcall or ccall ASM functions, build them into an object file or library, link that into your C++ app and then call those functions from inside member, or indeed any, functions. |
Yeah, no offense, it just tickled my funnybone when I read it.
|
Quote:
|
I finally got it linked correctly.
:
class Foo:
.386PThanks alot for your help! See you soon again! ;) /Klarre |
| All times are GMT -5. The time now is 12:51 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC