开发者

how do i write assembly code from c#?

i want to write a string of assembly code in c# and have it sent t开发者_JS百科o 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.


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.


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.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜