I've been using the basics of MASM for some time now, so I have started to try and optimize some of my C++ routines.
My question is, say for example you are using a D3DXVECTOR3 from the DirectX library. The structure contains three floats x,y,z, and is stored on the stack. How can I access those floating point values in asm code. I realize that I will have to use the FPU, but it doesn't necessarily have to be floating points.
Say I have an INT_POINT with an int x, and int y value that can be accessed.
INT_POINT temp;
temp.x = 5;
temp.y = 7;
Now say I have a structure or object passed by reference can I access them the same way?
void fill(INT_POINT &temp)
{
temp.x = 5;
temp.y = 7;
}
I'd like to take and convert similar functions to assembly but the only way I have been successful is to do this.
void fill(INT_POINT &temp)
{
int tempX;
int tempY;
_asm
{
mov eax, 5
mov tempX, eax
mov eax, 7
mov tempY, eax
}
temp.x = tempX;
temp.y = tempY;
}
As you can see this is no way optimized, because I am copying the value to a temp location before using C++ again to store it where is should be put to begin with.
I'd really appreciate any help I can get on this, and if I'm not being clear enough just let me know.
Thanks in advance
Adam
http://adamwlarson.com
adam23,
The guy who knows all about this stuff is Raymond Filiatreault. You can visit his site here (http://www.ray.masmcode.com/).
There are nice tutorials, etc.
Paul
you might also just view this sample, works with VC:
typedef struct {
int x;
int y;
} POINT;
int fill(POINT& temp)
{
_asm {
mov edx,temp
mov (POINT [edx]).x,5
mov (POINT [edx]).y,6
}
return 0;
}
int main()
{
POINT p1;
fill (p1);
return 0;
}
That looks pretty easy, but I ran into a little problem trying to do it. It does get me going in the right direction though.
Say that I want to do this inside of a class,
I have a class Vector3 defined with a simple Test function to try and fill with values.
void Vector3::Test()
{
_asm
{
mov edx, this
mov (Vector3 [edx]).x, 5
mov (Vector3 [edx]).y, 7
}
}
I get these errors
error C2420: 'Vector3' : illegal symbol in first operand
Thanks again for the help
Man do I feel stupid
It was really simple
void Vector3::Test()
{
_asm
{
mov edx, this
mov ([edx]).x, 5
mov ([edx]).y, 7
}
}