This is probably another question that could easily be answered by the FAQ but I heard that a lot of programmes written in Assembler implement C code - for instance using C and ASM simultaneously. Is this just waffle or can it be done?
Printable View
This is probably another question that could easily be answered by the FAQ but I heard that a lot of programmes written in Assembler implement C code - for instance using C and ASM simultaneously. Is this just waffle or can it be done?
If the faq might answer this question, why didnt you try there first?
But no. Assembler can not use c code. C can use asm though.
I did check the FAQ, I just didn't read through all of it ;)
Perhaps I should have phrased the question better - I didn't mean can C code be written in ASM, I mean was it possible for code in C to call code in ASM
eg:
Thanks anywayCode:int DoSomething ( Blah ) {
//Call ASM function
}
Thanks anyway?
I answerd your question.
Yeah, thanks anyway - it's an expression. ;)
Using Visual Studio you can do it easily
like:
Code:int DoSomething ( Blah ) {
_asm{
// Do some stuff in assembly
}
}
Two options:
a) write a function collection in assembly and assemble it. You can include the object files in your project (but only corresponding compiler/assembler combos: MASM and VC++, TASM and Borland C++ builder, NASM and DJGPP, as and gcc) and call the functions. Note that you must heed the naming conventions:
C function declaration:
void AsmFunc(int i);
ASM function:
_AsmFunc
declaration:
void __stdcall AsmFunc(int i, double d);
ASM:
_AsmFunc@12
In C++, add a extern "C" block around the declarations.
b) write a few assembly lines directly into the C/C++ code. Almost every compiler supports the keyword asm (or _asm) which can be used for a single instruction and for a whole block. The standard even requires another way of doing it, but this way is weird and is neither supported nor used often.
You can use any assembler with any c compiler. You dont have to have their counterpart,
To respond to another post above... You can certainly use C code in an assembly program. They all compile to the same basic code.
Z.
Not really. C code is "c = a + b /e". It gets turned into asm, and that asm can be copied into your asm file. Also, you can call a c function from your asm code, but thats not using c code in your asm code either.
chimp:
If you use external object files that were written in assembler to include asm functions in your application, you need to use the counterpart. e.g. the microsoft linker can only read object/library files created by MASM or MSVC. Same thing probably for TASM and the Builder.
And why is calling C functions from assembler not using C code in an assembler app? You cannot directly include C code in ASM like vice versa, but the external object file solution is possible.
Ive used pretty much any assembler for any c compiler. You just have to know how to use them. You do not need tasm to write assembly for turbo c.
And calling a c function from an assembly source file is not using c in your asm. Its just not. Its calling a c function from asm.
[quote]You cannot directly include C code in ASM like vice versa, but the external object file solution is possible.[quote]
The external object file solution is possible with any compiled language.
So, how do I include object code created with TASM in my VC++ project?
Yeah, it's possible for every compiled language. So what?
You assemble the file in tasm. And then when your linking in vc, include the object file. Theres a little more to it, but im not gonna sit here and explain it for you.
You said it like sometimes its not possible.
I know that you cannot use Borland Static Libraries for MS and vice versa (I tried). I figured it would be impossible with object files too.
Im not sure what you meant by Borland static libraries. Im guessing you mean .lib files that come with tasm for you to use. Im talking just pure code. No outside libs.
I mean .lib files that are created by the Borland linker. They are different from those created by the MS linker. So I thought .obj files would also be different.
Never used them so i dont know. But ive never had any major problems.
You should be able to use _C_ libs, as there is no name mangling differences across compiler vendors or versions, like in C++. Objs should be the same.
Z.