tags:

views:

109

answers:

3

Hi,

I am looking at lots of assembly language code that is compiled along with c. They are using simple #define assembly without any headers in boot.s code. How does this work ?

A: 

Compilers can frequently include in-line assembly, but I believe it is compiler specific.

I don't remember the precise details, but I think its something like:

void myFunc(void)
{
    int myNum; /* plain old C */

    __asm   /* Assembly */
    {
       mov ax,bx;
       xor cx,cx;
    }

    myNum = 5; /* more C */
}

Research your specific compiler for details.

abelenky
yeah I know about inline assembly but mose of the time its written in a seperate .S file which doesnt use any headers. Thats why I asked the question.
brett
+1  A: 

Typically .s files are processed by an assembler. Without knowing any other details, there's nothing more to say. .s file goes in, .o file comes out.

Many assemblers provide some kind of include directive to allow use of headers, which would also be in assembly language.

Ah, the code you linked is for use by the GNU as assembler. If you're on Linux or Mac, do man as to learn about it. If you're on Windows, install MinGW or Cygwin.

Potatoswatter
A: 

The link you post in your comment is an assembly language source file that is meant to be first run through a c-preprocessor. It's just a programming convenience, but lots of assembly language compilers support similar constructs anyway, so I'm not sure why they went the c-preprocessor route.

Jim Buck
@Jim Buck why a c preprocessor is used ? Also I dint get they are compiling c and asm together so they are using a c compiler right ?
brett
They are using a C-preprocessor to have the benefit of using `#define` and C/C++-style comments (they are using `/* */`). And then they compile the result with an assembler. A C compiler is not used at all.
Jim Buck