Thread: How can I incorporate Assembly code in my C++ program.

  1. #1
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53

    How can I incorporate Assembly code in my C++ program.

    How can I incorporate Assembly code in my C++ program.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Most compilers have some method of inling assembly, you'll have to check your help files for specifics.
    zen

  3. #3
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    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

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    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

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. assembly code for release code?
    By George2 in forum Windows Programming
    Replies: 4
    Last Post: 07-09-2008, 11:17 AM
  3. Incorporate an existing program into another?
    By thetinman in forum Windows Programming
    Replies: 5
    Last Post: 06-06-2008, 08:40 AM
  4. Please test my program: Code Black
    By PhoenixC++ in forum Windows Programming
    Replies: 15
    Last Post: 04-29-2004, 07:18 PM
  5. Program Code
    By anewhope in forum C Programming
    Replies: 0
    Last Post: 04-22-2002, 09:06 AM