Skip to main content
gamedev.net
🔒 Locked

quick asm question

Started by dawidjoubert 1 reply 400+ views
Original Post
dawidjoubert
dawidjoubert
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!
----------------------------http://djoubert.co.uk
bakery2k1
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.
dawidjoubert
dawidjoubert
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!
----------------------------http://djoubert.co.uk

Topic Locked

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

Sign in to reply to this topic.