|
-
Feb 19th, 2002, 01:42 PM
#1
Thread Starter
Addicted Member
C and Assembly
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?
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Feb 19th, 2002, 01:45 PM
#2
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.
-
Feb 19th, 2002, 02:03 PM
#3
Thread Starter
Addicted Member
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:
Code:
int DoSomething ( Blah ) {
//Call ASM function
}
Thanks anyway
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Feb 19th, 2002, 02:07 PM
#4
Thanks anyway?
I answerd your question.
-
Feb 20th, 2002, 07:44 AM
#5
Thread Starter
Addicted Member
Yeah, thanks anyway - it's an expression.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Feb 20th, 2002, 10:50 AM
#6
Lively Member
Using Visual Studio you can do it easily
like:
Code:
int DoSomething ( Blah ) {
_asm{
// Do some stuff in assembly
}
}
-
Feb 20th, 2002, 12:48 PM
#7
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 20th, 2002, 01:20 PM
#8
You can use any assembler with any c compiler. You dont have to have their counterpart,
-
Feb 20th, 2002, 06:26 PM
#9
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.
-
Feb 21st, 2002, 01:01 AM
#10
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.
-
Feb 21st, 2002, 10:16 AM
#11
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 21st, 2002, 12:58 PM
#12
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.
-
Feb 22nd, 2002, 08:21 AM
#13
So, how do I include object code created with TASM in my VC++ project?
Yeah, it's possible for every compiled language. So what?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 22nd, 2002, 02:09 PM
#14
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.
-
Feb 23rd, 2002, 11:26 AM
#15
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 23rd, 2002, 01:43 PM
#16
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.
-
Feb 24th, 2002, 05:03 AM
#17
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 24th, 2002, 01:45 PM
#18
Never used them so i dont know. But ive never had any major problems.
-
Feb 27th, 2002, 09:24 PM
#19
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|