C#中的代码转换 [英] Code translation in C#

查看:110
本文介绍了C#中的代码转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我说我有这堆代码:

Well let's say I have this bunch of code :

Console.WriteLine("Hello World");



我希望我的程序(在C#中)要做的是将此代码翻译为:


What I want my program (in C#) to do is translate this code to :

mov si,mystring
call print_string
mystring db 'Hello World'



有没有简单的方法呢? (如果不是那么复杂的方式也可以)

任何帮助都将不胜感激.....

~Sids123


Is there any simple way to do that? (If not then complex ways are also okay)
Any help would be appreciated.....
~Sids123

推荐答案

C#不直接编译为本机代码 - 它编译为中间语言,后来由JIT编译器转换为本机指令。



如果你有什么看IL,这是一回事 - 这很容易做到 - 但你不能看原生代码,因为它没有与源存储。



如果你真的想要处理字符串Console.WriteLine(Hello World);在你的应用程序中并将其转换为可执行指令,然后你基本上必须编写一个C#编译器,并提供几乎整个.NET(或至少很大一部分),以支持您生成的代码 - 甚至print_string不是一个简单的练习!这是很多工作,但你会发现许多关于编译器编写的书籍 - 谷歌会在那里提供帮助。
C# does not compile directly to native code - it compiles to an Intermediate Language which is later converted to the native instructions by the JIT compiler.

If you what to view the IL, that's one thing - and it's easy enough to do - but you can't look at the native code because it isn't stored with the source.

If you actually want process the string "Console.WriteLine("Hello World");" in your application and convert it to executable instructions, then you basically have to write a C# compiler, and provide pretty much the whole of .NET (Or at least a large percentage of it) in order to support the code you generate - and even print_string isn't a trivial exercise! It's a lot of work, but you will find many, many books on compiler writing - Google will help there.


这篇关于C#中的代码转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆