Hello,

I've got an application written in C++ and now I'd like to speed it up a bit by using asm procedures for data manipulation on large arrays. So I've written a dll and am trying to pass the address of the first array element to my asm proc, from which i should be able to sequentially move through all elements. Sadly, my code won't work - so maybe some of you guys could help me out a bit?
Here's some testing code using an integer array, if anyone knows a better way or finds the mistake, I'd really appreciate it! Thanks in advance.

ASM PART (MASM32):

.386
.model flat, stdcall
option casemap:none
include d:\masm32\include\windows.inc
include d:\masm32\include\user32.inc
include d:\masm32\include\kernel32.inc
includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\kernel.lib
.data
MsgBoxCaption db "proc exec",0
MsgBoxText db "So far so good...",0
test1 dd 0
.code
DllEntry proc hInstDLL:HINSTANCE,reason:DWORD,reserved1:DWORD
mov eax,TRUE
ret
DllEntry endp

MyTestProc proc adrField:PTR
;mov eax,
.if ==2 ; TEST:do i have a pointer to my first element (which is 2)?
invoke MessageBox,NULL,addr MsgBoxText,addr MsgBoxCaption,MB_OK
.endif
ret
MyTestProc endp
End DllEntry

C++ part:

#include "windows.h"
#include "iostream.h"
extern "C" _declspec(dllexport)
typedef int (CALLBACK* LPFNDLLPROC)(int*);
int test[10]={2,5,2,4,5,6,7,8,9,10};
int main()
{
HINSTANCE hDLL;
LPFNDLLPROC lpfnASMProc;
hDLL = LoadLibrary("d:\\masm32\\test\\testdll\\testdll.dll");
if (hDLL != NULL)
{
lpfnASMProc = (LPFNDLLPROC)GetProcAddress(hDLL,"MyTestProc");
if (!lpfnASMProc)
{
FreeLibrary(hDLL);
cout<<"Proc not found!\n";
}
else
{
cout<<"Proc found!\n";
//pass address of first element
lpfnASMProc(&test[0]);
}
}
else
{
MessageBeep((WORD)-1);
cout<<"DLL not found!\n";
}
return 0;
}
Posted on 2002-09-12 10:26:49 by IH82W8
The value you are passing to the function is a 32 bit address.

You must remember that you cannot directly reference from memory, the x86 doesn't support such a mode of operation.

Try this instead:
MyTestProc proc adrField:PTR

mov eax, adrField
.if [eax]==2 ; TEST:do i have a pointer to my first element (which is 2)?
invoke MessageBox, NULL, addr MsgBoxText, addr MsgBoxCaption, MB_OK
.endif
ret
MyTestProc endp


Mirno
Posted on 2002-09-12 10:33:30 by Mirno
Great! Thank you very much, Mirno!!
Actually I had to put
.if dword ptr == 2
for it to work, but close enough.. I was stuck on this for a few days - hould have come here earlier! Thumbs up..

:alright: :alright: :alright:
Posted on 2002-09-12 15:59:50 by IH82W8
Ok, now for the theory of the funny part:
If that array wouldn't consist of int's but of custom classes - how to get member values of it in the asm part?
would you count the number of bytes 'before' the member var manually in the class definition and put that in an 'address offset' or is there a better way to do it?
Thanks in advance!
Posted on 2002-09-13 01:55:39 by IH82W8