delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/02/02/19:56:22

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: inline assembly and c struct
Date: 02 Feb 2001 16:48:25 -0800
Organization: InterWorld Communications
Lines: 45
Sender: nate AT mercury DOT st DOT hmc DOT edu
Message-ID: <83lmro7fs6.fsf@mercury.st.hmc.edu>
References: <957ghs$kl$1 AT news DOT onet DOT pl> <959619$f3k$1 AT murdoch DOT acc DOT Virginia DOT EDU> <95f5mk$cug$1 AT news DOT onet DOT pl>
NNTP-Posting-Host: mercury.st.hmc.edu
Mime-Version: 1.0
X-Trace: nntp1.interworld.net 981161305 24186 134.173.57.219 (3 Feb 2001 00:48:25 GMT)
X-Complaints-To: usenet AT news DOT interworld DOT net
NNTP-Posting-Date: Sat, 3 Feb 2001 00:48:25 +0000 (UTC)
User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.5
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"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.

-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019