How can I incorporate Assembly code in my C++ program.
How can I incorporate Assembly code in my C++ program.
Most compilers have some method of inling assembly, you'll have to check your help files for specifics.
zen
Though I've never used it and don't know if it's compiler specific or not, I believe there is an asm keyword that allows you to put assembler right into your program.
Code:int main( void ) { asm { MOV AX, 0x0200 MOV DL, 7 INT 0x21 }; return 0; }
pointer = NULL
It is compiler specific, some don't include it at all. Not only is the asm keyword compiler specific, asm is platform specific. Not a good thing for portable programs.
one fish two fish
red fish blue fish
But almost necessary for fast graphic operations, even in DirectX. If you wanted to program a per-pixel shader in DirectX rather than use the default you would definitely want to use assembly and/or MMX instructions. Fast alpha blending can also be done with MMX instructions.
I don't have MSVC but I"m sure it has support for most of the assembly opcodes - probably does not allow access to control registers like CR0, though, and for good reason.
For the most versatility in assembly you would need an assembler and then link your program with the resulting OBJ or COFF (whichever MASM does) - object file - and then call those functions from within your C++ program. If you are trying to implement a function that is not supported in the 3D hardware, the only real solution is to use assembly. Not as fast as hard-coded circuitry but faster than C++, if you do it right and optimize it.
Assembly is not always the answer and probably never the answer if you are programming for business type apps or GUI apps in Windows. But for games on the Win9X and XP platforms all of them will use DirectX so if your assembly is compatible with DirectX (there are many books on this) then your game *should* work on most home PCs. Not portable, but how many games do you see that are made for multiple platforms that use the same code? Not many. Most will only work on certain platforms with certain configs. Hence the large debate: console gaming vs. PC gaming. A PC game may only work on 70% of PCs out there. A console game will work on every console system it was designed for - theoretically.