-4

I am currently designing and developing a programming language from scratch. Mostly as a learning experience. Although it's not entirely related to the question, it's important that you know a little bit of the backstory.

I have a fairly good idea as to how I'll turn the code from my language into the target assembly code, but there is a slight problem: which assemblers does one normally use when developing and creating a programming language (as for code generation)?

For Windows, I could theoretically compile my language into the MASM syntax, but then that wouldn't be available on all target Windows machines using my programming language. And I believe (don't take my word for it) I read somewhere that you're not allowed to bundle it up with your own software and redistribute it.

I suppose one could use NASM, as that would work on Linux and has the potential of working on Windows as well. But I feel as though there has to be another way. Surely people haven't relied on standalone software to compile their programs in the past?

Is there some architecture specific assembler bundled up with the operating system you are on, or do you need to rely on such aforementioned software?

I'm sure one could just compile down to ones and zeroes with no intermediate assembly language step, but that sounds a slight bit tedious, don't you think? ;-)

  • Would someone care to explain what my question lacks, so I can make sure not to repeat the same error when I reask this question at a later date? – D. Ataro Apr 23 '18 at 12:08
  • Have you considered generating C? – Erik Eidt Apr 23 '18 at 14:02
  • 2
    While you could certainly use assembly as your compilation target, why not just output the actual opcodes if you already know what they are? As @ErikEidt points out, you could generate C instead of assembly and that would compile on any platform that supports C. Or you could use a backend like LLVM. – Robert Harvey Apr 23 '18 at 15:09
  • 2
    Any decent assembler ought to suffice. Try to find one with syntax you like. en.wikipedia.org/wiki/Comparison_of_assemblers – Robert Harvey Apr 23 '18 at 15:43
  • 2
5

Most compilers bundle an assembler and linker as part of their backend. These may or may not be standalone programs. For example, LLVM will not generate textual assembly language, but generates machine code directly from the in-memory IR (intermediate representation). Using LLVM as a library in your compiler is the easiest way to get a production-grade native compiler backend.

Note that many programming languages are not implemented as compilers but as interpreters, as interpreters are generally much easier to develop. E.g. you might get garbage collection “for free” from the host language, without having to develop a language runtime in addition to the compiler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.