Jump to content
  • Advertisement
Sign in to follow this  
dawidjoubert

quick asm question

This topic is 4618 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

Hi, me again! Okay please not the following code is working correctly, the problem is i don't understand why! I will highlight the block i think is incorrect
	unsigned int offset = (y2 * g_iScreenMultiple);
	unsigned int *start = (g_puiScreen) + offset +x1; 
	{
		__asm
		{
		mov ecx, x2			// Set ecx to x2
		sub ecx, x1			// subtract x1 from ecx
		jna end			// (if x2-x1 is negative)

		mov edi, start		// Get address of buffer
		mov ebx, color		// Set ebx to color

		
		drawloop:			// While (ecx > 0) ecx--;
			mov [edi], ebx		//set memorylocation to pixel color
			add edi,4
			//inc edi				//Increase the xposition	
		loop drawloop //loop until ecx is zero
end:
		}
	}
Okay now according to some online material js is the correct jump funciton to be used, js is a conditional jump that happends if the sign flag is set. The sign flag will be set if at sub ecx,x1 (ecx < x1 which means the new ecx should be a negative value). Now can someone please explain why jna (jump if not above) works and js doesnt!

Share this post


Link to post
Share on other sites
Advertisement
jna tests the carry flag, rather than the sign flag. That is, it tests whether the top bit of the subtraction required a borrow, which it will if (in your case) x1 > ecx.

Using js does not work - an example is ecx = 0, x1 = 0xffffffff. Clearly this should cause a jump, but the resulting ecx will be 0x00000001 due to truncation, and hence js will not jump.

Share this post


Link to post
Share on other sites
Quote:
Original post by bakery2k1
jna tests the carry flag, rather than the sign flag. That is, it tests whether the top bit of the subtraction required a borrow, which it will if (in your case) x1 > ecx.

Using js does not work - an example is ecx = 0, x1 = 0xffffffff. Clearly this should cause a jump, but the resulting ecx will be 0x00000001 due to truncation, and hence js will not jump.


mm I love this guy, he is such an asm guru!!

Thanks.. For what it is worth.. ratings!

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!