Reputation: 715
I have several struct/unions, for example:
union
{
uint8_t X;
struct __attribute__((packed, aligned(1)))
{
uint8_t A : 1;
uint8_t B : 1;
uint8_t C : 1;
uint8_t D : 1;
uint8_t E : 1;
uint8_t F : 1;
uint8_t G : 1;
uint8_t H : 1;
};
}DATA;
I need to access their elements in in-line assembly, for example:
asm volatile
(
"\
mov %1, %%eax \t\n\
inc %%eax \t\n\
mov $0, %0 \t\n\
"
:"=d"(u->X)
:"d"(temp)
);
Application segfaults at the last line.
mov (%rdx),%eax
inc %eax
mov $0x0,%dl
mov %dl,0x1(%rax)
I tried to create a mirror pointer and access struct via it but it doesn't had an effect, just no segfault. So I use temp variable. Is it possible at all or I try to do a weird things?
Upvotes: 1
Views: 555
Reputation: 3675
Inline assembly must not alter registers which are not listed as outputs or in the clobber list.
In your example the compiler has chosen to store u
in RAX, which is altered by your code. EAX is the lower half of RAX.
Upvotes: 2