From: "Lars O. Hansen" Newsgroups: comp.os.msdos.djgpp Subject: Re: inline assembly syntax for accessing variables ? Date: Fri, 20 Dec 2002 23:16:59 +0100 Organization: 1&1 Internet AG Lines: 72 Message-ID: References: <200212192236 DOT gBJMav017047 AT envy DOT delorie DOT com> NNTP-Posting-Host: p50838309.dip0.t-ipconnect.de X-Trace: news.online.de 1040422619 12154 80.131.131.9 (20 Dec 2002 22:16:59 GMT) X-Complaints-To: abuse AT online DOT de NNTP-Posting-Date: 20 Dec 2002 22:16:59 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > For XCHG, both variables would be listed in the output section, and > the input section would have two numeric constraints. Or something > like that. You end up with four things listed in the constraints, two > of which are references to the other two. asm("XCHG %2,%3" : "=r" (localy2), "=r" (localy1) : "0" (localy2), "1" (localy1)); as in #include "stdio.h" int main() { int localy1=5,localy2=4; asm("XCHG %2,%3" : "=r" (localy2), "=r" (localy1) : "0" (localy2), "1" (localy1)); printf("%d %d",localy1,localy2); } works. http://212.247.200.167/asm/asm_deformed_us/documentation/gccasmtut.txt is also helpful. But I didn't really understand what the principle of gcc extended asm syntax on using constraints is (I would have exchanged "0" and "1" or omitted the "input registers" entirely). Anyway, one now can use #include "stdio.h" inline void swap(int *x, int *y) { asm("XCHG %2,%3" : "=r" (*y), "=r" (*x) : "0" (*y), "1" (*x)); } inline void exchange(int *x, int *y) { asm("XCHG %2,%3" : "=r" (*y), "=r" (*x) : "0" (*y), "1" (*x)); } int main() { int localy1=5,localy2=4; swap(&localy1,&localy2); printf("%d %d",localy1,localy2); exchange(&localy1,&localy2); printf("%d %d",localy1,localy2); } did I want to complain about how inlining of functions id perfomed? Yes, but ah... link: http://www.computing.net/programming/wwwboard/forum/4268.html title: swap without temporary variable.