how do i write assembly code from c#?

时间秒杀一切 提交于 2019-12-24 05:14:06

问题


i want to write a string of assembly code in c# and have it sent to some win32 api to compile and execute it and get the results back.

example:

string str = "MOV 1,2;XOR EBP,EBP"...

sounds like hard to do but any suggestion would be helpful.


回答1:


I doubt there's a win API to compile & execute assembly. Probably the best you could do is write a file, execute MASM (or whatever it's called these days), link it then execute the resulting program. I can't imagine what you are trying to do but this would be pretty much the last way I would try to solve almost any problem!

If you want to compare native & managed code, just write two programs that do more or less the same thing. There is no reason to generate the assembly from .NET. You can use any suitable tool for this. MASM, debug etc.




回答2:


AFAIK there is no assembler compiler available as a part of WinAPI. You would have to use some of the 3rd party compilers (and your program would need to redistribute it).

However, you can use ilasm which is a part of .NET framework. (Beware however that it's not an Intel32 compiler, its source is CIL code, so the instructions like xor ebp, ebp wouldn't work.)



来源:https://stackoverflow.com/questions/4330322/how-do-i-write-assembly-code-from-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!