Mail Archives: djgpp/2001/02/08/14:10:29
----- Original Message -----
From: "Nate Eldredge" <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Sent: Saturday, February 03, 2001 1:48 AM
Subject: Re: inline assembly and c struct
> "clusty" <clusty AT poland DOT com> writes:
>
> > I want compiler to print y_offset in my piece of inline assembly code.
> > In above example i will get y_offset in variable and i.e instead of writing
> >
> > asm(...
> > mov <y_offset>(%%eax),%%edx
> > ...)
> >
> > I would have to write
> >
> > asm(...
> > mov _y_offset,%%eax
> > mov <y_offset>(%%eax),%%edx
> > ...)
> >
> > see the difference
> >
> > i tried something like this
> >
> > asm(...
> > "%0(%%eax),%%edx \n"
> > ...
> > ::"m"(*(&some_struct.member-&some_struct)) /*this thing gives*/
> > /*variable at offset of*/
> > /*offset of member */
> > );
> > but it won't work
>
> I think what you want is (untested)
>
> asm("movl %0(%%eax),%%edx"
> :: "i" (offsetof(some_struct, member))
> );
>
> The "i" constraint specifies that this operand is an immediate value,
> and hence will be inserted as a constant.
>
> Note that you should always use the standard `offsetof' macro instead
> of trying to calculate the offseet yourself.
>
ok but i wont be able to do that
> > "%0(%%eax),%%edx \n"
because the constraint will be "i".
The constraint must be "m" or "o" in order to above line to compile.
- Raw text -