3.4.4 - Compilers, interpreters and assemblers

3.4.4 - Compilers, interpreters and assemblers

Explain why source programs need translation, compare the three required translators, and choose a suitable approach for development or repeated execution.

Why program translation is needed

A processor executes its machine instructions, so high-level or assembly source must be translated before its operations can be carried out.

High-level source expresses a problem in constructs that are convenient for the programmer. Assembly uses mnemonics for the processor's operations. Neither is the binary machine code that the processor directly understands. A translator bridges that difference.

The translator must preserve the intended operations and produce or invoke instructions suitable for the execution system. Syntax rules matter during translation: if a statement cannot be understood, the translator reports an error rather than guessing the programmer's intention. However, a program can translate successfully and still contain a logic error, such as applying the wrong calculation. Translation does not prove that the program solves the problem.

An assembler is needed for assembly source. High-level source uses compilation, interpretation or a system combining these ideas. The important examination distinction is what the three translators do, rather than assuming every real language implementation follows exactly one simple route.

Program translator

System software that translates source code or carries out its statements using machine-code operations that the processor can execute.

How the three translators differ

Compilers, interpreters and assemblers differ in their input and in how they arrange execution.

A compiler translates high-level source into machine code before that compiled program runs. It processes the program and reports translation errors. Once a successful compiled version exists, it can run repeatedly without compiling the unchanged source again. Changing the source requires producing a new compiled version.

An assembler translates assembly into machine code directly. In the required model, each assembly instruction becomes one machine-code instruction. A high-level statement may instead need several machine instructions, so its relationship is not generally one-to-one.

An interpreter carries out high-level statements as the program proceeds. In the specification's model, it does not directly generate a separate machine-code program from the source; it calls suitable machine-code subroutines within the interpreter's own code to perform the statements. The processor still executes machine code, but that code belongs to the executing interpreter. Source and the interpreter are needed for this interpreted route.

Continue this lesson.

You’re previewing NovaLearn without an account. Create a free account to read the rest.

Create free account