can i use assemblers code in c# code?

How can i use in my c# application a block of assembler code

Answer this question

can i use assemblers code in c# code?

  • mafandon

    I don't believe you can, directly. The .NET framework is designed to compile to MSIL, so there's a layer between your code and the machine, which makes assembly there unlikely. You can do it in C++ tho, and you can call a C++ dll from C# using COM or just plain interop.



  • avrilsim

    Just a quick addition to the other comments. If you're talking about assembly language (x86 or otherwise), you can do it by implementing in C++/CLS (managed C++) and then calling the code from C#. One important thing to note is that your application will require Full Trust, as you'll be calling unmanaged code. (The same would be true if you were using a COM object or P/Invoking into an unmanaged DLL.)
    The real question is what are you thinking of doing that would require assembly language It's amazing what can be accomplished with a combination of "unsafe" C#, managed C++, or P/Invoking unmanaged C/C++. Also just because it's managed doesn't mean it's slow. I would highly recommend reading the following before embarking on any assembly language or unmanaged C++ endeavours:
    Hope that helps.


  • Dahl Berg

    Thanks. How i can call C++ code from C#
  • Antistar

    Which assembly code do you want to run have in your code x86 or MSIL

    If the answer is x86 you are out of luck... one of the few ways you could do that would be to build the ASM code into another project just as an unmanaged C++ dll and call it from your C# app.

    If MSIL... you can... just not directly, nor is it recommended or supported. To do so, take a look at the following links where a couple of people have built some small tools for inline MSIL.

    http://blogs.msdn.com/jmstall/archive/2005/02/21/377806.aspx

    http://www.microsoft.com/downloads/details.aspx FamilyId=7E979ED3-416B-43B6-993B-308A160831B6&displaylang=en



  • phreakstar

    To call unmanaged (or C++)( code from managed code (or C#), this might help:

    http://blogs.msdn.com/deeptanshuv/archive/2005/06/26/432870.aspx



  • arindam_

    I think you can use "Lightweight Code Generation" to control IL-level code generation.
  • can i use assemblers code in c# code?