Page 1 of 1

GNU AS using .intel_syntax inline?

Posted: Sat Apr 11, 2009 2:54 pm
by Jimmio92
Hello everyone.

I've been trying to use AS with the .intel_syntax... and it's able to create the proper source and build it, but I can't get variables into the asm(...); no matter what I've tried.

I'm not even sure that the variables getting in there are the issue... but it's my best guess as it says undefined reference on the two variables I'm trying to use.

(rather simple)Code below:

Code: Select all

void outb(u16 port,u8 value)
{
    	//asm volatile("outb %1, %0" : : "dN" (port), "a" (value));
	asm volatile("mov dx,_port");
	asm volatile("mov al,_value");
	asm volatile("out dx,al");
}
The commented asm command is the exact same thing in AT&T syntax.

Any help on the matter would be much appreciated.
-Jim

[EDIT] It seems I'm now only getting "too many memory references"

Code: Select all

./src/kernel.c: Assembler messages:
./src/kernel.c:7: Error: too many memory references for `mov'
./src/kernel.c:8: Error: too many memory references for `mov'
./src/kernel.c:9: Error: too many memory references for `out'

Re: GNU AS using .intel_syntax inline?

Posted: Sat Apr 11, 2009 4:17 pm
by Combuster
use .intel_syntax noprefix otherwise you will still have to add %s before register names.

right now its thinking that dx and ax are variables in memory.

Re: GNU AS using .intel_syntax inline?

Posted: Sat Apr 11, 2009 4:59 pm
by Jimmio92
Actually, it's defined as intel syntax everything from commandline... but I'll fool with it some more...

Re: GNU AS using .intel_syntax inline?

Posted: Sat Apr 11, 2009 6:52 pm
by Jimmio92
I've found what the issue is. Everything works perfect except passing in variables... and it's the one thing I really need.

Re: GNU AS using .intel_syntax inline?

Posted: Mon Apr 13, 2009 5:38 pm
by Jimmio92
I've got it. It actually works too.

1. Put -masm=intel at the command line
2. Put the code into your source file (in the weird way shown below)

Code: Select all

//In my common.h file
static inline void outb(u16 port,u8 value)
{
	//asm(".intel_syntax noprefix");
	asm volatile("mov dx,%0"::"dN"(port));
	asm volatile("mov al,%0"::"a"(value));
	asm volatile("out dx,al");
	//asm(".att_syntax noprefix");
}
static inline u8 inb(u16 port)
{
	u8 ret=0;
	asm volatile("mov dx,%0"::"dN"(port));
	asm volatile("in al,dx");
	asm volatile("mov %0,al":"=a"(ret));
	return ret;
}
static inline u16 inw(u16 port)
{
	u16 ret=0;
	asm volatile("mov dx,%0"::"dN"(port));
	asm volatile("in ax,dx");
	asm volatile("mov %0,ax":"=a"(ret));
	return ret;
}
3. Enjoy the working code! :D

Re: GNU AS using .intel_syntax inline?

Posted: Mon Apr 13, 2009 9:20 pm
by frank

Code: Select all

void outb( DWORD port, BYTE value )
{
    asm volatile( "out dx, al" : : "a" ( value ), "d" ( port ) );

}

Code: Select all

BYTE inb( DWORD port )
{
    BYTE result;

    asm volatile( "in al, dx" : "=a" ( result ) : "d" ( port ) );

    return( result );

} // end inb
Also works well and allows GCC to optimize the loads into the registers itself. You may want to take a look at http://www.ibiblio.org/gferg/ldp/GCC-In ... TO.html#s5