To: djgpp AT delorie DOT com Subject: Re: Inline Asm? Message-ID: <19970106.200214.4975.4.chambersb@juno.com> References: <19961231 DOT 204032 DOT 5015 DOT 0 DOT chambersb AT juno DOT com> <5as4du$jd6 AT mack DOT rt66 DOT com> From: chambersb AT juno DOT com (Benjamin D Chambers) Date: Mon, 06 Jan 1997 22:56:41 EST On 6 Jan 1997 17:12:46 -0700 brennan AT mack DOT rt66 DOT com (Brennan "The Rev. Bas" Underwood) writes: >In article <19961231 DOT 204032 DOT 5015 DOT 0 DOT chambersb AT juno DOT com>, >Benjamin D Chambers wrote: >>Well, I spent some time stepping through my program with GDB, and >found >>that the following lines caused problems: >> >>cmpl $0, %%edx (This is, of course, in the c file) >>jne 0 >> >>Now, to me, this means that if edx is not zero, jump to the label 0 >>(which was defined earlier) and, if edx is zero, keep executing as >>normal. However, when I stepped through this with GDB, I found that >no >>matter what value edx held, the loop fell through (that is, no jump >was >>performed). Am I doing something wrong here? Again, thanx in >advance... > >Tell you what, just use jnz as below... (JNZ = jump if not zero) > >> asm("0: \n >> movb $1, (,%%eax,1) \n >> incl %%eax \n >> decl %%edx \n > jnz 0b \n >> " >> : // No Output >> : "d" (size), >> "a" (data) >> : "memory", "%cc" >> ); > >Also, the decl and jnz will pair into 1 cycle on the Pentium. >And, I put a 'b' on the '0', to make 0 into a local label in case of >loop unrolling. > I think I figured this out... The 0 was treated as an offset, rather than a label. (I had tried jnz originally, then changed it to the more readable jne). When jne 0 was used, it always jumped 0 bytes ahead - with the no effect I was observing. When I used labels like LoopTop or LOOP or something, it jumped to the label correctly. Perhaps this tidbit should be placed in the FAQ - it certainly can be confusing :) ...Chambers