Hello all,

Ive posted more over the last few days on this site then I ever have.

I am trying to implement some routines with inline assembly from managed c++ (vs 2008 express), I am trying to pass pointers to the first element in the array to the assembly code, but it is not recieving the correct addresses. What I have so far:

Code:
MiniBI^ operator+(MiniBI^ _val1, MiniBI^ _val2){

     MiniBI^ _retval=gcnew MiniBI();

     pin_ptr<int> _v1 = &_val1->_numa[0];
     pin_ptr<int> _v2 = &_val2->_numa[0];
     pin_ptr<int> _tempadd= &_retval->_numa[0];

     MyBase::Add(_v1,_v2, _tempadd, _val1->_numa->Length, _val2->_numa->Length, _retval->_numa->Length);

     return _retval;

}
So the code above is supposed to pin all the variables and return a pointer to the first element in the array, then it calls the assembly code passing the pointers, as well as the lengths of the arrays.

Code:
#pragma managed(push,off)

	void MyBase::Add(int* _val1offset, int* _val2offset, int* _retval, int _val1size, int _val2size, int _retvalsize){

		short count=0;
		short car=0;

		__asm{

				push		ecx
				push		edi
				push		esi
				xor			edi,edi
				xor			ecx,ecx

Add1:

				xor			eax,eax
				mov			ax,car
				mov			car,0h
				add			eax, dword ptr [_val1offset+edi*4]
				add			eax, dword ptr [_val2offset+edi*4]
				jnc			NoCarry
				mov			car, 01h
NoCarry:
				mov			dword ptr [_retval+edi*4],eax
				inc			edi
				cmp			edi,_val1size
				jle			Add1
				xor			eax,eax
				mov			ax,car
				mov			dword ptr [_retval+edi*4],eax
				pop			esi
				pop			edi
				pop			ecx
				ret


		}

		//return _retval;

	}

#pragma managed(pop)
and then is supposed to show up here. The algorithm appears to work correctly, except the values that show up for:

add eax, dword ptr [_val1offset+edi*4]
add eax, dword ptr [_val2offset+edi*4]

are not the values that were in the arrays in the calling routine, in fact, most of the time the assembly code errors out with an accessviolation error (Im assumiing because it is not hitting the arrays), also, Ive noticed that the _val1size variable almost allways (maybe allways) changes on the first pass through the algorithm, but it does start out with the correct value.

I am not a solid assembly (or native c++) programmer so you wouldnt hurt my feelings at all if you pointed out other problems with the alg.

Thanks