Home arrow Forums
OSDEV Forums  


anonymous
Visitor

Fresh Osdever
Posts: 0
graphgraph
Karma: 0  
intel inline assembly with gcc - 2005/06/28 00:55 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!
  | | The administrator has disabled public write access.
OSDEV
Community
Advertisement
   
anonymous
Visitor

Fresh Osdever
Posts: 0
graphgraph
Karma: 0  
Re: intel inline assembly with gcc - 2005/06/28 03:21 isn't the asm syntax with () instead of {}

hope this helps
  | | The administrator has disabled public write access.
eosp
User

Junior Osdever
Posts: 6
graphgraph
Karma: 0  
Re: intel inline assembly with gcc - 2005/06/28 08:28 I'm not sure, but I think both formats work with gcc.

asm { ... } for a long code block (like an entire function), and asm("..." : : : ) for a single line, although you can put more than one line.

btw, gcc is incompatible unless you write it yourself, of course with intel syntax. use at&t.

EDIT: never mind that, I was mixing up my compilers. The only valid GCC syntax is:

asm("..." : : : ); and at&t assembler.
[ Edited Wed Jun 29 2005, 12:25AM ]
  | | The administrator has disabled public write access.
gaf
User

Platinum Osdever
Posts: 153
graph
Karma: 10  
Re: intel inline assembly with gcc - 2005/06/29 13:36 As eosp already said, gcc only supports inline assembly in at&t syntax. Since it's a rather complex syntax in my opinion, you might prefere using an external asm-file:

Code:
[nasm asm-file]

section .text
bits 32

global CheckProcessor

CheckProcessor:
mov eax,0x00;
cpuid;
.........

[C file]
extern CheckProcessor();


Parameters are pushed by the compilerbefore calling the asm code (from the right to the left) and can be accessed through the stack using ebp. The return value is stored in the eax register.

regards,
gaf
  | | The administrator has disabled public write access.
eosp
User

Junior Osdever
Posts: 6
graphgraph
Karma: 0  
Re: intel inline assembly with gcc - 2005/06/30 08:37 Notes on the previous post: No semicolons after instructions.
  | | The administrator has disabled public write access.

A WebArticles site. Sponsored by Evoleto. Motorola V525 / Business Directory / Delaware Incorporation / Home Made Bazaar