Structure offsets in GCC inline assembly for the i386
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Structure offsets in GCC inline assembly for the i386




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Structure offsets in GCC inline assembly for the i386  
KJK::Hyperion


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:14 PM

Not strictly an UNIX question, but: how do I specify a structure member
offset in inline assembly? let's say I have a CONTEXT * loaded in EAX,
and I need to move its Eip field into ECX. So far I've come up with:

__asm__("mov %0(%%eax), %%ecx" "\n" : : "o"(offsetof(CONTEXT, Eip)) );

but this creates a variable with a value of offsetof(CONTEXT, Eip) and
tries to read into ECX from an offset of EAX from it (???). Using the
"i" constraint I get a syntax error, because instead of an offset I get
an immediate. How should I do?

While we're on topic, how do I jump to a C label or load its address? I
keep getting variables containing the offsets instead of true offsets

Thanks in advance





[ Post a follow-up to this message ]



    Re: Structure offsets in GCC inline assembly for the i386  
Valentin Nechayev


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:15 PM

>>> KJK::Hyperion wrote:

KH> Not strictly an UNIX question, but: how do I specify a structure member
KH> offset in inline assembly? let's say I have a CONTEXT * loaded in EAX,
KH> and I need to move its Eip field into ECX. So far I've come up with:
KH> __asm__("mov %0(%%eax), %%ecx" "\n" : : "o"(offsetof(CONTEXT, Eip)) );
KH> but this creates a variable with a value of offsetof(CONTEXT, Eip) and
KH> tries to read into ECX from an offset of EAX from it (???).

You can load offset to yet another register and sum base pointer and
offset. This isn't optimized, but is working.
But, all examples I've seen keeps offset values in assembler code as constan
t
calculated manually or using separate preprocessing phase.

KH> While we're on topic, how do I jump to a C label or load its address? I
KH> keep getting variables containing the offsets instead of true offsets

It's better to think you can't.
But if using only i386 + gcc + GNU binutils, the following will work:
asm("...; jc j2");
...
asm("j2:");


-netch-





[ Post a follow-up to this message ]



    Re: Structure offsets in GCC inline assembly for the i386  
KJK::Hyperion


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:18 PM

> You can load offset to yet another register and sum base pointer and
quote:
> offset. This isn't optimized, but is working. > But, all examples I've seen keeps offset values in assembler code as > constant calculated manually or using separate preprocessing phase.
blech. Anyway, the problem is that the code I'm porting uses offsets to access local variables (I doubt we can use C variables, but I can ask), so I really can neither hardcode offsets nor use an offset register, because most offsets aren't offsetof(), but sums of several constants
quote:
> It's better to think you can't.
it's that I can't use scope-sensitive labels (__label__) in ASM, and I'd like to. If it isn't possible, we'll just give up nesting, anyway




[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:25 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register