3
인라인 어셈블리를 사용하여 구조체 멤버를로드하려고합니다 (Particle
은 이러한 구조체에 대한 포인터 임). 정크인라인 어셈블리에서 구조 멤버에 액세스 하시겠습니까?
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
, gas
취급 (%eax)
후 : GCC는 다음과 같이 즉시 숫자 리터럴 이러한 오프셋을 출력으로하지만,
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"
);
그것은 작동하지 않습니다 여기 내 초기 솔루션입니다 표현식 :
Error: junk `(%eax)' after expression
출력에서 달러 기호 만 제거 할 수 있으면 작동합니다. 구조 멤버에 액세스하는 방법에 대한 아이디어가 있습니까?
'structs'와'$ '같은 문제는 [GCC 확장 asm, struct element offset encoding] (http://stackoverflow.com/q/13254512)에서 논의됩니다. 이것은 질문의 중복 일지 모르지만 다른 질문은 확장 된 ASM의 컨텍스트에 있기 때문에 확실하지 않습니다. [% CC는 GCC 인라인 어셈블리 코드에서 무엇을 의미합니까?] (http://stackoverflow.com/q/1672900/608639)를 참조하십시오. – jww