I'm trying to use inline assembly to load a bunch of structure members (Particle
is a pointer to such structure) into some registers. Here's my initial solution:
asm("mov %1(%0), %%edx\n"
"fld %2(%0)\n"
"fld %3(%0)\n"
"fld %4(%0)\n"
"fld %5(%0)\n"
"movups %6(%0), %%xmm1\n"
"movups %7(%0), %%xmm2\n"
"movups %8(%0), %%xmm3\n"
"movups %9(%0), %%xmm4\n"
:
: "r" (Particle),
"n" (offsetof(ptcParticle, Active)),
"n" (offsetof(ptcParticle, Size)),
"n" (offsetof(ptcParticle, Rotation)),
"n" (offsetof(ptcParticle, Time)),
"n" (offsetof(ptcParticle, TimeScale)),
"n" (offsetof(ptcParticle, Colour)),
"n" (offsetof(ptcParticle, Location)),
"n" (offsetof(ptcParticle, Velocity)),
"n" (offsetof(ptcParticle, Accel))
: "%edx", "%st", "%st(1)", "%st(2)", "%st(3)", "%xmm1", "%xmm2",
"%xmm3", "%xmm4"
);
It doesn't work, though, as GCC outputs these offsets as immediate number literals, like this:
mov $0(%eax), %edx
fld $44(%eax)
fld $40(%eax)
fld $8(%eax)
fld $4(%eax)
movups $12(%eax), %xmm1
movups $28(%eax), %xmm2
movups $48(%eax), %xmm3
movups $60(%eax), %xmm4
As a result, gas
treats (%eax)
as junk after expression:
Error: junk `(%eax)' after expression
This would work if I could only get rid of the dollar sign in the output. Any idea how to access structure members?