GCC on FreeBSD - C and ASM

S

Serpent

I have a few old routines written in Intel ASM; years ago they were
used inline a C-program. Now I find that to use inline-assembler with
GCC I have to use AT&T ASM. I figured the easiest solution would be to
simply put all the assembler in its own clean file, build that, and
link it to the C (from whence I'd be able to call the ASM routines). I
hope I'm not imaginatively expanding on the concept of linked object
files. It seems I >should< be able to call the assembler from the C.
How? Any decent resources on the topic?

Thanks!
- Elliot :)
 
J

jacob navia

Push the arguments in the stack

int a = myasm_routine(arg1,arg2,arg3);

Supposing word size args (32 bits) the asm
routine will find the args at esp+4,esp+8,esp+12,etc

That's all.

How is the ASM routine reading its input?

Does it expect it in some special places like
registers or like?

If yes, add an interface asm code like this:
; routine expects args in eax,edx
; put arg1 in eax
movl 4(%esp),%eax
; put arg2 in edx
movl 8(%esp),%edx
call original_asm_routine
ret

Use the -S option of your compiler and look
at the generated assembler.

Good luck
 
K

Keith Thompson

jacob navia said:
Push the arguments in the stack

int a = myasm_routine(arg1,arg2,arg3);

Supposing word size args (32 bits) the asm
routine will find the args at esp+4,esp+8,esp+12,etc

That's all.

How is the ASM routine reading its input?

Does it expect it in some special places like
registers or like?

If yes, add an interface asm code like this:
; routine expects args in eax,edx
; put arg1 in eax
movl 4(%esp),%eax
; put arg2 in edx
movl 8(%esp),%edx
call original_asm_routine
ret

Use the -S option of your compiler and look
at the generated assembler.

I suppose the OP is probably using an x86 system, but I can't be
certain; it may be obvious from the context, but not to me.

I have no idea whether Jacob's response is correct, because he's
really talking about assembly language, not about C.

Which is why both the question and the answer really belong in a
system-specific newsgroup, where it can be discussed intelligently,
rather than here in comp.lang.c, where it's off-topic.

I can understand the OP making that mistake; it happens all the time,
and the usual (and proper) response is to suggest a better place to
get help.
 
B

brian

Serpent said:
I have a few old routines written in Intel ASM; years ago they were
used inline a C-program. Now I find that to use inline-assembler with
GCC I have to use AT&T ASM. I figured the easiest solution would be to
simply put all the assembler in its own clean file, build that, and
link it to the C (from whence I'd be able to call the ASM routines). I
hope I'm not imaginatively expanding on the concept of linked object
files. It seems I >should< be able to call the assembler from the C.
How? Any decent resources on the topic?

Thanks!
- Elliot :)

Check out NASM and it's related website.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top