Search code examples
c++visual-studio-2010visual-c++masmmasm32

How do I integrate an ASM obj file with a C++ program?


I want to integrate ASM and C++ code in Visual Studio 2010. Basically, I want to be able to use certain routines created in ASM in my C++ code.

So I want to know:

  1. How do I add the ASM obj files to VS2010 in the first place?
  2. How do I call a function in the ASM code from the C++ part of the code?
  3. Suppose that I make a function (in ASM) that computes a value and stores the value in the tax register. Let's say its called compute. Will I be able to receive the return value in C++ using something like: int val=compute();?

Solution

  • All of these samples have what you need:

    http://msdn.microsoft.com/en-us/library/t13a3526%28v=VS.80%29.aspx

    You will have to let visual studio automatically "convert" them to the new project format, but I just tried it with the PRIMESSTEP2 example and it worked.

    All you need is a function prototype like:

    void sieve(void);  // prototype for Sieve of Eratosthenes function
    

    And then you can implement them in asm and they will link together. You return values by placing them in the EAX register and it will come through as a return value in C / C++.