views:

188

answers:

3

i am designing a compiler in c . but for certain problems like big integers i have to code in assembly code . so how can i integrate assembly code in c?

i am wrting my code in dev cpp.. which i suppose uses gcc ... in windows..!!..

pls give me instructions for linux too

+2  A: 

Use the 'asm' instruction, e.g.

asm("movl %ecx %eax"); /* moves the contents of ecx to eax */
Chaos
+4  A: 

using asm

Good article : GCC-Inline-Assembly-HOWTO

aJ
A: 

Don't you compile the runtime with your own compiler?

Note that another option is to use an external assembler (like AS). Less optimal, but the principle is portable. (though assembler syntaxes vary wildly)

Our own little compiler (which is GCC linking compatible) used AS for most of its assembler, and only acquired an own internal assembler after 8 year or so.

P.s. if you implement an internal assembler, have a look at NASM, their tables of assembler instructions and their addressing are really clean and can be often get converted (and used for regular updates for new instructions)

Marco van de Voort