You cannot, not directly.
The platform is absolutely different: it does not compile to CPU instruction-set code; the code is compiled into CIL (
Common Intermediate Language), so the code can run on many different platforms implementing SLR
without recompilation, unless some limitation are applied. (One such limitations is using the native code through P/Invoke, for example.) This is really so: I regularly run my .NET applications on Linux without recompilation, even those using
System.Windows.Forms
(which is not a standard library).
When loaded, the .NET assembly is compiled to the CPU instructions on each platforms it's being executed using JIT (
Just-in-Time Compiler). Most typically, JIT compilation is performed on the per-method basis, when each method is about to be called for the very first time. This way, the methods never called may never be compiled in the native code.
Please see:
http://en.wikipedia.org/wiki/Common_Language_Runtime[
^],
http://en.wikipedia.org/wiki/Common_Intermediate_Language[
^],
http://en.wikipedia.org/wiki/Common_Language_Infrastructure[
^],
http://en.wikipedia.org/wiki/Just-in-time_compilation[
^].
This should explain why there is not a place for assembly language in a .NET assembly written in C#, VB.NET or IL.
However, there is a delicate difference here:
it does not mean that an executable module cannot have a place for both native code and .NET assembly at the same time. This pretty exotic but relatively widely used option can be implemented with so-called
mixed-mode (managed+unmanaged) project written in C++ and C++/CLI at the same time. You can even use C++ code in C++/CLI and visa versa.
In — voila! — you can use
asm
directives in unmanaged C++ parts of such projects.
About C++/CLI, please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[
^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[
^],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[
^],
http://www.gotw.ca/publications/C++CLIRationale.pdf[
^].
I don't know if it needs to mention that you can use Assembly language in a .NET application indirectly: you can write some unmanaged (native) executable module (DLL) using Assembly language or some high-level language with embedded Assembler and use this module in .NET assembly using P/Invoke.
If you need to learn it, please see:
http://en.wikipedia.org/wiki/P/Invoke[
^],
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[
^].
This CodeProject article can also be useful:
Essential P/Invoke[
^].
—SA