Jump to content
  • Advertisement
Sign in to follow this  
dawidjoubert

Inline asm

This topic is 4474 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 could someone please help me set up the functions so that it works
void putHorizLine(int x1,int x2,int y2,int color)
{ 
	int lineoffset = y2 * (g_cscreen->pitch >> 2;
	asm
	{
		mov     ax, [g_puiScreen]  // move segment of Where to AX
		mov     es, ax       // set ES to segment of Where
		mov     di, [lineoffset]	 // set di to Y offset
		add     di, [x1]     // add the X1 offset to DI
		mov     al, [color]  // move Col to AL
		mov     ah, al       // move Col to AH (we want 2 copies for word moving)
		mov     cx, [x2]     // move X2 to CX
		sub     cx, [x1]     // move the change in X to CX
		shr     cx, 1        // divide change in X by 2 (for word moving)
		jnc     Start        // if we have an even number of moves, go to Start
		stosb                // otherwise, move one byte more
	}


	Start: asm 
	{
		rep     stosw        // do it!
	}
}

Share this post


Link to post
Share on other sites
Advertisement
Are you getting compile errors? If not, use a debugger to go through the code and see what happens.
Suggestion: Unless you have a good reason to use 16-bit assembly, start using 32/64-bit assembly.

Share this post


Link to post
Share on other sites
Quote:
Original post by vNistelrooy
Are you getting compile errors? If not, use a debugger to go through the code and see what happens.
Suggestion: Unless you have a good reason to use 16-bit assembly, start using 32/64-bit assembly.


Oh so that is 16bit asm? Okay so how can i make it 32bit, that is probably why it won't compile under a win32 project

Share this post


Link to post
Share on other sites
Quote:
Original post by RDragon1
Nope


Well actually i want to learn asm, so you going to help me..

Here is the compile output in c++:
error C2065: 'ASM' : undeclared identifier
error C2143: syntax error : missing ';' before '{'
error C2065: 'mov' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'ax'
error C2065: 'ax' : undeclared identifier
error C2059: syntax error : '['
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2065: 'rep' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'stosw'
error C2065: 'stosw' : undeclared identifier
error C2143: syntax error : missing ';' before '}'

Share this post


Link to post
Share on other sites
Quote:
Original post by RDragon1
Nope


How about being useful!

Umm the asm keyword is actually:

__asm
{}

Hope that helps,

Dave

Share this post


Link to post
Share on other sites
If you want speed then you won't be losing much, if any, by using C in place. Even C++ won't slow it down noticably. If you weight up the time taken to solve this problem to the speed of the program, i think you'll find C++ perfectly fine.

dave

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!