www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - in-line assembly register usage

↑ ↓ ← Scott Michel <scottm aero.org> writes:
How does one go about writing inline assembly and inform the compiler 
about which registers are being used? To be more concrete about things, 
I hate using a third variable to swap two pointers -- I know about the 
XOR hack (it's my favorite programmer's test.) x86 has the xchg 
instruction, which is perfect for the job. With GCC, I can tell the 
compiler about the operands to xchgc: one has to be memory, the other 
register, the register is an output.

How would I go about writing this code, bearing in mind that this might 
appear in the middle of a statement sequence (how do I tell DMC what 
registers I intend to use)? Or is this just not possible?


-scooter
Oct 12 2004
↑ ↓ → "Walter" <newshound digitalmars.com> writes:
"Scott Michel" <scottm aero.org> wrote in message
news:ckhlr0$1kqg$1 digitaldaemon.com...
 How does one go about writing inline assembly and inform the compiler
 about which registers are being used? To be more concrete about things,
 I hate using a third variable to swap two pointers -- I know about the
 XOR hack (it's my favorite programmer's test.) x86 has the xchg
 instruction, which is perfect for the job. With GCC, I can tell the
 compiler about the operands to xchgc: one has to be memory, the other
 register, the register is an output.

 How would I go about writing this code, bearing in mind that this might
 appear in the middle of a statement sequence (how do I tell DMC what
 registers I intend to use)? Or is this just not possible?

You don't need to tell it. DMC's inline assembler can figure it out from the instructions. It's a lot easier to use than GCC's.
Oct 13 2004