www.digitalmars.com         C & C++   DMDScript  

c++ - in-line assembly register usage

reply 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
parent "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