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

seemingly random changes to the this pointer [asm]

Started by exorcist_bob Jul 8, 2006 at 8:26 PM 1 replies 450+ views
Original Post
exorcist_bob
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.

.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
LessBread
LessBread
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
exorcist_bob
exorcist_bob
I should have know. I thought that I was only supposed to not monkey around with ebp/esp. Thanks!

Topic Locked

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

Sign in to reply to this topic.