• Foundation
  • About 13 min
  • 5 practice questions

Language translators: assembler, compiler and interpreter

Explain why translators are needed and compare compilers and interpreters.

If something looks wrong, please tell us.

People write programs in languages they can read, but a computer runs only machine code. Translators close that gap, and the difference between a compiler and an interpreter is a classic question.

Levels of language

  • Machine language: binary 0s and 1s, understood directly by the CPU.
  • Assembly language: short codes like ADD and MOV, closer to the machine.
  • High-level language: close to English, such as C, Java or Python, and easy for humans to write.

The three translators

Translators
TranslatorTranslatesHow
AssemblerAssembly language to machine codeConverts the program to machine code
CompilerHigh-level language to machine codeTranslates the whole program first, then it runs
InterpreterHigh-level languageTranslates and runs one line at a time

Compiler versus interpreter

  • A compiler reports all errors after scanning the whole program; an interpreter stops at the first error it meets.
  • A compiled program runs faster once built because it is already translated.
  • An interpreter is handy for learning and testing because you see results line by line.

Worked examples

Example 1. A program has errors on line 3 and line 9. An interpreter shows the line 3 error and stops. A compiler lists both errors after reading the whole program.

Example 2. Which translator would convert a program written in assembly language? An assembler.

Assembler: assembly to machine. Compiler: whole program at once. Interpreter: line by line.

— Remember

Key takeaways

  • Three levels: machine, assembly, high-level.
  • Assembler, compiler and interpreter are all translators.
  • Compiler = whole program; interpreter = one line at a time.

Check your understanding

  1. 1. Which translator converts a program written in assembly language into machine code?

    1. Compiler
    2. Interpreter
    3. Assembler
    4. Web browser
    Show answer

    Answer: C. An assembler translates assembly language into machine code. Compilers and interpreters work on high-level languages.

  2. 2. A program has errors on line 3 and line 9. What does an interpreter do?

    1. It lists both errors after reading the whole program
    2. It shows only the error on line 9
    3. It runs the whole program without reporting any error
    4. It shows the error on line 3 and stops
    Show answer

    Answer: D. An interpreter translates and runs one line at a time, so it stops at the first error it meets, on line 3. Listing both errors after reading the whole program is what a compiler does.

  3. 3. Which translator translates the whole high-level program first, and then the program runs?

    1. Interpreter
    2. Compiler
    3. Device driver
    4. Text editor
    Show answer

    Answer: B. A compiler translates the whole program before it runs. An interpreter works line by line; a driver and an editor are not translators.

  4. 4. Short codes such as ADD and MOV belong to

    1. Machine language
    2. Assembly language
    3. High-level language
    4. Plain English
    Show answer

    Answer: B. Assembly language uses short codes like ADD and MOV and is close to the machine. Machine language is pure 0s and 1s.

  5. 5. Why does a compiled program usually run faster than the same program run through an interpreter?

    1. It has already been translated into machine code before it runs
    2. It is translated again line by line every time it runs
    3. It does not need the CPU
    4. It is stored as firmware
    Show answer

    Answer: A. Once a compiler has built the program, it is already translated, so it runs faster. An interpreter has to translate as it runs.

Privacy · Terms · Refunds · Delivery