Page 1 of 1

c++ portout function

Posted: Tue Jul 15, 2003 7:57 am
by slacker
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));
}

Re:c++ portout function

Posted: Tue Jul 15, 2003 8:00 am
by Tim
Maybe gcc knows. Did you get some kind of error message?

Re:c++ portout function

Posted: Tue Jul 15, 2003 8:18 am
by slacker
invalid asm operand number missing after %-letter

Re:c++ portout function

Posted: Tue Jul 15, 2003 8:43 am
by Pype.Clicker
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));
}

Re:c++ portout function

Posted: Tue Jul 15, 2003 8:47 am
by Solar
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... ;-)

Re:c++ portout function

Posted: Tue Jul 15, 2003 8:49 am
by slacker
k so whenever i have input/output variables i need two % to reference registers?

Re:c++ portout function

Posted: Tue Jul 15, 2003 9:12 am
by Solar
That's what the doc and Pype said.