gcc has a syntax for incorporating assembly code into your C code. For
instance, here's a function from crt0.c, the file that provides the
application startup and shutdown glue:

static void do_bhook(Word cmd, Ptr PBP, Word flags)
{
    void **hookend, **hookptr;
    unsigned long text = (unsigned long)&start;
    asm ("sub.l #start, %0" : "=g" (text) : "0" (text));

    asm ("lea bhook_start(%%pc),%0" : "=a" (hookptr) :);
    asm ("lea bhook_end(%%pc),%0" : "=a" (hookend) :);

    while (hookptr < hookend) {
     void (*fptr)(Word,Ptr,Word) = (*(hookptr++)) + text;
     fptr(cmd,PBP,flags);
    }
}

This is just an example. There's also a syntax for multi-line statements
(so that you don't have to say "asm" all the time).

I don't know what the full syntax is or even what most of the above example
means. You should probably poke around the gnu site for some documentation
on this.

Or just program in C...   :-)

-- Keith Rollin






ml user <[EMAIL PROTECTED]> on 04/26/99 02:26:47 PM

Please respond to [EMAIL PROTECTED]

To:   [EMAIL PROTECTED]
cc:    (Keith Rollin/HQ/3Com)
Subject:  asm in C source, how ?




Hi,
how do I integrate a function written in assembler into a C source file (a
programm written in C) ? I'm using gcc/Linux.
thanks ... Collin









Reply via email to