From: Endlisnis Newsgroups: comp.os.msdos.djgpp Subject: Bug in GCC? Date: Sun, 06 Sep 1998 11:06:00 -0300 Organization: NBTel Internet Lines: 62 Message-ID: <35F296C8.EE7B49C7@unb.ca> NNTP-Posting-Host: fctnts05c94.nbnet.nb.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk The program doesn't compile as I would expect. All it was spose to do is show how you could use inline asm to add 2 integers. But, the return value was always 4. So I looked at the asm code generated for the function, it reads from port 0x83 and does some loops and stuff. All I wanted was 1 add. And the debugger (when the asm window is open) can't debug it right. It skips lines and weird things happen, registers change values without any obvious reason. Note: Moving the function after the main makes GCC compile it as expected. I am using DJGPP v2.8.1 from RHIDE with "-Wall" and "-g" on, nothing else. Also, I've tried compiling it on a different machine with the same results. -----------Code--------------- #include int add(int a, int b) { int Ret; asm ("addl %1, %0" : "=r" (Ret) : "0" (a), "r" (b) ); return Ret; } int main() { int a=2,b=4; cout << add(a,b); return 0; } --------Asm for add(int,int)----------- pushl %ebp inl $0x83,%eax //Why is it reading from a port? inb (%dx),%al //And here? pushl %ebx decl %ebp popl %ebp orb $0x1,%al //Oring al with 1?? leave decl %ebp cld pushl %ebp cld movl %edx,%eax jmp add__Fii+28 jbe add__Fii+28 popl %ebp clc leave ret jbe main -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT GeoCities DOT com Endlis AT nbnet DOT nb DOT ca