intel inline assembly with gcc

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kan
Posts: 19
Joined: Sat Jan 22, 2005 12:00 am
Location: India

intel inline assembly with gcc

Post by kan »

hi,
i want to use inline assembly (with INTEL syntax) in my C Kernel code.
can i code like this in one of my C functions :

void CheckProcessor(void)
{
asm
{
mov eax,0x00;
cpuid;
.........
}
}

i give following compile options :

gcc -o KLoader.o -c KLoader.c -Wall -Werror -W --no-warn -nostdlib -nostartfiles -nodefaultlibs -masm=intel

given above options gcc doesn't compile source code. i think it has some problem with 'asm' keyword?
any solution would be highly appreciated!
Nothings Impossible :)
bregma
Member
Member
Posts: 25
Joined: Tue Oct 26, 2004 11:00 pm
Location: the back woods
Contact:

Re: intel inline assembly with gcc

Post by bregma »

kan wrote:

Code: Select all

void CheckProcessor(void)
{
  asm 
  {
     mov eax,0x00;
     cpuid;
     .........
  }
}
That's not the right syntax for GCC inline assembler. Inline assembly is a non-standard extension to any compiler. Regardless of the assembler syntax itself, GCC's extended asm syntax is more like the following.

Code: Select all

void CheckProcessor(void)
{
  asm("mov eax,0x00\n\tcpuid"
           : /* output constraints */ 
           : /* input constraints */
           : /* clobbers */);
  .......
}
You might want to consult your GCC documentation for more information.

--
smw
Post Reply