Sign in to follow this  
dawidjoubert

more asm... Stack corrupted?

Recommended Posts

dawidjoubert    161
hi, i am trying to get this code to work.. please help me
	unsigned int offset = (y2 * g_iScreenMultiple);
	unsigned int *start = (g_puiScreen) + offset +x1;
	
       char col = 50; 
	if 	(x1	<	x2)
	{
		__asm
		{
		lea edi, [start]	// Get address of buffer
		mov al, col			// Set al to color

		mov ecx, x2			// Set ecx to x2
		sub ecx, x1			// subtract x1 from ecx

		
		drawloop:			// While (ecx > 0) ecx--;
			mov [edi], al		//set memorylocation to pixel color
			inc edi				//Increase the xposition	
		loop drawloop //loop until ecx is zero
		}
	}
Here is what the asm is suppose to do
	while (x1	<	x2)
	{
		{
			(*start) = color;
		}
		start++;
		x1++;
	}
It is giving me runtime errors saying stack around start is corrupt Here is the dissamsbler code
if 	((x1	<	x2) && (x1 < g_iWidth))
00411F81  mov         eax,dword ptr [x1] 
00411F84  cmp         eax,dword ptr [x2] 
00411F87  jge         drawloop+5 (411FA5h) 
00411F89  mov         eax,dword ptr [x1] 
00411F8C  cmp         eax,dword ptr [g_iWidth (41A720h)] 
00411F92  jge         drawloop+5 (411FA5h) 
	{
		__asm
		{
		lea edi, [start]	// Get address of buffer
00411F94  lea         edi,[start] 
		mov al, col			// Set al to color
00411F97  mov         al,byte ptr [col] 

		mov ecx, x2			// Set ecx to x2
00411F9A  mov         ecx,dword ptr [x2] 
		sub ecx, x1			// subtract x1 from ecx
00411F9D  sub         ecx,dword ptr [x1] 

		
		drawloop:			// While (ecx > 0) ecx--;
			mov [edi], al		//set memorylocation to pixel color
00411FA0  mov         byte ptr [edi],al 
			inc edi				//Increase the xposition	
00411FA2  inc         edi  
		loop drawloop //loop until ecx is zero
00411FA3  loop        drawloop (411FA0h) 
		}
	}
};
00411FA5  push        edx  
00411FA6  mov         ecx,ebp 
00411FA8  push        eax  
00411FA9  lea         edx,ds:[411FCAh] 
00411FAF  call        @ILT+235(@_RTC_CheckStackVars@8) (4110F0h) 
00411FB4  pop         eax  <---- Line highlighted

Share this post


Link to post
Share on other sites
bakery2k1    712
start holds the address of your buffer, and you want this to be in edi. Therefore, you need:

mov edi, start

rather than:

lea edi, [start] (equivalent to lea edi, start)

which loads the address of _start_ into edi.

Also, this:

drawloop: // While (ecx > 0) ecx--;

mov [edi], al //set memorylocation to pixel color

inc edi //Increase the xposition

loop drawloop //loop until ecx is zero


whilst correct, can be replaced by a simple "rep stosb".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this