OCR Computing A-Level Revision

Intermediate Code & Virtual Machines (3.2.e)

When translating code from a high-level language to machine code, a translator is used. If code is translated directly, then a different translator would need to be used for each high-level language and each "version" of machine code (as each processor architecture requires different machine code).

It is more efficient if the compiler (or interpreter) only translates the code to a "half-way" stage - this is called "intermediate code". Although intermediate code cannot run without further translation, it provides a "standard" form of code for translation to machine code. This means that a high level language can be translated to intermediate code (for example, using the translator provided by the creators of the high level language), and then the intermediate code can be translated to machine code (for example, using the translator provided by the creators of the particular processor architecture).

Intermediate code can also be run in a "virtual" machine - this allows the code to run faster than interpreted code, while allowing the code to be run cross-platform in a way which it couldn't if it had been compiled fully into machine code (as machine code is architecture specific, whereas intermediate code can be translated to machine code "just-in-time" by the "virtual" machine).