Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing a c#.net application which convert codes to assembly code.
Please help me to find out how to convert a c program code file to its
corresponding assembly code using c# code.
Posted
Comments
joshrduncan2012 23-Jan-14 10:44am    
Great question for google.
ZurdoDev 23-Jan-14 10:46am    
There is a ton of code required to do this. Where are you stuck?
thisisacs@gmail.com 23-Jan-14 10:57am    
Please post some links here for me
ZurdoDev 23-Jan-14 11:13am    
google.com.

This is not as easy as you may think, you have to be able to take libraries, change special constructs (assembly does not have a FOR loop), etc.

In order to do something like this you first have to parse the C file into its syntax tree[^], you can search google for AST tools to help you do this. This will let you verify that the C program is syntax correct, since you don't want to compile to a bad file.

Next, you need to start changing parts of the AST into equivalent assembly, also not an easy task since you need to keep track of things like stacks and registers. You will have to be responsible for push-ing all the right things on a stack before a method call for example.

While the steps here aren't great, there is a somewhat easier way. You could take the C file and pass it to an actual C compiler, saving the intermediate output (assembly files) when its done. You should leverage tools that are out there and work than try to reinvent the wheel, especially since this wheel is about as complicated as you can get.
 
Share this answer
 
Comments
thisisacs@gmail.com 23-Jan-14 11:02am    
Thank you for your replay.. Ok then can i get c# code to convert a simple hello world program to assembly code?
Ron Beyer 23-Jan-14 11:04am    
Doesn't matter if its "Hello World" or Duke Nukem, the process is the same unfortunately. It has nothing to do with how complicated the C code is, but how complicated the language itself is.
phil.o 23-Jan-14 11:07am    
My 5!
Ron Beyer 23-Jan-14 11:13am    
Thanks!
thisisacs@gmail.com 23-Jan-14 11:07am    
Please check this link
http://assembly.ynh.io/
How do they do this... Do you have any suggestions?
Yours would be a very complex task, basically you have to write a C compiler.
Using a tool would speed-up the process. Have a look, for instance at ANTLR4[^].
 
Share this answer
 
Comments
Ron Beyer 23-Jan-14 11:13am    
ANTLR, that was the term I was looking for, I kept looking up ANT :) +5
thisisacs@gmail.com 23-Jan-14 11:22am    
what is that?ANTLR4[^]??
Ron Beyer 23-Jan-14 11:23am    
Its a link, click it and learn.
CPallini 23-Jan-14 13:02pm    
Eh, he, AST->ANTLR should be automatic. :-)

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