From mboxrd@z Thu Jan 1 00:00:00 1970 From: martin.kahlert@keksy.mchp.siemens.de (Martin Kahlert) To: help-gcc@gnu.org Subject: Re: Assembler in C under Linux Date: Fri, 31 Dec 1999 22:24:00 -0000 Message-ID: <828qs3$akc$1@news.mch.sbs.de> References: X-SW-Source: 1999-12n/msg00066.html Message-ID: <19991231222400.Eps8LSIfYeiZDKQwk-Ozhd-Q0wHoZg4d_v6Vdml4Eew@z> [Posted and mailed] In article < slrn84dhpn.ihf.mperrin@hcs.harvard.edu >, mperrin@hcs.harvard.edu (Marshall Perrin) writes: > I'm trying to port a driver for a digital signal processor card from > DOS to Linux. The DOS driver, developed by someone not me ;-), is > mostly C but has a fair amount of inline assembler. For Borland C for > DOS, this was pretty easy to do. Just > asm { > mov dx, DSP_BaseIO > add dx, reg_offset > } > etc etc. > > Gcc of course chokes on the above. I've attempted to read through the gcc > documentation and figure out how to do this, but no luck. That led me > towards something like > > asm("mov dx, %0" : : "d" (DSP32C_BaseIo)); > asm("add dx, %0" : : "d" (reg_offset)); > asm("in ax,dx"); > asm("mov %0,ax" :"=d" (value) : ); The (hopefully) correct syntax for these lines would be something like: #include int main(int argc,const char *argv[]) { short int DSP32C_BaseIo=18,reg_offset=15,value; asm("inw %1, %0" : "=r" (value) : "r" (DSP32C_BaseIo+reg_offset)); printf("value=%d\n",value); return 0; } Then gcc -O -o prog prog.c ^^^ important! This prog doesn't work! In LINUX you can't directly access the hardware. Write a driver, or write a setuid root program. All the stuff the asm does could be done easily and much more portable in C. For that read http://www.linuxdoc.org/HOWTO/mini/IO-Port-Programming.html first. Hope that helps, Martin.