0

This question already has an answer here:

When we build a new machine, how do we add software to that machine?

I know we have assemblers and compilers that convert the high-level code into machine code for it to understand. But having designed a new machine with some new architecture, how do we proceed ahead and add assembler and compilers to a machine understanding only machine language?

As far as I know, we do not write the assemblers or compilers in machine language, so how do we add these programs to the new machine so that it can run programs in high-level language?

marked as duplicate by gnat, Wayne Molina, Dan Pichelman, user40980, jwenting Aug 18 '14 at 9:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    As far as I know, we do not write the assemblers or compilers in machine language. Well, for the very first bits of software, you would have to... – Oded Aug 16 '14 at 7:15
  • @gnat I think I have a different question more into the software side.... – sarthak Aug 16 '14 at 9:53
  • meta.stackexchange.com/a/194495/165773 – gnat Aug 16 '14 at 11:35
7

As far as I know, we do not write the assemblers or compilers in machine language, so how do we add these programs to the new machine so that it can run programs in high-level language?

As a matter of fact we do, at least if there is no other development chain available for cross-compilation. The first modern computers didn't have one, so yes, people wrote assemblers in machine language, then compilers in assembly language, and finally application programs in higher-level languages. Google "bootstrapping" for more information.

Today, of course, it is very rare that no cross-compiling development chain is available, since there are multiple free or almost-free compiler kits out there that have portability as one of their main goals. In fact, it's unlikely that we will ever go back to the times when new machines have no option to cross-develop anything! The chain of program-transforming programs goes back in history all the way to the beginning of compilers, much like all life today is ultimately descended from the same cells eons ago, and losing it would be a catastrophe similar to killing off all higher life and having to let nature redevelop it from single-cell organisms. But at least in principle, yes, compilers have to be arduously implemented at a level below the one they're supposed to work with.

  • What we do after cross-compiling? Do we add the generated machine-code (for the assembler or compiler) into our machine? Could you please go into the details of this as well... – sarthak Aug 16 '14 at 9:50
  • Well, yes. The cross-compiled code is copied (via NFS, internet or whatever), then you have a working compiler executable for your architecture, and you can use that to recompile itself from source normally. From then on the compiler will be self-hosting, but you can't skip that first step. – Kilian Foth Aug 17 '14 at 13:44
1

We first build assemblers and compilers for them, compile those for existing computers (the result are "cross-", as they are executing on an host which hasn't the target architecture). Those are usually build before any machine having that architecture (and used with simulators to design the chips).

When you have that, it exactly the same way than for a computer which is using an old architecture. Write a loader which is able to load a file from somewhere (HD, USB, network) put that at a fixed place and then execute it and put the loader in a ROM at the address which is executed at startup by your processor.

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