Jump to content
  • Advertisement
Sign in to follow this  
exorcist_bob

Unity seemingly random changes to the this pointer [asm]

This topic is 4485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, Community I was just porting my inline assembler code for code in MASM, but when I run my program, the 'this' pointer seems to change very eratically.
.686P
.MMX
.XMM
.MODEL FLAT, C

.CODE

Matrix3Add PROC mat1:DWORD, mat2:DWORD, mat3:DWORD
	
	mov eax, dword ptr[mat1]
	mov ebx, dword ptr[mat3]
	mov ecx, dword ptr[mat2]
	movaps xmm0, dword ptr[ecx]
	movaps xmm1, dword ptr[ecx + 10h]
	addps xmm0, dword ptr[eax]
	addps xmm1, dword ptr[eax + 10h]
	movaps [ebx], xmm0
	movaps [ebx + 10h], xmm1
	fld dword ptr [ecx+20h]
	fadd dword ptr [eax+20h]
	fstp dword ptr [ebx+20h]
	mov ecx, dword ptr[mat2]
	ret

Matrix3Add ENDP

END

extern "C" void Matrix3Add( Matrix3* mat1, Matrix3* mat2, Matrix3* mat3 );

inline Matrix3 Matrix3::operator+ ( const Matrix3& mat )
{
	Matrix3 matReturn;

	Matrix3Add((Matrix3*)&mat, this, &matReturn);

	return matReturn; // mat, this and matReturn are still valid
};

inline Matrix3(const Matrix3& mat)
{
	__asm
	{
		mov ecx, 0x9
		mov esi, dword ptr[mat]
		mov edi, this //'this' now points to some random value

		rep movsd
	};
};

Thanks for any help, and thanks for the help in previous posts. It's been great![smile] exorcist_bob

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by exorcist_bob
Hello, Community

I was just porting my inline assembler code for code in MASM, but when I run my program, the 'this' pointer seems to change very eratically.


Don't clobber Ecx.

thiscall

Quote:

...
The convention operates much like __stdcall except that the this pointer (which is effectively a hidden argument) is stored in the ECX register. This neatly matches with the C++ rule that one cannot take the address of the this pointer.
...


This might offer some insights too: Fast Delegate.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!