Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can you compile an .asm file in C# and if you can how do you do it?
Posted
Comments
Sergey Alexandrovich Kryukov 20-Dec-13 2:17am    
Why?!
—SA

1 solution

You can use some available assembler: http://en.wikipedia.org/wiki/Assembler_%28computing%29#Assembler[^].

This can be done using System.Diagnostics.Process.Start:
System.Diagnostics.Process.Start(@"a\file\path\to\the\executable\module\of\some\Assember", "some parameters fileName.asm");

Please see: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start%28v=vs.110%29.aspx[^].

However, this is most likely quite pointless. The customer system, most likely, does not have an Assember. And even if you compiler it, then what? Assembler and Assembly languages have little to do with .NET, they target particular system and particular processor. However, just in case: you should understand that, with .NET, you can use native-code executable modules using P/Invoke:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[^].

—SA
 
Share this answer
 
Comments
IAmABadCoder 20-Dec-13 2:35am    
Sorry, the main reason I want to use assembly is to test things and just explore creativity. I am currently thinking about making an .asm file editor program. But anyways thankyou for the answer I will try and incorporate this code in my program. Thankyou
—DK
Sergey Alexandrovich Kryukov 20-Dec-13 2:47am    
Please, there is nothing to apologize about. It could be an interesting project. Some more things to learn: read about redirection of StandardOutput and StandardError. This is explained here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput(v=vs.110).aspx, with examples.

You will need it to capture output from a compiler, present errors/warnings in your editor, on click, to locate the file/line/columns of the editor with source code and put a cursor on this place. I have done all of that; this is quite a work, but it took me just few days to create such editor.

Besides, you need to perform compilation in a separate thread. So, you will also need to learn Control or Dispatcher Invoke/BeginInvoke.

Are you familiar with all that? If not, I'll gladly answer. For now, are you going to accept this answer (green "accept" button). If you have quick follow-up questions, I'll answer anyway.

—SA
IAmABadCoder 20-Dec-13 3:08am    
What do you mean by 'System.Diagnostics.Process.Start(@"a\file\path\to\the\executable\module\of\some\Assember", "some parameters fileName.asm");'.
Sergey Alexandrovich Kryukov 20-Dec-13 3:16am    
I already explained, and this is just some "placeholder path"; you need to calculate some real file path and pass it. Do you know how to use Assembly directly, to compile ("assemble") some .asm file? It will be some executable module which you run with parameters, .EXE. You need to provide a path to this file. By the way, did you develop anything in assembly language by yourself? You really need at least a bit of it. Do you understand the the output of the Assembler is used by the linker? Do you know how to create Assembly code for the platform you target? You need it all...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900