开发者

Writing assembly code for the .Net platform

I'm a seasoned C# developer who wants, for fun, to write a bit of assembly code. I was wondering if it 开发者_如何学Gowas easiest simply to write in byte code and somehow use the C# compiler, linker whatever. I'm a bit unsure on how to go about this.

Or maybe there is a decent assembly language out there with a step debugger and other nice things shipped in an environment that I should pick up instead?

I mainly want to write code to do calculations and output to the console window.


You can write IL code and compile it with ILASM


You can write it in MSIL and assemble it via the MSIL assembler (ilasm.exe).

As for a debugger, I've previously used DILE (DotNet IL Editor) to step through IL code, it's a bit out-dated though.

Seems that DILE is still being updated, check out the weekly builds.


you can use assembly language of .net environment which is called CIL

http://en.wikipedia.org/wiki/Common_Intermediate_Language


You can't use the C# compiler to write assembly code. However, you can you Visual Studio "CLR" projects which will compile native C/C++ with inline assembly blocks, which you can write a managed wrapper around so you can invoke via C#. See CLI/C++ Tutorials for more information.

You can also look at masm32 which you can use to write native x86 assembly libraries, then use p/invoke to execute them via C#.

Have fun!


This may be helpful to others

As for editing MSIL, we can dump assembly file to IL file by the ILDASM utility and recompile it to assembly file by the ILASM utility,

The two utilities are included in the .NET SDK.

  • C:\Program Files\Microsoft Visual Studio 8\VC>ildasm .
  • Open your assembly e.g. my.dll
  • After opening the file, select File->Dump. Ensure all checkboxes are selected and then click OK. You will be prompted to save it as an IL file. I recommend creating a new directory to save as my.IL
  • Open my.IL by your favourite editing tool (I use Visual Studio .NET 2005/2003).
  • Edit your my.IL and then save it.
  • C:\Program Files\Microsoft Visual Studio 8\VC>ilasm /DLL X:\Folder\my.IL
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜