GCC on FreeBSD - C and ASM

Discussion in 'C Programming' started by Serpent, Jul 21, 2004.

  1. Serpent

    Serpent Guest

    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 :)
    Serpent, Jul 21, 2004
    #1
    1. Advertising

  2. Serpent

    jacob navia Guest

    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
    jacob navia, Jul 21, 2004
    #2
    1. Advertising

  3. "jacob navia" <> writes:
    > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Jul 21, 2004
    #3
  4. Serpent

    brian Guest

    Serpent wrote:
    > 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
    brian, Jul 22, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-15?Q?S=F6nke_Tesch?=

    Weird syntax error with gcc and FreeBSD

    =?ISO-8859-15?Q?S=F6nke_Tesch?=, Oct 22, 2003, in forum: C Programming
    Replies:
    5
    Views:
    446
    =?ISO-8859-1?Q?S=F6nke_Tesch?=
    Oct 24, 2003
  2. Spike

    GCC and asm()

    Spike, Dec 22, 2004, in forum: C Programming
    Replies:
    3
    Views:
    335
    Michael Mair
    Dec 22, 2004
  3. Razvan Cojocaru
    Replies:
    1
    Views:
    440
  4. Akira Kitada
    Replies:
    0
    Views:
    712
    Akira Kitada
    Oct 25, 2008
  5. M.-A. Lemburg
    Replies:
    0
    Views:
    387
    M.-A. Lemburg
    Oct 25, 2008
Loading...

Share This Page