Second - this sounds like a homework assignment - you have to write an assembler in C#. The reason I'm calling it homework is because nobody in the corporate world would waste their time reinventing the wheel that is MASM (Microsoft's Assembler). Why? It's freakin' free , as in no charge, as in download it and use it.

Third, you're asking for code to fulfill your homework assignment. How are you going to learn anything if you don't do the work yourself?

Fourth, when lazy know-nothing programmers enter the workforce, they threaten EVERYBODY'S job that came before them, and that will follow them into the industry.

If you can prove me wrong about this being homework, I'll delete this answer.

Solution 3

The compiler is actually the last step. You first start with a scanner that scans the input (also detects syntax errors). A parser that creates corresponding structures, which is usually a tree (and also detects grammatical errors). The corresponding structures (or tree items) are the most easy when they are objects of a class that has a compile method. After parsing the complete input you simply call the compile at the root (that will compile itself and every branch) and that way produce the output. You can also choose to implement an execute method instead of compile and that way create an interpreter. Just look for "How to build your own compiler/interpreter" with google and you will get lots of results.

Solution 4

An oldie-goldie is the Crenshaw's series Let's build a compiler[^], inspired by the KISS[^] principle. He used Turbo Pascal and wrote the compiler for Motorola 68000 CPU, but, you know, in compiler contruction good ideas really matters.

Solution 1

Just download Visual Studio 2010 Express. It's free. When you're done with it, uninstall it from your machine. If you don't like that option, google "C# comnpiler" and see if one of the 890,000 results gives you something you can use.