Hi You All, I need a sample of an asm DDL func for C++ to call dynamically. In the "Winasm" sample directory, I do find two samples "usedll.asm" and "skeleton.asm" to describe how to build an asm DDL. But now I intend to build an asm DDL func for a C++ program. I have tried the skeleton format hard and all failed. I enclose my asm func "afft2.asm" in the attachment and hope someone may be able to reconstruct it into a "afft2.ddl" for a C++ to call. The C++ calling func may look like this:

afft(mode,npsd,npow2,t,w,xseg); supposing all arguments are pointers to address, i.e. to pass address rather than pass value.

best regards and many thanks.
Posted on 2004-02-18 05:02:18 by yhcheng

You could get more help if you post all your project files. Also clarify what you mean "fail".


Posted on 2004-02-18 05:16:09 by akyprian
First many thanks to akyprian.
I put the original five workable file ??afft.c??, ??afft1.asm??,??afft.def??,??afft.dll?? and ??spctrm0.e??
put in the attachment. The ??spctrm0.e?? is a file of GAUSS6.0 which is a statistical package providing foreign language interface for C++ only. The Gauss requires a C++ func to look like this:
Int func(double *arg[]);
The procedure to build the ??afft.dll?? file is done in the following way:
For MSC Visual C++ operation,
(1) open new project "afft"
(2)choose Dynamic-linking Library and choose empty project.
(3) in the command line option,choose "project" command, choose "add to project" and "files" command.
(4) add "afft1.obj" , "afft.c","afft.def" to the project
(5) in the command line option, choose ??build?? command and ??build afft.dll?? to complete.
For Masm32 operation in the MSC Visual C++ environment
(6) copy ??ml.exe??,??ml.err?? and ??ml.ded?? from ??masm32\bin?? directory to ??Microsoft visual studio\VC98\BIN?? directory.
(7) in the command line option,choose project -->??settings-->??file visual-->??afft1.asm-->??command build. In the ??commands?? filling-in block,fill in the ??ml /c /Cp /Cx /coff d:\GAUSSL6.0\fli\afft1.asm?? .
(8) In the ??outputs?? filling-in block ,fill in the ??$(InputPath)afft1.obj?? .
(9) in the command line option ,choose Build -->??compile afft1.asm.

As you see, the normal procedure is for Gauss to call C++ and for C++ to call ASM. Now I try to call ASM directly from GAUSS. And I am sure the calling convention still sticks to the convention of C++.
I have used the skeleton of ??afft2.asm?? to successfully build the ??afft2.dll??, and for testing purpose, in the final step I even intentionally use ??jmp to end ?? skill in the beginning code to skip most in-between codes, but all the same problem was reported. The massage is like the followings:
1)in first error dialog,??Gauss UI application encounters problem, must be closed.??
2)in the second error dialog, [??0x73d31351?? instruction refers to ??0x00000004?? memory, and that memory should not be read. Press ??Ok?? to terminate program.]
Well,I guess I may have my problem more clear now.
best regards.
Posted on 2004-02-18 06:39:56 by yhcheng
Many thanks for your help in this problem, Akyprian
Now I think I already have the initial success in the try. First I will thank the good samples for an ASM dll in the Winasm Studio.
Later I will upload the basic structure and describe how it works along with important things to note in window environment.
The need to call a asm dll directly from Gauss rather than from Gauss to C++ and C++ to ASM is simply that a C++ dll size takes about 217K and an ASM dll only 4k.
Best regards.
Posted on 2004-02-19 22:56:42 by yhcheng

I am glad you 've succeded. I am sorry I couldn't find the time to help more. I've been very busy lately.


Posted on 2004-02-20 00:24:41 by akyprian
Many thanks for your concerns in my problem, Akyprian
The key is in the stack structure built for the dll func and in any register one may modify within the dll func.
When Gauss or any C++ package loads a dll func, it pushes necessary arguments(in value or address) in the stack and then calls the dll func. In the attachment example, the Gauss ??dllcall?? command pushes six four-bytes address arguments into stack and then calls the ??Asmfft?? asm func. Here is what Gauss code looks like:
dllcall Asmfft(mode,npsd,npow2,t,w,xseg);
When the asmfft takes over execution, it must manage what registers and stack space it will use.
In the asmfft example, I uses registers like eax, ebx,ecx,edx,esi,edi, and 116 bytes stack space.
The important thing is not to change any status of registers when you take the charge from Window.
So one should push esi,edi on beginning codes and pop them on ending codes. As to registers like eax,ebx,ecx or edx, one may choose to keep its status or not, depending on the window func preceding the dll call. Since most window func returns value into eax, it is better to push eax as well.
Now the structure of stack after asmfft takes charge of execution will look like the following:
-- -------------------------4-bytes
---------------------------4-bytes, for addressing ??Xseg?? in the stack
----------------------------4-bytes, for addressing ??w?? in the stack
----------------------------4-bytes, for addressing ??t?? in the stack
----------------------------4-bytes, for addressing ??npow2?? in the stack
----------------------------4-bytes, for addressing ??npsd?? in the stack
----------------------------2-bytes, for addressing ??mode?? in the stack
cs--> a must for any call in any language
ip--> a must for any call in any language
ebp--> a must if one needs to use stack in any subroutine func
Though here no data segemt is used in the asmfft, it by no means can not done as have been shown in the dll sample of Winasm Studio . In extreme situation, an OBJ class containing data member and methods for the OOP concept can be used in the asmfft example. For this I have a sample modified from someone??s work (nothing to do with asmfft) in the ??Simple !!!!!! OOP Example demanded?? thread on the ??Object Oriented Programming?? topic.
Best regards.
Posted on 2004-02-20 02:15:46 by yhcheng