Hi,

I am more comfortable in c(TC++ compiler) when it comes to really big programs.
But i wnat to use win32 asm for the frontend & faster computing & it's small size.

So my question is >
1> can we write functions in c & complile it to be used in assembly? If yes how?
2> how can we use those functions in our asm module.(invoke & include stuff)?
3> can we use invoke even in this case? (i feel only call can be used)?

I am waiting for some body to help me out .
Posted on 2002-09-02 05:38:26 by ajith
First up, this question is not particularly algorithmic in nature... Could a moderator move it to main?

Now for the question itself:
1) can we write functions in c & complile it to be used in assembly? If yes how?
Write them in C, compile to object code (o.obj), then when linking the assembly language specify this extra object file too.
In the assembly code, create an include (like a header file) defining that it is C calling type (unless the C code has specified a different type, such as stdcall). Check the proto keyword in the \masm32\help\masm32.hlp file provided with MASM32.

This has a problem, I believe that the Turbo C++ compiler creates OMF format object files by default. If you can get it to create COFF objects using some compiler switch, this would help. Otherwise link.exe will convert the object to COFF, and throw up a warning to that effect.

2) how can we use those functions in our asm module.
Once the PROTO has been defined:
MyCProc PROTO C a:DWORD
for example, then it should be useable in the assembly code.

3) can we use invoke even in this case?
Yes.
invoke is a built in macro. If you've defined a prototype, then you can use invoke.

Mirno
Posted on 2002-09-02 05:50:26 by Mirno
Thanks a lot for your reply.
Sorry for posting in wrong place as i am a newbie.
Bye
Posted on 2002-09-13 02:19:19 by ajith
One thing to beware of: some features of C++, and some libraries, require initialization of support code. You're generally safe with the C subset and standard C functions (except for stdio). That means only data structures are safe -- classes that don't have any member functions, which also means no constructors and no destructors.
Posted on 2002-09-13 21:00:00 by tenkey
Unless size if a prime concern, I advice to let C/C++ do its initialization and only add the assembly builded .obj to the project you are working with,
Posted on 2002-09-15 09:38:18 by dxantos
When I have to do that, I copy my function(s) to a Lib project using VC++, define them as STDCALL, and compile them...

After, I have a lib useable with the "includelib" keyword...

As Tenkey said, be careful with the C/C++ libraries, personally, I only do that with plain C code (eventually calling Win32 functions but never the libc functions or similar)...
Posted on 2002-09-15 09:43:12 by JCP
Thanks to all who replied to my question.
Finally i could write a 'c' program and use the same in assembly.

But the new problem i face is i can't use any of the libraries.

So My question is
1> Is there any way we can use c or c++ libraries (shipped along with the compiler) in our assembly prog?

2> like "wsprintf" function ,do we have any function that does the work of "sscanf"
function in C,that can be used in assembly ?

3>I did not use 'STDCALL' declarations. But simply saved the prog as casm.c & compiled it to get the obj file ,which i later used during linking to get the exe file.
I want to know how can we declare the function as STDCALL (Again a silly Question for you.Sorry for that...). Since i have used the normal C calling function & it's working perfectly in assembly, I am not getting the difference between C calling & STDCALL ing conventions.

Please help
Posted on 2002-09-30 05:49:17 by ajith

1> Is there any way we can use c or c++ libraries (shipped along with the compiler) in our assembly prog?


There probably is, but these libraries requires lots of code to initialize them... it is a bit tricky to use this from assembly, imho...


2> like "wsprintf" function ,do we have any function that does the work of "sscanf"
function in C,that can be used in assembly ?


Win32API provides some libc similar functions included in Windows, but there is no "native support" for the libc included in the win32api...


3>I did not use 'STDCALL' declarations. But simply saved the prog as casm.c & compiled it to get the obj file ,which i later used during linking to get the exe file.
I want to know how can we declare the function as STDCALL (Again a silly Question for you.Sorry for that...). Since i have used the normal C calling function & it's working perfectly in assembly, I am not getting the difference between C calling & STDCALL ing conventions.


Unless I have to deal with variable arguments functions, I way prefer the stdcall calling convention... it is more logical, results in more compact code, and it seems that the masm32 tool lib2inc doesn't find the function if it is not specified as a stdcall one... :grin:

If you have to use the C library extensively, I suggest you to program in C: everything you will do to interface some C functions (especially the ones dealing with streams like sscanf) will looks a bit tricky to my personal taste...
It is possible, but I way prefer to write replacement using pure code or the win32api...
If you have to use assembly from C, look at inline assembly or link your asm code as an obj or as a lib to your main C program...
Posted on 2002-09-30 06:18:22 by JCP
H,
i thanks for the reply.
I wanted that stuff because i wanted to use some float math in my programs<math.h>. Now i need to do them all manually.
Also i am working on a project in which i used 32bit asm for front end & using C library calls to do parallel port i/o. But facing problem in using the c libraries.

so the q is
1> how can we do the float +,-,/,* in asm.(I Lack asm knowledge)?

2>Can we make use of the math coprocessor on system? If so how?

3> what are the advantages of using math coprocessor for the same over manual coding?

4>how to return the float value from our functions? As eax is just 4bytes long & float or double operations require 8 or 10 bytes.

waiting for your reply.Guess you are online
Posted on 2002-09-30 06:32:53 by ajith
Search for FPU (floating point unit) on the forum search engine...

PS: Please don't post anything cracking or reversing related here... please read the rules (link on my signature).
Thanks in advance.

*EDIT*: and please edit your profile (interests)...
Posted on 2002-09-30 06:36:26 by JCP