473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Help I need to call a member from assembler code (WIN32)

Hi to all!
I have something like this:

class FWrap {
public:
virtual void READ (void) = 0;
}

class Optimized {
private:
FWrap* FFile;

public:
void Calc (void);
}

I need to optimize Calc routine as much as I can because it is called
billion of times. In Calc function I must call FFile->READ () within
assembler code.

I have something like this now ...

void Calc (void)
{
__asm {
MOV EAX, &this // I get cell address which contain
'this' address
MOV EBX, [EAX] // Now I have 'this' address in EBX
MOV ECX, [EBX].FFile // Cell address which contain 'FFile'
address
MOV EBX, [ECX] // Now EBX contain 'FFile' address (EBX
= PIC)
...
???
}
}

Now I must call READ with something like "CALL DWORD PTR [EBX + ADDRESS
OF READ]" but I have no Idea how I can get the right offset READ
function.
I've tried FWrap::READ, FFile.READ and so on ... but I can't figure out
how I can call the right function address.

Is vital for me to create a function made of asm at 100%

Anyone can help me?

Sep 7 '05 #1
3 1562

<en***************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi to all!
I have something like this:

class FWrap {
public:
virtual void READ (void) = 0;
}

class Optimized {
private:
FWrap* FFile;

public:
void Calc (void);
}

I need to optimize Calc routine as much as I can because it is called
billion of times. In Calc function I must call FFile->READ () within
assembler code.

I have something like this now ...

void Calc (void)
{
__asm {
MOV EAX, &this // I get cell address which contain
'this' address
MOV EBX, [EAX] // Now I have 'this' address in EBX
MOV ECX, [EBX].FFile // Cell address which contain 'FFile'
address
MOV EBX, [ECX] // Now EBX contain 'FFile' address (EBX
= PIC)
...
???
}
}

Now I must call READ with something like "CALL DWORD PTR [EBX + ADDRESS
OF READ]" but I have no Idea how I can get the right offset READ
function.
I've tried FWrap::READ, FFile.READ and so on ... but I can't figure out
how I can call the right function address.

Is vital for me to create a function made of asm at 100%

Anyone can help me?

You can use a global, extern "C" wrapper function to call the member
function. Then your assembly can simple call the global function.

ben
Sep 7 '05 #2
en***************@gmail.com wrote:


I need to optimize Calc routine as much as I can because it is called
billion of times. In Calc function I must call FFile->READ () within
assembler code.
Is vital for me to create a function made of asm at 100%

Anyone can help me?


Not here. comp.lang.c++ is for platform independent C++.
Your question obivously deals with very platform specific things.
You need to ask in a newsgroup dealing with your particular compiler.

--
Karl Heinz Buchegger
kb******@gascad.at
Sep 7 '05 #3

en***************@gmail.com wrote:
Hi to all!
I have something like this:

class FWrap {
public:
virtual void READ (void) = 0;
Do not use all uppercase names for functions. READ screams MACRO
according to established (and good!) conventions.
}

class Optimized {
private:
FWrap* FFile;

public:
void Calc (void);
}

I need to optimize Calc routine as much as I can because it is called
billion of times. In Calc function I must call FFile->READ () within
assembler code.
This reminds me about an example assemlber program, Borland sent out
many, many years ago. Written in wonderful Borland assembler and
awfully slow because all time was spent inside an inefficient
IO-routine.
I have something like this now ...

[snip]

Is vital for me to create a function made of asm at 100%
Are you sure? Did you profile your program. To me it looks as if the
time is spent in the read function.
Anyone can help me?


Your code would be most fragile. Surely not portable - not to other
compilers, not to the next release of the same compiler and not from
one compiler setting to another. Much better would be to delegate to
some function where the function-call is not virtual - e.g.
extern "C" void Read(FWrap* fw)
{
return fw->READ();
}

This would probably improve portability regardless of compilersettings
(esp. if you decorate Read with __cdecl or whatever it is called), and
perhaps even from one compiler version to the next.
Still I recommend you not use my solution. Instead find out what takes
so much time.

/Peter

Sep 7 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dale McGorman | last post by:
The following is some code that I am trying to bring over from VB 6.0, that I have working there. I am trying to get to where I can talk to a USB device. I am stuck on how to correctly pass params...
3
by: fischerjd | last post by:
Is Microsoft still producing/releasing the Microsoft Macro Assembler (MASM)? I just installed Visual Studio .NET 2003 (p/o an MSDN/AA subscription) and apparently MASM is not provided/installed...
12
by: Anthony Jones | last post by:
Just a bit of background: I'm one of a group of FORTRAN programmers, looking to switch to C++. We are trying to write a few simple examples to demonstrate the power of the language to our manager,...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Tank | last post by:
How do I call OpenFileName Win32 API from C# ? Can someone show me a sample code ?
5
by: trint | last post by:
I know that this function IS in this dll that comes with windows xp that allows bidirectional printing (you can search "bidispl.dll" on MSDN). However, I keep getting the same error all day, go to...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
4
by: smp9737 | last post by:
Hello. I'm developing a Win32 Console Application for a Smart Device (MotoQ). All i need to do is delete a file with a known name and path. I'm under the impression that I have to use...
10
by: CuTe_Engineer | last post by:
hii, i have cs assignment i tried to solve it but i still have many errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote the prog. i just wanna you to show me my mistakes ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.