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.
slacker
Post
by slacker » Tue Jul 15, 2003 7:57 am
anyone know what is wrong with this function?
Code: Select all
void Port_Out(char data, short port)
{
asm("outb %al, %dx"::"d"(port), "a"(data));
}
Tim
Post
by Tim » Tue Jul 15, 2003 8:00 am
Maybe gcc knows. Did you get some kind of error message?
slacker
Post
by slacker » Tue Jul 15, 2003 8:18 am
invalid asm operand number missing after %-letter
Pype.Clicker
Member
Posts: 5964 Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:
Post
by Pype.Clicker » Tue Jul 15, 2003 8:43 am
you must double the % sign!
GCC uses %* as a parameter reference (for instance %0 is the first parameter of the asm command). registers must have the form %%eax ...
You could do
Code: Select all
void Port_Out(char data, short port)
{
asm("outb %1, %0"::"d"(port), "a"(data));
}
or
Code: Select all
void Port_Out(char data, short port)
{
asm("outb %%al, %%dx"::"d"(port), "a"(data));
}
Solar
Member
Posts: 7615 Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:
Post
by Solar » Tue Jul 15, 2003 8:47 am
Google search for "inline asm", link #8 "DJGPP FAQ - Inline Assembly code with GCC", suggests
info gcc "C Extensions" "Extended Asm"
At about 34% of the file, it reads:
If you refer to a particular hardware register...
That paragraph will probably help you. (No time to try things myself.)
Heh, Pype beat me to it...
Every good solution is obvious once you've found it.
slacker
Post
by slacker » Tue Jul 15, 2003 8:49 am
k so whenever i have input/output variables i need two % to reference registers?
Solar
Member
Posts: 7615 Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:
Post
by Solar » Tue Jul 15, 2003 9:12 am
That's what the doc and Pype said.
Every good solution is obvious once you've found it.