Access 'this' in inline assembly

Simon s.d.hammett at gmail.com
Mon Mar 7 10:17:04 PST 2011


On 07/03/2011 15:14, Martin Kinkelin wrote:
> Hi, sorry for the dumb question, but how do i get the address of an object
> inside a member function in inline assembly?
>
> I have no experience with assembler yet. It seems like names of variables on
> the stack are treated as pointers in inline assembly, but I have no clue about
> how to get the address of the object itself (this and [this] do not work).
>
> struct float4
> {
>      float[4] _data;
>
>      float dot(in float4 rhs) const
>      {
>          float r = void;
>          asm
>          {
>              movups XMM0, this; // need pointer to _data
>              movups XMM1, rhs;
>              ...
>              movss r, XMM0;
>          }
>          return r;
>      }
> }
>
> Please note that even this doesn't work:
> float* ptr = cast(float*) _data.ptr;
> asm { movups XMM0, ptr; }
> =>  2 operands found for movups instead of the expected 1

'this' is passed in EAX:

See the bit titled 'parameters'

http://www.digitalmars.com/d/2.0/abi.html

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list