Skip to main content
GameDev.net gamedev.net
🔒 Locked

Inline asm

Started by dawidjoubert Mar 26, 2006 at 12:53 PM 16 replies 3.5k views
Original Post
dawidjoubert
dawidjoubert
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!
	}
}
----------------------------http://djoubert.co.uk
vNistelrooy
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.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
dawidjoubert
dawidjoubert
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
----------------------------http://djoubert.co.uk
RDragon1
RDragon1
Why are you using assembly at all?
dawidjoubert
dawidjoubert
Quote:
Original post by RDragon1
Why are you using assembly at all?


Speed, is that a valid excuse?
----------------------------http://djoubert.co.uk
dawidjoubert
dawidjoubert
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 '}'
----------------------------http://djoubert.co.uk
dave
dave
Quote:
Original post by RDragon1
Nope


How about being useful!

Umm the asm keyword is actually:

__asm
{}

Hope that helps,

Dave
dave
dave
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
RDragon1
RDragon1
What compiler?

If using VC++8, inline assembly is done using __asm , I believe
RDragon1
RDragon1
Also, you're missing a ) on this line:

int lineoffset = y2 * (g_cscreen->pitch >> 2;
RDragon1
RDragon1
Quote:
Original post by Dave
Quote:
Original post by RDragon1
Nope


How about being useful!



Being useful was trying to not waste hours of this guy's and everyone else's time trying to push him down a road that has no business being travelled. But since he wants to 'learn asm' It's slightly more justified.
dawidjoubert
dawidjoubert
Thanks for all your help!

Oh and thanks RDragon1, i have thought about trying asm for myself for about 4 years.. I finally think i am ready to learn it!
----------------------------http://djoubert.co.uk
dawidjoubert
dawidjoubert
Quote:
Original post by Anonymous Poster
That code looks like an old implementation of 320x200 graphics mode line drawing algorithm, where Whole graphics buffer is contained inside one segment.
Might cause problems when run in W2k/xp os, because it's 16-bit application.
I think you could start learning assembler using some emulator() and doing easier things for start. Or just start with 32-bit inline assembler and let compiler do your variable declarations.


Yes you are correct about the source, but i want to use it in connection with SDL do directly access the screen buffer. Obviously i am not getting anywhere!
----------------------------http://djoubert.co.uk
Spoonbender
Spoonbender
Quote:
Original post by Dave
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


C/C++ will be *a lot* faster than writing in ASM.

It is possible, if you know everything about your target CPU architecture, to write small snippets of ASM that can outperform C/C++ in small isolated sections of the code. But in the general case, a C/C++ compiler will do a *much* better job.
noNchaoTic
noNchaoTic
With compilers that perform optimization, most asm programmers will get outcoded by the compiler anyway... but learning asm is always good to improve understanding of how higher level code is working. Good luck with it :-)
Steven ToveySPUify | Twitter

Topic Locked

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

Sign in to reply to this topic.