Why code must be translated, and how compilers, interpreters and assemblers differ.
What you will learn
- Explain why translation is needed
- Compare compilers and interpreters
- Choose a translator for a situation
Why translate?
The CPU only understands machine code, so source code, the program as the programmer wrote it, must be translated.
A compiler's output is object code: machine code saved as an executable file that runs without the translator.
| Compiler | Interpreter | |
|---|---|---|
| How | translates the whole program once | translates and runs one line at a time |
| Errors | reports them all at the end | stops at the first error |
| Output | an executable file | no file: it runs the source directly |
| Running | fast; no translator needed | slower; the interpreter is needed every time |
| Source code | stays private | must be shared |
| Good for | finished software | writing, testing and learning |
An assembler translates assembly language into machine code, one instruction for one instruction.
A drawback of a compiler is that after any change the whole program must be compiled again before it can be tested. An interpreter can run the changed line straight away, which suits writing and testing, but it is needed every time the program runs.
The rest of this lesson and its 7 practice questions are locked.
In this lesson
- Why translate?
- Try it: Which translator?
7 practice questions, marked as you go; about 20 minutes in all.
Key terms
Source code, Executable, Assembler
In this unit: Languages and translators
High-level and low-level languages, machine code and assembly language, compilers, interpreters and assemblers, IDEs, and the three kinds of error.
- High-level and low-level languages
- Compilers, interpreters and assemblers
- IDEs and errors