Jump to content
  • Advertisement
Sign in to follow this  

__asm in c#

This topic is 3858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
You cannot directly inline assembly into C#, no, but you can call unmanaged code from managed code.

Chances are this is a bad idea anyway.

Share this post


Link to post
Share on other sites
c# is executed on a virtual machine and thus it is pointless to directly inline assembly code.

if you need the speed of assembly, use a native compiled language to begin with.

/thread

Share this post


Link to post
Share on other sites
You could emit MSIL instructions from your application, see the System.Reflection.Emit namespace. It's not the same thing, but at least somewhat similar.

Share this post


Link to post
Share on other sites
Only possible in C++/CLI.

You can move the routines requiring asm code into a C++/CLI library and call them in a C# project without much overhead (and certainly much less than P/Invoke would involve).

The implications will be that your assembly requires extended security privileges (problematic if you're doing a client-side browser component, eg. using Silverlight) and that your project will no longer be portable (embedded machine code cannot be executed on other platforms and last time I checked, mono supported pure CIL code only).

If you consider using asm for fast vecor or math math, don't do that. Better investige the native image generator (ngen.exe) and read Washu's blog to learn why you'll have a hard time beating .NET's own optimizer.

-Markus-


Share this post


Link to post
Share on other sites
Quote:
Original post by Cpp_Programmer
Is it possible to code asm in c# or can you only do it in c++?


You signed up just to ask that question, with a name like Cpp_Programmer?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!