Mail Archives: djgpp/1997/02/02/19:43:35
In article <32F1A438 DOT 5509 AT rangenet DOT com>,
Dan Hedlund <markiv AT rangenet DOT com> wrote:
>The following lines compile wrong with the -O3 option.
>
>unsigned char inportb (int port)
>{
> unsigned char c;
> asm ("inb %%dx, %%al"
> : "=a" (c)
> : "d" (port));
> return c;
>}
>
>void main (void)
>{
> while (inportb (0));
>}
>
>GCC reads a byte from port 0 only once, and then compars that byte to 0
>in an endless loop. Apparently GCC thinks the byte retrieved from the
>port doesn't change.
You need a 'volatile' on that asm there. i.e.
extern __inline__ unsigned char
inportb (unsigned short _port)
{
unsigned char rv;
__asm__ __volatile__ ("inb %1, %0"
: "=a" (rv)
: "d" (_port));
return rv;
}
That's from pc.h. Just #include <pc.h> and it'll be correctly handled.
Brennan
--
brennan AT rt66 DOT com | Ding-a-ding-dang my dang-a-long-ling-long.
Riomhchlaraitheoir|
Rasterfarian | <http://brennan.home.ml.org> -O
- Raw text -