From: Pål-Kristian Engstad Newsgroups: comp.os.msdos.djgpp Subject: Re: Optimization and Inline ASM Date: Mon, 07 Oct 1996 18:31:50 +0100 Organization: Funcom Oslo AS Lines: 57 Message-ID: <32593E86.377@funcom.com> References: <199610042155 DOT VAA24760 AT gauss DOT logicnet DOT com DOT mx> Reply-To: engstad AT funcom DOT com NNTP-Posting-Host: khazad.funcom.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp YOMERO SOFTWARE LTD. wrote: > >The code giving me the problem is: > > > >void myproc() > >{ > > __asm__ __volatile__(" > > cli\n > > movw $0x3DA, %dx\n > >loc1:\n > > inb %dx, %al\n > > andb $8, %al\n > > jnz loc1\n > >loc2:\n > > inb %dx, %al\n > > andb $8, %al\n > > jz loc2\n"); > >} > > > >What am I doing wrong? Help me, or I'll be bold soon! This error has driven > >me NUTS!!! > Farhan: [--snip--] > That's the way I did it, hope it works for you too! let me know about. > > Yomero. You are both wrong. With optimization, the compiler is free to put myproc() inlined in other functions, thereby causing several loc1 and loc2 labels in the assembly file. The solution is to use GCC's unnamed labels: void myproc() { __asm__ __volatile__( "\tcli\n\t" "movw $0x3da, %dx\n" "1:\t" "inb %dx, %al\n\t" "andb $8, %al\n\t" "jnz 1b\n" "1:\t" "inb %dx, %al\n\t" "andb $8, %al\n\t" "jz 1b\n"); } The point is that numbered labels can be repeated. When using them, you will specify '1b' to get _back_ to the previous label 1, and '1f' to get _forward_ to the next label 1. Another thing though. Those assembly statements is unnescessary, as GCC compiles the equivalent C code just as well as you can do. PKE. -- Pål-Kristian Engstad, Funcom Oslo AS, http://www.funcom.com/~engstad mailto:engstad AT funcom DOT com, +47 22 42 01 02.