Skip to main content
GameDev.net gamedev.net
🔒 Locked

Inline assembler inside a member function.

Started by farmersckn Sep 28, 2000 at 4:35 PM 7 replies 200+ views
Original Post
farmersckn
farmersckn
I''ve tried to use the inline assembler in the member function of a class, but unless i make a local variable and set it to the value of the member it is an alias of, i can''t use members of classes in the inline assembler. Does anyone know how to get access using the inline assembler? I''ve already thought about using globals and using them as aliases for the members, but that will require a little bit of a speed decrease every time i call the methods. etc. etc. plz help. thanks Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Jumpster
Jumpster
Here''s the code to my Normalize() method...


    
class pt
{
double x;
double y;
double z;

void Normalize();
}

void pt::Normalize ()
{
double l = Length ();
if (l > 0.0) // can never be negative

{
//**************************************************

// In essence, this is what we are doing...
// The assembly makes the math faster, about 30%
// x = x*l;

// y = y*l;

// z = z*l;

l = 1.0 / l;
_asm
{
// x = x * l;

mov eax, dword ptr [this]
fld qword ptr [eax]
fmul qword ptr [l]
fstp qword ptr [eax]

// y = y * l;

fld qword ptr [eax+8]
fmul qword ptr [l]
fstp qword ptr [eax+8]

// z = z * l;

fld qword ptr [eax+16]
fmul qword ptr [l]
fstp qword ptr [eax+16]
}
}
else
{
Clear ();
}
}



Regards,
Jumpster




Semper Fi
Regards,JumpsterSemper Fi
farmersckn
farmersckn
I think i got it. Thanks a lot!
farmersckn

Yesterday is the past, tomorrow is the future. Today is a gift, that is why
we call it the present.
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Prosper/LOADED
Prosper/LOADED
Notice that it can be tricky. With inheritance, classe''s data can sometimes begin after the ''this'' pointer. It depends on the compiler i think.

I''m not sur thought...
Shannon Barber
Shannon Barber
Can''t you replace this with x?
eax+8 with y?
eax+16 with z?
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
davepermen
davepermen
ive tried your source with the _asm insert. it compiles fine, but when i try to start it, there is a messagebox from vc++, "programm could not be executed"...
what should i do?!

(im asking here because i know you made it yet)

we wanna play, not watch the pictures

If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
Jumpster
Jumpster
davepermen - Don't forget, you still need a main()/winmain() function. Without it, the program won't start...

Also, don't forget a Length() and Clear() method. Normalize() uses both.


pt::Clear() {x=y=z=0.0;}
pt::Length() {return sqrt(x*x+y*y+z*z); }


BTW - That's not originally even my code. I got it from Mickey Kowacks book.


Regards,
Jumpster





Semper Fi

Edited by - Jumpster on October 2, 2000 9:58:47 AM
Regards,JumpsterSemper Fi
davepermen
davepermen
it was none of your tips, im sorry.. it was my fault

trick was, i changed the folder for the exe, so that it wasnt in the release-folder anymore, but let vc++ executeing it from the release-folder anyway... ...i was so stupid..

we wanna play, not watch the pictures

If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
Serge K
Serge K
quote:
Original post by farmersckn

I''ve tried to use the inline assembler in the member function of a class, but unless i make a local variable and set it to the value of the member it is an alias of, i can''t use members of classes in the inline assembler. Does anyone know how to get access using the inline assembler?



    

class SomeClass
{
int m_SomeMemberVariable;

int InlineFunction( int x )
{
// inline functions does not receive "this" in ECX

__asm mov edx, this
__asm mov eax, x
__asm add eax, [edx]this.m_SomeMemberVariable
}
};

int SomeClass::RegularFunction( int x )
{
__asm mov eax, x
// ECX already contains "this"

__asm add eax, [ecx]this.m_SomeMemberVariable
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.